use of org.geotoolkit.storage.feature.FeatureStore in project geotoolkit by Geomatys.
the class ShapefileQuadTreeReadWriteTest method test.
private void test(final FeatureType type, final FeatureCollection one, final File tmp, final ShapefileProvider maker, final boolean memorymapped) throws IOException, MalformedURLException, Exception {
FeatureStore s;
s = createDataStore(maker, tmp.toURI().toURL(), memorymapped);
s.createFeatureType(type);
Session session = s.createSession(true);
session.addFeatures(type.getName().toString(), one);
session.commit();
s = createDataStore(new ShapefileProvider(), tmp.toURI().toURL(), true);
GenericName typeName = s.getNames().iterator().next();
FeatureCollection two = s.createSession(true).getFeatureCollection(new Query(typeName));
// copy values, order is not tested here.
Collection<Feature> cone = new ArrayList<>();
Collection<Feature> ctwo = new ArrayList<>();
FeatureStoreUtilities.fill(one, cone);
FeatureStoreUtilities.fill(two, ctwo);
// one.containsAll(two);
// two.containsAll(one);
}
use of org.geotoolkit.storage.feature.FeatureStore in project geotoolkit by Geomatys.
the class ShapefileQuadTreeReadWriteTest method test.
void test(final String f) throws Exception {
// ShapeTestData.url(f)
// File file = copyShapefiles(f); // Work on File rather than URL from
// // JAR.
FeatureStore s = createDataStore(new ShapefileProvider(), ShapeTestData.url(f), true);
GenericName typeName = s.getNames().iterator().next();
FeatureType type = s.getFeatureType(typeName.toString());
FeatureCollection one = s.createSession(true).getFeatureCollection(new Query(typeName));
ShapefileProvider maker = new ShapefileProvider();
test(type, one, getTempFile(), maker, false);
test(type, one, getTempFile(), maker, true);
}
use of org.geotoolkit.storage.feature.FeatureStore in project geotoolkit by Geomatys.
the class AbstractModelTests method testDataStore.
@Test
public void testDataStore() {
final FeatureStore store = getDataStore();
assertNotNull(store);
}
use of org.geotoolkit.storage.feature.FeatureStore in project geotoolkit by Geomatys.
the class AbstractModelTests method testSchemaCreation.
@Test
public void testSchemaCreation() throws Exception {
final FeatureStore store = getDataStore();
final List<Class> geometryBindings = getSupportedGeometryTypes();
final List<Class> bindinds = getSupportedAttributTypes();
FeatureTypeBuilder sftb = new FeatureTypeBuilder();
final Session session = store.createSession(true);
for (final Class geomType : geometryBindings) {
// create the schema ------------------------------------------------
final String name = "testname";
sftb = new FeatureTypeBuilder();
sftb.setName(name);
sftb.addAttribute(geomType).setName("att_geometry").setCRS(CommonCRS.WGS84.geographic()).addRole(AttributeRole.DEFAULT_GEOMETRY);
for (int i = 0; i < bindinds.size(); i++) {
sftb.addAttribute(bindinds.get(i)).setName("att" + i);
}
final FeatureType sft = sftb.build();
// add listeners
StorageCountListener storeListen = new StorageCountListener();
StorageCountListener sessionListen = new StorageCountListener();
store.addListener(StoreEvent.class, storeListen);
session.addListener(StoreEvent.class, sessionListen);
store.createFeatureType(sft);
final FeatureType type = store.getFeatureType(name);
assertNotNull(type);
assertTrue(FeatureTypeExt.equalsIgnoreConvention(sft, type));
// check listeners
// assertEquals(1, storeListen.numManageEvent);
// assertEquals(1, sessionListen.numManageEvent);
// assertEquals(0, storeListen.numContentEvent);
// assertEquals(0, sessionListen.numContentEvent);
// assertNotNull(storeListen.lastManagementEvent);
// assertNotNull(sessionListen.lastManagementEvent);
// assertNull(storeListen.lastContentEvent);
// assertNull(sessionListen.lastContentEvent);
// assertEquals(StorageManagementEvent.Type.ADD, storeListen.lastManagementEvent.getType());
// assertEquals(StorageManagementEvent.Type.ADD, sessionListen.lastManagementEvent.getType());
// assertEquals(name, storeListen.lastManagementEvent.getFeatureTypeName().getLocalPart());
// assertEquals(name, sessionListen.lastManagementEvent.getFeatureTypeName().getLocalPart());
// assertEquals(sft, storeListen.lastManagementEvent.getNewFeatureType());
// assertEquals(sft, sessionListen.lastManagementEvent.getNewFeatureType());
// assertEquals(null, storeListen.lastManagementEvent.getOldFeatureType());
// assertEquals(null, sessionListen.lastManagementEvent.getOldFeatureType());
store.removeListener(StoreEvent.class, storeListen);
session.removeListener(StoreEvent.class, sessionListen);
// delete the created schema ----------------------------------------
GenericName nsname = null;
for (GenericName n : store.getNames()) {
if (n.tip().toString().equalsIgnoreCase(name)) {
nsname = n;
break;
}
}
assertNotNull(nsname);
readAndWriteTest(store, nsname);
// add listeners
storeListen = new StorageCountListener();
sessionListen = new StorageCountListener();
store.addListener(StoreEvent.class, storeListen);
session.addListener(StoreEvent.class, sessionListen);
store.deleteFeatureType(nsname.toString());
// check listeners
// assertEquals(1, storeListen.numManageEvent);
// assertEquals(1, sessionListen.numManageEvent);
// assertEquals(0, storeListen.numContentEvent);
// assertEquals(0, sessionListen.numContentEvent);
// assertNotNull(storeListen.lastManagementEvent);
// assertNotNull(sessionListen.lastManagementEvent);
// assertNull(storeListen.lastContentEvent);
// assertNull(sessionListen.lastContentEvent);
// assertEquals(StorageManagementEvent.Type.DELETE, storeListen.lastManagementEvent.getType());
// assertEquals(StorageManagementEvent.Type.DELETE, sessionListen.lastManagementEvent.getType());
// assertEquals(name, storeListen.lastManagementEvent.getFeatureTypeName().getLocalPart());
// assertEquals(name, sessionListen.lastManagementEvent.getFeatureTypeName().getLocalPart());
// assertEquals(null, storeListen.lastManagementEvent.getNewFeatureType());
// assertEquals(null, sessionListen.lastManagementEvent.getNewFeatureType());
// assertEquals(sft, storeListen.lastManagementEvent.getOldFeatureType());
// assertEquals(sft, sessionListen.lastManagementEvent.getOldFeatureType());
store.removeListener(StoreEvent.class, storeListen);
session.removeListener(StoreEvent.class, sessionListen);
try {
store.getFeatureType(nsname.toString());
throw new Exception("Should have raised an error.");
} catch (DataStoreException ex) {
// ok
}
}
}
use of org.geotoolkit.storage.feature.FeatureStore in project geotoolkit by Geomatys.
the class PostgisDemo method main.
public static void main(String[] args) throws DataStoreException {
Demos.init();
System.out.println(PostgresProvider.PARAMETERS_DESCRIPTOR);
final Parameters parameters = Parameters.castOrWrap(PostgresProvider.PARAMETERS_DESCRIPTOR.createValue());
parameters.getOrCreate(PostgresProvider.HOST).setValue("hote");
parameters.getOrCreate(PostgresProvider.PORT).setValue(5432);
parameters.getOrCreate(PostgresProvider.DATABASE).setValue("base");
parameters.getOrCreate(PostgresProvider.USER).setValue("user");
parameters.getOrCreate(PostgresProvider.PASSWORD).setValue("secret");
final FeatureStore store = (FeatureStore) DataStores.open(parameters);
final MapLayers context = MapBuilder.createContext();
for (GenericName n : store.getNames()) {
System.out.println(store.getFeatureType(n.toString()));
final FeatureSet col = store.createSession(true).getFeatureCollection(new Query(n));
final MapLayer layer = MapBuilder.createLayer(col);
layer.setStyle(RandomStyleBuilder.createRandomVectorStyle(col.getType()));
context.getComponents().add(layer);
}
// FXMapFrame.show(context);
}
Aggregations