Search in sources :

Example 11 with Session

use of org.geotoolkit.storage.feature.session.Session in project geotoolkit by Geomatys.

the class ShapefileRTreeReadWriteTest method doubleWrite.

private void doubleWrite(final FeatureType type, final FeatureCollection one, final File tmp, final boolean memorymapped) throws IOException, MalformedURLException, DataStoreException {
    IndexedShapefileFeatureStore s;
    s = new IndexedShapefileFeatureStore(tmp.toURI(), memorymapped, true);
    s.createFeatureType(type);
    Session session = s.createSession(true);
    session.addFeatures(type.getName().toString(), one);
    session.addFeatures(type.getName().toString(), one);
    session.commit();
    s = new IndexedShapefileFeatureStore(tmp.toURI());
    assertEquals(one.size() * 2, s.getCount(new Query(s.getName())));
    s.close();
}
Also used : Query(org.geotoolkit.storage.feature.query.Query) Session(org.geotoolkit.storage.feature.session.Session)

Example 12 with Session

use of org.geotoolkit.storage.feature.session.Session in project geotoolkit by Geomatys.

the class ShapefileRTreeReadWriteTest method test.

private void test(final FeatureType type, final FeatureCollection one, final File tmp, final boolean memorymapped) throws IOException, MalformedURLException, Exception {
    IndexedShapefileFeatureStore s;
    GenericName typeName;
    s = (IndexedShapefileFeatureStore) new IndexedShapefileFeatureStore(tmp.toURI(), memorymapped, true);
    s.createFeatureType(type);
    Session session = s.createSession(true);
    session.addFeatures(s.getName().toString(), one);
    session.commit();
    s.close();
    s = new IndexedShapefileFeatureStore(tmp.toURI());
    typeName = s.getName();
    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);
    // compare(one.iterator(), two.iterator());
    s.close();
}
Also used : GenericName(org.opengis.util.GenericName) Query(org.geotoolkit.storage.feature.query.Query) FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) ArrayList(java.util.ArrayList) Feature(org.opengis.feature.Feature) Session(org.geotoolkit.storage.feature.session.Session)

Example 13 with Session

use of org.geotoolkit.storage.feature.session.Session in project geotoolkit by Geomatys.

the class FeatureStoreUtilities method collection.

public static FeatureCollection collection(final NamedIdentifier id, FeatureType type) {
    if (type == null) {
        // a collection with no defined type, make a generic abstract type
        // that is possible since feature collection may not always have a type.
        final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
        ftb.setName("null");
        ftb.setAbstract(true);
        type = ftb.build();
    }
    final MemoryFeatureStore ds = new MemoryFeatureStore(type, true);
    final Session session = ds.createSession(false);
    FeatureCollection col = session.getFeatureCollection(new Query(type.getName()));
    ((AbstractFeatureCollection) col).setIdentifier(id);
    return col;
}
Also used : FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) Query(org.geotoolkit.storage.feature.query.Query) GenericMappingFeatureCollection(org.geotoolkit.storage.memory.GenericMappingFeatureCollection) MemoryFeatureStore(org.geotoolkit.storage.memory.MemoryFeatureStore) Session(org.geotoolkit.storage.feature.session.Session)

Example 14 with Session

use of org.geotoolkit.storage.feature.session.Session 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
        }
    }
}
Also used : FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) FeatureType(org.opengis.feature.FeatureType) GenericName(org.opengis.util.GenericName) DataStoreException(org.apache.sis.storage.DataStoreException) FeatureStore(org.geotoolkit.storage.feature.FeatureStore) DataStoreException(org.apache.sis.storage.DataStoreException) Session(org.geotoolkit.storage.feature.session.Session) Test(org.junit.Test)

Example 15 with Session

use of org.geotoolkit.storage.feature.session.Session in project geotoolkit by Geomatys.

the class ShapefileReadWriteTest method test.

private void test(final String f, final Charset charset) throws Exception {
    // Work on File rather than URL from JAR.
    copyShapefiles(f);
    ShapefileFeatureStore s = new ShapefileFeatureStore(TestData.url(AbstractTestCaseSupport.class, f).toURI(), false, charset);
    GenericName typeName = s.getNames().iterator().next();
    Session session = s.createSession(true);
    FeatureType type = s.getFeatureType(typeName.toString());
    FeatureCollection one = session.getFeatureCollection(new Query(typeName));
    File tmp = getTempFile();
    ShapefileProvider maker = new ShapefileProvider();
    test(type, one, tmp, maker, true, charset);
    // TODO consider reuse tmp results in
    File tmp2 = getTempFile();
    // failure
    test(type, one, tmp2, maker, false, charset);
}
Also used : FeatureType(org.opengis.feature.FeatureType) GenericName(org.opengis.util.GenericName) Query(org.geotoolkit.storage.feature.query.Query) FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) File(java.io.File) Session(org.geotoolkit.storage.feature.session.Session)

Aggregations

Session (org.geotoolkit.storage.feature.session.Session)21 Query (org.geotoolkit.storage.feature.query.Query)20 FeatureType (org.opengis.feature.FeatureType)14 Test (org.junit.Test)13 Feature (org.opengis.feature.Feature)13 FeatureCollection (org.geotoolkit.storage.feature.FeatureCollection)12 FeatureIterator (org.geotoolkit.storage.feature.FeatureIterator)10 ResourceId (org.opengis.filter.ResourceId)9 GenericName (org.opengis.util.GenericName)7 Date (java.util.Date)5 FeatureStore (org.geotoolkit.storage.feature.FeatureStore)5 Coordinate (org.locationtech.jts.geom.Coordinate)5 Point (org.locationtech.jts.geom.Point)4 ArrayList (java.util.ArrayList)3 FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)3 SQLQuery (org.geotoolkit.storage.feature.query.SQLQuery)3 Version (org.geotoolkit.version.Version)3 GeometryCollection (org.locationtech.jts.geom.GeometryCollection)3 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)3 File (java.io.File)2