Skip to content

Commit aa86abc

Browse files
authored
Merge pull request #18 from 3dcitydb/feature-schema-mapping
Add schema mapping API
2 parents 1894a7c + 96017e1 commit aa86abc

36 files changed

+1833
-680
lines changed

citydb-cli/src/main/java/org/citydb/cli/deleter/DeleteCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public Integer call() throws ExecutionException {
9090
QueryExecutor executor = QueryExecutor.of(databaseManager.getAdapter());
9191
Deleter deleter = Deleter.newInstance();
9292

93-
FeatureStatistics statistics = helper.createFeatureStatistics(databaseManager.getAdapter());
93+
FeatureStatistics statistics = new FeatureStatistics(databaseManager.getAdapter());
9494
IndexOption.Mode indexMode = indexOption.getMode();
9595
AtomicLong counter = new AtomicLong();
9696

citydb-cli/src/main/java/org/citydb/cli/exporter/ExportController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ protected boolean doExport() throws ExecutionException {
101101

102102
DatabaseManager databaseManager = helper.connect(connectionOptions, config);
103103
QueryExecutor executor = QueryExecutor.of(databaseManager.getAdapter());
104-
FeatureStatistics statistics = helper.createFeatureStatistics(databaseManager.getAdapter());
104+
FeatureStatistics statistics = new FeatureStatistics(databaseManager.getAdapter());
105105

106106
helper.logIndexStatus(Level.INFO, databaseManager.getAdapter());
107107
initialize(databaseManager);

citydb-cli/src/main/java/org/citydb/cli/importer/ImportController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ protected boolean doImport() throws ExecutionException {
106106
}
107107

108108
DatabaseManager databaseManager = helper.connect(connectionOptions, config);
109-
FeatureStatistics statistics = helper.createFeatureStatistics(databaseManager.getAdapter());
109+
FeatureStatistics statistics = new FeatureStatistics(databaseManager.getAdapter());
110110
IndexOption.Mode indexMode = indexOption.getMode();
111111

112112
if (indexMode != IndexOption.Mode.keep) {

citydb-cli/src/main/java/org/citydb/cli/util/CommandHelper.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.citydb.io.IOAdapterException;
3737
import org.citydb.io.IOAdapterManager;
3838
import org.citydb.logging.LoggerManager;
39-
import org.citydb.operation.util.FeatureStatistics;
4039
import org.citydb.plugin.PluginManager;
4140

4241
import java.sql.SQLException;
@@ -103,15 +102,6 @@ public IOAdapterManager createIOAdapterManager() throws ExecutionException {
103102
return manager;
104103
}
105104

106-
public FeatureStatistics createFeatureStatistics(DatabaseAdapter adapter) throws ExecutionException {
107-
try {
108-
return new FeatureStatistics(adapter.getSchemaAdapter().getObjectClassHelper(),
109-
adapter.getSchemaAdapter().getNamespaceHelper());
110-
} catch (SQLException e) {
111-
throw new ExecutionException("Failed to create feature statistics helper.", e);
112-
}
113-
}
114-
115105
public void createIndexes(DatabaseAdapter adapter) throws ExecutionException {
116106
try {
117107
IndexHelper indexHelper = adapter.getSchemaAdapter().getIndexHelper();

citydb-database/src/main/java/org/citydb/database/adapter/DatabaseAdapter.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121

2222
package org.citydb.database.adapter;
2323

24+
import org.citydb.database.DatabaseException;
2425
import org.citydb.database.Pool;
2526
import org.citydb.database.connection.ConnectionDetails;
2627
import org.citydb.database.metadata.DatabaseMetadata;
2728
import org.citydb.database.metadata.DatabaseVersion;
2829
import org.citydb.database.metadata.SpatialReference;
30+
import org.citydb.database.schema.SchemaException;
2931

3032
import java.sql.*;
3133
import java.util.Objects;
@@ -43,7 +45,7 @@ public abstract class DatabaseAdapter {
4345
public abstract int getDefaultPort();
4446
public abstract String getConnectionString(String host, int port, String database);
4547

46-
public final void initialize(Pool pool, ConnectionDetails connectionDetails) throws SQLException {
48+
public final void initialize(Pool pool, ConnectionDetails connectionDetails) throws DatabaseException, SQLException {
4749
this.pool = Objects.requireNonNull(pool, "The database pool must not be null.");
4850
this.connectionDetails = Objects.requireNonNull(connectionDetails, "The connection details must not be null.");
4951
schemaAdapter = Objects.requireNonNull(createSchemaAdapter(this), "The schema adapter must not be null.");
@@ -62,6 +64,12 @@ public final void initialize(Pool pool, ConnectionDetails connectionDetails) thr
6264
vendorMetadata.getDatabaseMajorVersion(),
6365
vendorMetadata.getDatabaseMinorVersion());
6466
}
67+
68+
try {
69+
schemaAdapter.buildSchemaMapping();
70+
} catch (SchemaException e) {
71+
throw new DatabaseException("Failed to build schema mapping.", e);
72+
}
6573
}
6674

6775
public SchemaAdapter getSchemaAdapter() {

citydb-database/src/main/java/org/citydb/database/adapter/SchemaAdapter.java

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,19 @@
2121

2222
package org.citydb.database.adapter;
2323

24-
import org.citydb.core.concurrent.LazyInitializer;
2524
import org.citydb.database.metadata.SpatialReferenceType;
2625
import org.citydb.database.schema.*;
2726

28-
import java.sql.SQLException;
2927
import java.util.Iterator;
3028
import java.util.Set;
3129

3230
public abstract class SchemaAdapter {
3331
protected final DatabaseAdapter adapter;
34-
private final LazyInitializer<DataTypeHelper, SQLException> dataTypeHelper;
35-
private final LazyInitializer<NamespaceHelper, SQLException> namespaceHelper;
36-
private final LazyInitializer<ObjectClassHelper, SQLException> objectClassHelper;
3732
private final IndexHelper indexHelper;
33+
private SchemaMapping schemaMapping;
3834

3935
protected SchemaAdapter(DatabaseAdapter adapter) {
4036
this.adapter = adapter;
41-
dataTypeHelper = LazyInitializer.of(() -> DataTypeHelper.newInstance(adapter));
42-
namespaceHelper = LazyInitializer.of(() -> NamespaceHelper.newInstance(adapter));
43-
objectClassHelper = LazyInitializer.of(() -> ObjectClassHelper.newInstance(adapter));
4437
indexHelper = IndexHelper.newInstance(adapter);
4538
}
4639

@@ -57,16 +50,12 @@ protected SchemaAdapter(DatabaseAdapter adapter) {
5750
protected abstract String getSpatialReference();
5851
protected abstract SpatialReferenceType getSpatialReferenceType(String type);
5952

60-
public DataTypeHelper getDataTypeHelper() throws SQLException {
61-
return dataTypeHelper.get();
53+
void buildSchemaMapping() throws SchemaException {
54+
schemaMapping = SchemaMappingBuilder.newInstance().build(adapter);
6255
}
6356

64-
public NamespaceHelper getNamespaceHelper() throws SQLException {
65-
return namespaceHelper.get();
66-
}
67-
68-
public ObjectClassHelper getObjectClassHelper() throws SQLException {
69-
return objectClassHelper.get();
57+
public SchemaMapping getSchemaMapping() {
58+
return schemaMapping;
7059
}
7160

7261
public IndexHelper getIndexHelper() {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* citydb-tool - Command-line tool for the 3D City Database
3+
* https://www.3dcitydb.org/
4+
*
5+
* Copyright 2022-2024
6+
* virtualcitysystems GmbH, Germany
7+
* https://vc.systems/
8+
*
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
*/
21+
22+
package org.citydb.database.schema;
23+
24+
import java.util.Locale;
25+
26+
public class Column {
27+
private final String name;
28+
private final ColumnType type;
29+
30+
Column(String name, ColumnType type) {
31+
this.name = name.toLowerCase(Locale.ROOT);
32+
this.type = type;
33+
}
34+
35+
public String getName() {
36+
return name;
37+
}
38+
39+
public ColumnType getType() {
40+
return type;
41+
}
42+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* citydb-tool - Command-line tool for the 3D City Database
3+
* https://www.3dcitydb.org/
4+
*
5+
* Copyright 2022-2024
6+
* virtualcitysystems GmbH, Germany
7+
* https://vc.systems/
8+
*
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
*/
21+
22+
package org.citydb.database.schema;
23+
24+
import java.util.Arrays;
25+
import java.util.HashMap;
26+
import java.util.Locale;
27+
import java.util.Map;
28+
29+
public enum ColumnType {
30+
BOOLEAN("boolean"),
31+
INTEGER("integer"),
32+
DOUBLE("double"),
33+
STRING("string"),
34+
URI("uri"),
35+
TIMESTAMP("timestamp"),
36+
ARRAY("array"),
37+
BOOLEAN_ARRAY("booleanArray"),
38+
INTEGER_ARRAY("integerArray"),
39+
DOUBLE_ARRAY("doubleArray"),
40+
STRING_ARRAY("stringArray"),
41+
GEOMETRY("geometry");
42+
43+
private final static Map<String, ColumnType> types = new HashMap<>();
44+
private final String name;
45+
46+
static {
47+
Arrays.stream(values()).forEach(type -> types.put(type.name.toLowerCase(Locale.ROOT), type));
48+
}
49+
50+
ColumnType(String name) {
51+
this.name = name;
52+
}
53+
54+
public static ColumnType of(String name) {
55+
return name != null ? types.get(name.toLowerCase(Locale.ROOT)) : null;
56+
}
57+
58+
public String getName() {
59+
return name;
60+
}
61+
62+
@Override
63+
public String toString() {
64+
return name;
65+
}
66+
}

0 commit comments

Comments
 (0)