From ce184e650ed75a791611379412bb8e963ff0de45 Mon Sep 17 00:00:00 2001 From: Lyn Elisa Goltz Date: Mon, 8 Apr 2024 13:43:36 +0200 Subject: [PATCH 1/3] #9951 (#29) - added parameter dbSchema --- .../persistence/sql/ddl/DDLCreator.java | 13 ++++++- .../sql/ddl/PostGISDDLCreator.java | 7 +++- .../sql/mapper/AppSchemaMapper.java | 13 ++++--- .../sql/mapper/AppSchemaMapperTest.java | 39 ++++++++++++++----- .../config/FeatureStoreConfigWriter.java | 2 +- .../featurestoresql/config/LoadParameter.java | 13 ++++++- .../config/LoadParameterBuilder.java | 8 ++++ ...eatureStoreConfigCreatorConfiguration.java | 4 +- ...FeatureStoreConfigCreatorUsagePrinter.java | 1 + 9 files changed, 78 insertions(+), 22 deletions(-) diff --git a/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/ddl/DDLCreator.java b/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/ddl/DDLCreator.java index b4c4b751cd..e6b04e8407 100644 --- a/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/ddl/DDLCreator.java +++ b/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/ddl/DDLCreator.java @@ -73,6 +73,8 @@ public abstract class DDLCreator { protected TableName currentFtTable; + protected List createdSchemas = new ArrayList<>(); + /** * Creates a new {@link DDLCreator} instance for the given {@link MappedAppSchema}. * @param schema mapped application schema, must not be null @@ -121,7 +123,9 @@ private List process(FeatureTypeMapping ftMapping) { currentFtTable = ftMapping.getFtTable(); - StringBuffer sql = new StringBuffer("CREATE TABLE "); + StringBuffer sql = new StringBuffer(); + appendCreateSchema(currentFtTable.getSchema(), sql); + sql.append("CREATE TABLE "); ddls.add(sql); sql.append(currentFtTable); sql.append(" ("); @@ -168,6 +172,13 @@ private List process(FeatureTypeMapping ftMapping) { return ddls; } + protected void appendCreateSchema(String schema, StringBuffer sql) { + if (schema != null && !createdSchemas.contains(schema)) { + sql.append("CREATE SCHEMA ").append(schema).append(";\n"); + createdSchemas.add(schema); + } + } + private String getPkConstraintName(TableName ftTable) { String s = null; String table = ftTable.getTable(); diff --git a/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/ddl/PostGISDDLCreator.java b/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/ddl/PostGISDDLCreator.java index 74afa8271d..a48f47c05d 100644 --- a/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/ddl/PostGISDDLCreator.java +++ b/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/ddl/PostGISDDLCreator.java @@ -138,7 +138,8 @@ private List getGeometryCreate(GeometryMapping mapping, DBField db StringBuffer indexSql = new StringBuffer("CREATE INDEX "); String idxName = createIdxName(table.getTable(), column); indexSql.append(idxName); - indexSql.append(" ON ").append(table.getTable().toLowerCase()); + indexSql.append(" ON "); + indexSql.append(table.toString().toLowerCase()); indexSql.append(" USING GIST (").append(column).append(" ); "); ddls.add(indexSql); return ddls; @@ -187,7 +188,9 @@ protected void featureMappingSnippet(StringBuffer sql, FeatureMapping mapping) { @Override protected StringBuffer createJoinedTable(TableName fromTable, TableJoin jc, List ddls, FIDMapping fidMapping) { - StringBuffer sb = new StringBuffer("CREATE TABLE "); + StringBuffer sb = new StringBuffer(); + appendCreateSchema(jc.getToTable().getSchema(), sb); + sb.append("CREATE TABLE "); sb.append(jc.getToTable()); sb.append(" (\n "); sb.append("id serial PRIMARY KEY,\n "); diff --git a/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/mapper/AppSchemaMapper.java b/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/mapper/AppSchemaMapper.java index d3adef1de3..21e2cdc25a 100644 --- a/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/mapper/AppSchemaMapper.java +++ b/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/mapper/AppSchemaMapper.java @@ -140,6 +140,8 @@ public class AppSchemaMapper { private final boolean useRefDataProps; + private final String dbSchema; + /** * Creates a new {@link AppSchemaMapper} instance for the given schema. * @param appSchema application schema to be mapped, must not be null @@ -180,7 +182,7 @@ public AppSchemaMapper(AppSchema appSchema, boolean createBlobMapping, boolean c GeometryStorageParams geometryParams, int maxLength, boolean usePrefixedSQLIdentifiers, boolean useIntegerFids, int allowedCycleDepth) { this(appSchema, createBlobMapping, createRelationalMapping, geometryParams, maxLength, - usePrefixedSQLIdentifiers, useIntegerFids, allowedCycleDepth, null, false); + usePrefixedSQLIdentifiers, useIntegerFids, allowedCycleDepth, null, false, null); } /** @@ -203,7 +205,8 @@ public AppSchemaMapper(AppSchema appSchema, boolean createBlobMapping, boolean c */ public AppSchemaMapper(AppSchema appSchema, boolean createBlobMapping, boolean createRelationalMapping, GeometryStorageParams geometryParams, int maxLength, boolean usePrefixedSQLIdentifiers, - boolean useIntegerFids, int allowedCycleDepth, ReferenceData referenceData, boolean useRefDataProps) { + boolean useIntegerFids, int allowedCycleDepth, ReferenceData referenceData, boolean useRefDataProps, + String dbSchema) { this.appSchema = appSchema; this.geometryParams = geometryParams; this.useIntegerFids = useIntegerFids; @@ -211,6 +214,7 @@ public AppSchemaMapper(AppSchema appSchema, boolean createBlobMapping, boolean c this.maxComplexityIndex = DEFAULT_COMPLEXITY_INDEX * (allowedCycleDepth + 1); this.referenceData = referenceData; this.useRefDataProps = useRefDataProps; + this.dbSchema = dbSchema; List ftList = appSchema.getFeatureTypes(null, false, false); List blackList = new ArrayList(); @@ -285,10 +289,7 @@ private FeatureTypeMapping generateFtMapping(FeatureType ft) { LOG.info("Mapping feature type '" + ft.getName() + "'"); MappingContext mc = mcManager.newContext(ft.getName(), detectPrimaryKeyColumnName()); - // TODO - TableName table = new TableName(mc.getTable()); - // TODO - + TableName table = new TableName(mc.getTable(), dbSchema); FIDMapping fidMapping = generateFidMapping(ft); List mappings = new ArrayList<>(); diff --git a/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/test/java/org/deegree/feature/persistence/sql/mapper/AppSchemaMapperTest.java b/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/test/java/org/deegree/feature/persistence/sql/mapper/AppSchemaMapperTest.java index 97e0f48636..436e9151b4 100644 --- a/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/test/java/org/deegree/feature/persistence/sql/mapper/AppSchemaMapperTest.java +++ b/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/test/java/org/deegree/feature/persistence/sql/mapper/AppSchemaMapperTest.java @@ -466,7 +466,7 @@ public void testWithoutReferenceData() throws Exception { CRSRef storageCrs = CRSManager.getCRSRef("EPSG:4326"); GeometryStorageParams geometryParams = new GeometryStorageParams(storageCrs, "0", DIM_2); AppSchemaMapper mapper = new AppSchemaMapper(appSchema, false, true, geometryParams, 63, true, true, 0, null, - false); + false, null); MappedAppSchema mappedSchema = mapper.getMappedSchema(); @@ -497,7 +497,7 @@ public void testWithReferenceData() throws Exception { CRSRef storageCrs = CRSManager.getCRSRef("EPSG:4326"); GeometryStorageParams geometryParams = new GeometryStorageParams(storageCrs, "0", DIM_2); AppSchemaMapper mapper = new AppSchemaMapper(appSchema, false, true, geometryParams, 63, true, true, 0, - referenceData, false); + referenceData, false, null); MappedAppSchema mappedSchema = mapper.getMappedSchema(); @@ -539,7 +539,7 @@ public void testWithReferenceData_ComplexData_ComplexN() throws Exception { CRSRef storageCrs = CRSManager.getCRSRef("EPSG:4326"); GeometryStorageParams geometryParams = new GeometryStorageParams(storageCrs, "0", DIM_2); AppSchemaMapper mapper = new AppSchemaMapper(appSchema, false, true, geometryParams, 63, true, true, 0, - referenceData, false); + referenceData, false, null); MappedAppSchema mappedSchema = mapper.getMappedSchema(); @@ -587,7 +587,7 @@ public void testWithReferenceData_ComplexData_Complex1() throws Exception { CRSRef storageCrs = CRSManager.getCRSRef("EPSG:4326"); GeometryStorageParams geometryParams = new GeometryStorageParams(storageCrs, "0", DIM_2); AppSchemaMapper mapper = new AppSchemaMapper(appSchema, false, true, geometryParams, 63, true, true, 0, - referenceData, false); + referenceData, false, null); MappedAppSchema mappedSchema = mapper.getMappedSchema(); @@ -634,7 +634,7 @@ public void testWithReferenceData_ReferencedFeature_RefN() throws Exception { CRSRef storageCrs = CRSManager.getCRSRef("EPSG:4326"); GeometryStorageParams geometryParams = new GeometryStorageParams(storageCrs, "0", DIM_2); AppSchemaMapper mapper = new AppSchemaMapper(appSchema, false, true, geometryParams, 63, true, true, 0, - referenceData, false); + referenceData, false, null); MappedAppSchema mappedSchema = mapper.getMappedSchema(); @@ -683,7 +683,7 @@ public void testWithReferenceData_ReferencedFeature_Ref1() throws Exception { CRSRef storageCrs = CRSManager.getCRSRef("EPSG:4326"); GeometryStorageParams geometryParams = new GeometryStorageParams(storageCrs, "0", DIM_2); AppSchemaMapper mapper = new AppSchemaMapper(appSchema, false, true, geometryParams, 63, true, true, 0, - referenceData, false); + referenceData, false, null); MappedAppSchema mappedSchema = mapper.getMappedSchema(); @@ -722,7 +722,7 @@ public void testWithReferenceDataAndConsiderProperties() throws Exception { CRSRef storageCrs = CRSManager.getCRSRef("EPSG:4326"); GeometryStorageParams geometryParams = new GeometryStorageParams(storageCrs, "0", DIM_2); AppSchemaMapper mapper = new AppSchemaMapper(appSchema, false, true, geometryParams, 63, true, true, 0, - referenceData, true); + referenceData, true, null); MappedAppSchema mappedSchema = mapper.getMappedSchema(); @@ -755,7 +755,7 @@ public void testWithReferenceDataAndNilProperties() throws Exception { CRSRef storageCrs = CRSManager.getCRSRef("EPSG:4326"); GeometryStorageParams geometryParams = new GeometryStorageParams(storageCrs, "0", DIM_2); AppSchemaMapper mapper = new AppSchemaMapper(appSchema, false, true, geometryParams, 63, true, true, 0, - referenceData, true); + referenceData, true, null); MappedAppSchema mappedSchema = mapper.getMappedSchema(); @@ -778,7 +778,7 @@ public void testWithTimeProperties() throws Exception { CRSRef storageCrs = CRSManager.getCRSRef("EPSG:4326"); GeometryStorageParams geometryParams = new GeometryStorageParams(storageCrs, "0", DIM_2); AppSchemaMapper mapper = new AppSchemaMapper(appSchema, false, true, geometryParams, 63, true, true, 0, null, - false); + false, null); MappedAppSchema mappedSchema = mapper.getMappedSchema(); @@ -820,6 +820,27 @@ public void testWithTimeProperties() throws Exception { assertThat(getPrimitive(timePeriodOfTimeObject.getParticles(), "@gml:id"), is(notNullValue())); } + @Test + public void testWithoutDbSchema() throws Exception { + GMLAppSchemaReader xsdDecoder = new GMLAppSchemaReader(null, null, schemaForSampleValues); + AppSchema appSchema = xsdDecoder.extractAppSchema(); + + CRSRef storageCrs = CRSManager.getCRSRef("EPSG:4326"); + GeometryStorageParams geometryParams = new GeometryStorageParams(storageCrs, "0", DIM_2); + String dbSchema = "test"; + AppSchemaMapper mapper = new AppSchemaMapper(appSchema, false, true, geometryParams, 63, true, true, 0, null, + false, dbSchema); + + MappedAppSchema mappedSchema = mapper.getMappedSchema(); + + Map ftMappings = mappedSchema.getFtMappings(); + assertThat(ftMappings.size(), is(2)); + + FeatureTypeMapping featureA = mappedSchema.getFtMapping(FEATURE_A); + + assertThat(featureA.getFtTable().getSchema(), is(dbSchema)); + } + private CompoundMapping getFeatureC(List mappings) { return getCompound(mappings, "FeatureC"); } diff --git a/deegree-tools/deegree-tools-gml/src/main/java/org/deegree/tools/featurestoresql/config/FeatureStoreConfigWriter.java b/deegree-tools/deegree-tools-gml/src/main/java/org/deegree/tools/featurestoresql/config/FeatureStoreConfigWriter.java index 0730cff494..de2c14dd3a 100644 --- a/deegree-tools/deegree-tools-gml/src/main/java/org/deegree/tools/featurestoresql/config/FeatureStoreConfigWriter.java +++ b/deegree-tools/deegree-tools-gml/src/main/java/org/deegree/tools/featurestoresql/config/FeatureStoreConfigWriter.java @@ -82,7 +82,7 @@ public void write(List appSchemas) throws Exception { AppSchemaMapper mapper = new AppSchemaMapper(appSchema, !loadParameter.isRelationalMapping(), loadParameter.isRelationalMapping(), geometryParams, sqlDialect.getMaxColumnNameLength(), true, loadParameter.isUseIntegerFids(), loadParameter.getDepth(), loadParameter.getReferenceData(), - loadParameter.isUseRefDataProps()); + loadParameter.isUseRefDataProps(), loadParameter.getDbSchema()); MappedAppSchema mappedSchema = mapper.getMappedSchema(); SQLFeatureStoreConfigWriter configWriter = new SQLFeatureStoreConfigWriter(mappedSchema, loadParameter.getPropertiesWithPrimitiveHref()); diff --git a/deegree-tools/deegree-tools-gml/src/main/java/org/deegree/tools/featurestoresql/config/LoadParameter.java b/deegree-tools/deegree-tools-gml/src/main/java/org/deegree/tools/featurestoresql/config/LoadParameter.java index 2c10ce0204..82718d6f48 100644 --- a/deegree-tools/deegree-tools-gml/src/main/java/org/deegree/tools/featurestoresql/config/LoadParameter.java +++ b/deegree-tools/deegree-tools-gml/src/main/java/org/deegree/tools/featurestoresql/config/LoadParameter.java @@ -23,9 +23,8 @@ import org.deegree.feature.persistence.sql.mapper.ReferenceData; -import java.util.List; - import javax.xml.namespace.QName; +import java.util.List; /** * Load parameter. @@ -54,6 +53,8 @@ public class LoadParameter { private boolean useRefDataProps; + private String dbSchema; + LoadParameter() { } @@ -121,6 +122,14 @@ public void setDialect(String dialect) { this.dialect = dialect; } + public void setDbSchema(String dbSchema) { + this.dbSchema = dbSchema; + } + + public String getDbSchema() { + return dbSchema; + } + public void setDepth(int depth) { this.depth = depth; } diff --git a/deegree-tools/deegree-tools-gml/src/main/java/org/deegree/tools/featurestoresql/config/LoadParameterBuilder.java b/deegree-tools/deegree-tools-gml/src/main/java/org/deegree/tools/featurestoresql/config/LoadParameterBuilder.java index de1da7165f..538aaa40b9 100644 --- a/deegree-tools/deegree-tools-gml/src/main/java/org/deegree/tools/featurestoresql/config/LoadParameterBuilder.java +++ b/deegree-tools/deegree-tools-gml/src/main/java/org/deegree/tools/featurestoresql/config/LoadParameterBuilder.java @@ -83,6 +83,14 @@ public LoadParameterBuilder setDialect(String dialect) { return this; } + public LoadParameterBuilder setDbSchema(String dbSchema) { + if (dbSchema != null && dbSchema.isEmpty()) + loadParameter.setDbSchema(null); + else + loadParameter.setDbSchema(dbSchema); + return this; + } + public LoadParameterBuilder setSrid(String srid) { if (srid == null) loadParameter.setSrid(DEFAULT_SRID); diff --git a/deegree-tools/deegree-tools-gml/src/main/java/org/deegree/tools/featurestoresql/config/SqlFeatureStoreConfigCreatorConfiguration.java b/deegree-tools/deegree-tools-gml/src/main/java/org/deegree/tools/featurestoresql/config/SqlFeatureStoreConfigCreatorConfiguration.java index 55810d876b..464b69122e 100644 --- a/deegree-tools/deegree-tools-gml/src/main/java/org/deegree/tools/featurestoresql/config/SqlFeatureStoreConfigCreatorConfiguration.java +++ b/deegree-tools/deegree-tools-gml/src/main/java/org/deegree/tools/featurestoresql/config/SqlFeatureStoreConfigCreatorConfiguration.java @@ -54,7 +54,8 @@ public class SqlFeatureStoreConfigCreatorConfiguration { public LoadParameter parseJobParameter(@Value("#{jobParameters[schemaUrl]}") String schemaUrl, @Value("#{jobParameters[format]}") String format, @Value("#{jobParameters[srid]}") String srid, @Value("#{jobParameters[idtype]}") String idtype, @Value("#{jobParameters[mapping]}") String mapping, - @Value("#{jobParameters[dialect]}") String dialect, @Value("#{jobParameters[cycledepth]}") String depth, + @Value("#{jobParameters[dialect]}") String dialect, @Value("#{jobParameters[dbschema]}") String dbSchema, + @Value("#{jobParameters[cycledepth]}") String depth, @Value("#{jobParameters[listOfPropertiesWithPrimitiveHref]}") String listOfPropertiesWithPrimitiveHref, @Value("#{jobParameters[referenceData]}") String referenceData, @Value("#{jobParameters[useRefDataProps]}") String useRefDataProps) { @@ -64,6 +65,7 @@ public LoadParameter parseJobParameter(@Value("#{jobParameters[schemaUrl]}") Str .setIdType(idtype) .setMappingType(mapping) .setDialect(dialect) + .setDbSchema(dbSchema) .setDepth(depth) .setListOfPropertiesWithPrimitiveHref(listOfPropertiesWithPrimitiveHref) .setReferenceData(referenceData) diff --git a/deegree-tools/deegree-tools-gml/src/main/java/org/deegree/tools/featurestoresql/config/SqlFeatureStoreConfigCreatorUsagePrinter.java b/deegree-tools/deegree-tools-gml/src/main/java/org/deegree/tools/featurestoresql/config/SqlFeatureStoreConfigCreatorUsagePrinter.java index 819cc42c36..8ebad8dba4 100644 --- a/deegree-tools/deegree-tools-gml/src/main/java/org/deegree/tools/featurestoresql/config/SqlFeatureStoreConfigCreatorUsagePrinter.java +++ b/deegree-tools/deegree-tools-gml/src/main/java/org/deegree/tools/featurestoresql/config/SqlFeatureStoreConfigCreatorUsagePrinter.java @@ -42,6 +42,7 @@ public static void printUsage() { System.out.println(" -idtype={int|uuid}, default=int"); System.out.println(" -mapping={relational|blob}, default=relational"); System.out.println(" -dialect={postgis|oracle}, default=postgis"); + System.out.println(" -dbschema=STRING, name of the db schema to use, default: no schema"); System.out.println(" -cycledepth=INT, positive integer value to specify the depth of cycles, default=0"); System.out.println(" -listOfPropertiesWithPrimitiveHref=, not set by default"); System.out.println( From 182299f548f37ca716e009712974db1df5574082 Mon Sep 17 00:00:00 2001 From: Lyn Elisa Goltz Date: Wed, 10 Apr 2024 14:55:14 +0200 Subject: [PATCH 2/3] #9951 (#29) - added db schema to join tables --- .../feature/persistence/sql/mapper/AppSchemaMapper.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/mapper/AppSchemaMapper.java b/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/mapper/AppSchemaMapper.java index 21e2cdc25a..f9e0722e99 100644 --- a/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/mapper/AppSchemaMapper.java +++ b/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/mapper/AppSchemaMapper.java @@ -564,8 +564,8 @@ private CompoundMapping generatePropMapping(CodePropertyType pt, MappingContext } private List generateJoinChain(MappingContext from, MappingContext to) { - TableName fromTable = new TableName(from.getTable()); - TableName toTable = new TableName(to.getTable()); + TableName fromTable = new TableName(from.getTable(), dbSchema); + TableName toTable = new TableName(to.getTable(), dbSchema); List fromColumns = Collections.singletonList(from.getIdColumn()); List toColumns = Collections.singletonList("parentfk"); List orderColumns = Collections.singletonList("num"); @@ -580,7 +580,7 @@ private TableJoin generateFtJoin(MappingContext from, FeatureType valueFt) { if (valueFt != null && valueFt.getSchema().getSubtypes(valueFt).length == 1) { LOG.warn("Ambiguous feature join."); } - TableName fromTable = new TableName(from.getTable()); + TableName fromTable = new TableName(from.getTable(), dbSchema); TableName toTable = new TableName("?"); List fromColumns = Collections.singletonList(from.getColumn()); List toColumns = Collections.singletonList(detectPrimaryKeyColumnName()); From 7d7777cef0a5444e86fc20cbe4b9afbb073c9db3 Mon Sep 17 00:00:00 2001 From: Lyn Elisa Goltz Date: Mon, 6 May 2024 06:40:39 +0200 Subject: [PATCH 3/3] #9551 (#29) - create schema if not exists --- .../org/deegree/feature/persistence/sql/ddl/DDLCreator.java | 6 +++++- .../feature/persistence/sql/ddl/PostGISDDLCreator.java | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/ddl/DDLCreator.java b/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/ddl/DDLCreator.java index e6b04e8407..750896276c 100644 --- a/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/ddl/DDLCreator.java +++ b/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/ddl/DDLCreator.java @@ -174,7 +174,7 @@ private List process(FeatureTypeMapping ftMapping) { protected void appendCreateSchema(String schema, StringBuffer sql) { if (schema != null && !createdSchemas.contains(schema)) { - sql.append("CREATE SCHEMA ").append(schema).append(";\n"); + createSchemaSnippet(schema, sql); createdSchemas.add(schema); } } @@ -191,6 +191,10 @@ private String getPkConstraintName(TableName ftTable) { return s; } + protected void createSchemaSnippet(String schema, StringBuffer sql) { + sql.append("CREATE SCHEMA ").append(schema).append(";\n"); + } + protected abstract void primitiveMappingSnippet(StringBuffer sql, PrimitiveMapping mapping); protected abstract void geometryMappingSnippet(StringBuffer sql, GeometryMapping mapping, List ddls, diff --git a/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/ddl/PostGISDDLCreator.java b/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/ddl/PostGISDDLCreator.java index a48f47c05d..7a70e98035 100644 --- a/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/ddl/PostGISDDLCreator.java +++ b/deegree-datastores/deegree-featurestores/deegree-featurestore-sql/src/main/java/org/deegree/feature/persistence/sql/ddl/PostGISDDLCreator.java @@ -241,6 +241,10 @@ protected String getDBType(BaseType type) { return postgresqlType; } + protected void createSchemaSnippet(String schema, StringBuffer sql) { + sql.append("CREATE SCHEMA IF NOT EXISTS ").append(schema).append(";\n"); + } + private String retrieveTypeOfPrimaryKey(TableName fromTable, SQLIdentifier toColumn, FIDMapping fidMapping) { if (fidMapping != null) { for (Pair column : fidMapping.getColumns()) {