Closed ccarlow closed 4 years ago
Created pull request #16
So the patch fails at least for H2GISTest.updateGeometry_Columns() which creates the table using GEOMETRY(POLYGON) so the syntax seems correct after all but it gets created via dialect.postCreateTable() so the ALTER COLUMN statement only fails when called using dataStore.createSchema().
Sample code for reference:
String typeName = "blah";
Map<String, Object> params = new HashMap<>();
H2GISDataStoreFactory factory = new H2GISDataStoreFactory();
params.put(JDBCDataStoreFactory.NAMESPACE.key, "http://www.h2gis.org/test");
params.put(JDBCDataStoreFactory.DATABASE.key, "mem:" + typeName);
params.put(JDBCDataStoreFactory.DBTYPE.key, "h2gis");
params.put(JDBCDataStoreFactory.HOST.key, "localhost");
JDBCDataStore dataStore = null;
try {
dataStore = factory.createDataStore( params );
System.out.println(dataStore);
} catch (IOException e1) {
e1.printStackTrace();
}
try {
Iterator availableStores = DataStoreFinder.getAvailableDataStores();
System.out.println("List available Stores: ");
while (availableStores.hasNext()) {
System.out.println(availableStores.next().toString());
}
SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
//set global state
typeBuilder.setName(typeName);
typeBuilder.setNamespaceURI( "http://www.geotools.org/" );
typeBuilder.setSRS( "EPSG:4326" );
//add attributes
typeBuilder.add( "the_geom", Point.class );
typeBuilder.add( "intProperty", Integer.class );
typeBuilder.add( "stringProperty", String.class );
typeBuilder.add( "pointProperty", Point.class );
SimpleFeatureType featureType = typeBuilder.buildFeatureType();
dataStore.createSchema(featureType);
} catch (Exception e) {
e.printStackTrace();
}
I'm not entirely sure how H2GISTest.updateGeometry_Columns() is even able to use the GEOMETRY(POLYGON) syntax. Maybe factory.createSQLDialect(ds) enables something?
When I try to run the command manually it gives the original error. The example code given on the main page uses syntax "THE_GEOM MULTIPOLYGON" not "THE_GEOM GEOMETRY(MULTIPOLYGON)".
I'm not sure if the ALTER STATEMENT is even necessary in H2GISDialoect.postCreateTable(). When removed entirely it fixes both DataStore.createSchema() and H2GISTest.updateGeometry_Columns() failures.
Updated pull request with ALTER STATEMENT removed and no tests failed this time. Just need an expert to review since I'm not aware of how the change could break something else.
The following error is thrown when calling DataStore.createSchema(featureType):
It seems to be fixed by changing the ALTER TABLE statement from
+ "GEOMETRY(" + geomType + "); "
to+ geomType + "; "