use of org.apache.sis.storage.sql.SQLStoreProvider in project sis by apache.
the class PostgresTest method testSpatialFeatures.
/**
* Tests reading and writing features and rasters.
*
* @throws Exception if an error occurred while testing the database.
*/
@Test
public void testSpatialFeatures() throws Exception {
try (TestDatabase database = TestDatabase.createOnPostgreSQL(SQLStoreTest.SCHEMA, true)) {
database.executeSQL(PostgresTest.class, "file:SpatialFeatures.sql");
final StorageConnector connector = new StorageConnector(database.source);
connector.setOption(OptionKey.GEOMETRY_LIBRARY, GeometryLibrary.JTS);
final ResourceDefinition table = ResourceDefinition.table(null, SQLStoreTest.SCHEMA, "SpatialData");
try (SQLStore store = new SQLStore(new SQLStoreProvider(), connector, table)) {
/*
* Invoke the private `model()` method. We have to use reflection because the class
* is not in the same package and we do not want to expose the method in public API.
*/
final Method modelAccessor = SQLStore.class.getDeclaredMethod("model");
modelAccessor.setAccessible(true);
final Postgres<?> pg = (Postgres<?>) modelAccessor.invoke(store);
try (Connection connection = database.source.getConnection();
ExtendedInfo info = new ExtendedInfo(pg, connection)) {
testInfoStatements(info);
testGeometryGetter(info, connection);
testRasterReader(TestRaster.USHORT, info, connection);
}
/*
* Tests through public API.
*/
final FeatureSet resource = store.findResource("SpatialData");
try (Stream<AbstractFeature> features = resource.features(false)) {
features.forEach(PostgresTest::validate);
}
final Envelope envelope = resource.getEnvelope().get();
assertEquals(envelope.getMinimum(0), -72, 1);
assertEquals(envelope.getMaximum(1), 43, 1);
}
}
}
use of org.apache.sis.storage.sql.SQLStoreProvider in project sis by apache.
the class SelectionClauseWriterTest method testOnDerby.
/**
* Tests on Derby.
*
* @throws Exception if an error occurred while testing the database.
*/
@Test
public void testOnDerby() throws Exception {
try (TestDatabase db = TestDatabase.create("SQLStore")) {
db.executeSQL(SelectionClauseWriterTest.class, "CREATE TABLE TEST (ALPHA INTEGER, BETA INTEGER, GAMMA INTEGER, PI FLOAT);");
final StorageConnector connector = new StorageConnector(db.source);
connector.setOption(SchemaModifier.OPTION, this);
try (DataStore store = new SQLStoreProvider().open(connector)) {
table = (Table) store.findResource("TEST");
testSimpleFilter();
testGeometricFilter();
testGeometricFilterWithTransform();
}
}
}
Aggregations