From 976ccfcaa80c9d4919a332a9ccc40e85d8112d19 Mon Sep 17 00:00:00 2001 From: Zhihang Yao Date: Fri, 5 Jul 2024 00:04:32 +0200 Subject: [PATCH] minor change --- .../database/postgres/SchemaAdapter.java | 19 +++++++++++++++++-- .../database/adapter/SchemaAdapter.java | 9 +++++++++ .../operation/exporter/ExportHelper.java | 4 +--- .../exporter/feature/FeatureExporter.java | 9 +++------ 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/citydb-database-postgres/src/main/java/org/citydb/database/postgres/SchemaAdapter.java b/citydb-database-postgres/src/main/java/org/citydb/database/postgres/SchemaAdapter.java index 70f80f77..cd7c0344 100644 --- a/citydb-database-postgres/src/main/java/org/citydb/database/postgres/SchemaAdapter.java +++ b/citydb-database-postgres/src/main/java/org/citydb/database/postgres/SchemaAdapter.java @@ -73,7 +73,22 @@ public int getMaximumNumberOfItemsForInOperator() { @Override public String getFeatureHierarchyQuery() { try { - return featureHierarchyQuery.get(); + return PlainText.of(featureHierarchyQuery.get(), + PlainText.of("F.ENVELOPE"), + PlainText.of("G.GEOMETRY"), + PlainText.of("A.MULTI_POINT")).toString(); + } catch (Exception e) { + throw new IllegalStateException("Failed to create feature hierarchy query.", e); + } + } + + @Override + public String getFeatureHierarchyQuery(int targetSRID) { + try { + return PlainText.of(featureHierarchyQuery.get(), + PlainText.of(getTransformOperator("F.ENVELOPE", targetSRID)), + PlainText.of(getTransformOperator("G.GEOMETRY", targetSRID)), + PlainText.of(getTransformOperator("A.MULTI_POINT", targetSRID))).toString(); } catch (Exception e) { throw new IllegalStateException("Failed to create feature hierarchy query.", e); } @@ -155,7 +170,7 @@ private String readFeatureHierarchyQuery() throws IOException { } } - public String readRecursiveImplicitGeometryQuery() throws IOException { + private String readRecursiveImplicitGeometryQuery() throws IOException { try (BufferedReader reader = new BufferedReader(new InputStreamReader(Objects.requireNonNull( SchemaAdapter.class.getResourceAsStream("/org/citydb/database/postgres/query_recursive_implicit_geometry.sql"))))) { return reader.lines() diff --git a/citydb-database/src/main/java/org/citydb/database/adapter/SchemaAdapter.java b/citydb-database/src/main/java/org/citydb/database/adapter/SchemaAdapter.java index ba705ef0..824a7f28 100644 --- a/citydb-database/src/main/java/org/citydb/database/adapter/SchemaAdapter.java +++ b/citydb-database/src/main/java/org/citydb/database/adapter/SchemaAdapter.java @@ -28,6 +28,7 @@ import org.citydb.database.util.SqlHelper; import org.citydb.sqlbuilder.common.SqlObject; import org.citydb.sqlbuilder.query.Select; +import org.citydb.sqlbuilder.util.PlainText; public abstract class SchemaAdapter { protected final DatabaseAdapter adapter; @@ -51,6 +52,8 @@ protected SchemaAdapter(DatabaseAdapter adapter) { public abstract String getFeatureHierarchyQuery(); + public abstract String getFeatureHierarchyQuery(int targetSRID); + public abstract SqlObject getRecursiveImplicitGeometryQuery(Select featureQuery); public abstract String getCreateIndex(Index index); @@ -84,4 +87,10 @@ public SqlHelper getSqlHelper() { public IndexHelper getIndexHelper() { return indexHelper; } + + public String getTransformOperator(String column, int targetSRID) { + return adapter.getGeometryAdapter().getSpatialOperationHelper() + .transform(PlainText.of(column), targetSRID) + .toString(); + } } diff --git a/citydb-operation/src/main/java/org/citydb/operation/exporter/ExportHelper.java b/citydb-operation/src/main/java/org/citydb/operation/exporter/ExportHelper.java index 38a32941..71f658ea 100644 --- a/citydb-operation/src/main/java/org/citydb/operation/exporter/ExportHelper.java +++ b/citydb-operation/src/main/java/org/citydb/operation/exporter/ExportHelper.java @@ -175,9 +175,7 @@ public String getInOperator(String column, Set values) { public String getTransformOperator(String column) { return adapter.getDatabaseMetadata().getSpatialReference().getSRID() == getSRID() ? column : - adapter.getGeometryAdapter().getSpatialOperationHelper() - .transform(PlainText.of(column), getSRID()) - .toString(); + adapter.getSchemaAdapter().getTransformOperator(column, getSRID()); } Feature exportFeature(long id, long sequenceId) throws ExportException { diff --git a/citydb-operation/src/main/java/org/citydb/operation/exporter/feature/FeatureExporter.java b/citydb-operation/src/main/java/org/citydb/operation/exporter/feature/FeatureExporter.java index 2993c2aa..c6a2b485 100644 --- a/citydb-operation/src/main/java/org/citydb/operation/exporter/feature/FeatureExporter.java +++ b/citydb-operation/src/main/java/org/citydb/operation/exporter/feature/FeatureExporter.java @@ -28,7 +28,6 @@ import org.citydb.operation.exporter.ExportHelper; import org.citydb.operation.exporter.common.DatabaseExporter; import org.citydb.operation.exporter.hierarchy.HierarchyBuilder; -import org.citydb.sqlbuilder.util.PlainText; import java.sql.ResultSet; import java.sql.SQLException; @@ -42,11 +41,9 @@ public FeatureExporter(ExportHelper helper) throws SQLException { } private String getQuery() { - return PlainText.of(adapter.getSchemaAdapter().getFeatureHierarchyQuery(), - PlainText.of(helper.getTransformOperator("F.ENVELOPE")), - PlainText.of(helper.getTransformOperator("G.GEOMETRY")), - PlainText.of(helper.getTransformOperator("A.MULTI_POINT")) - ).toString(); + return adapter.getDatabaseMetadata().getSpatialReference().getSRID() == helper.getSRID() ? + adapter.getSchemaAdapter().getFeatureHierarchyQuery() : + adapter.getSchemaAdapter().getFeatureHierarchyQuery(helper.getSRID()); } public Feature doExport(long id) throws ExportException, SQLException {