Search in sources :

Example 6 with Session

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

the class PostgresSimpleTypeTest method testArray2Insert.

@Test
public void testArray2Insert() throws DataStoreException, VersioningException {
    reload(true);
    store.createFeatureType(FTYPE_ARRAY2);
    final FeatureType resType = store.getFeatureType(store.getNames().iterator().next().toString());
    final Feature feature = resType.newInstance();
    feature.setPropertyValue("fid", 0);
    feature.setPropertyValue("boolean", new Boolean[][] { { true, false, true }, { false, true, false }, { false, false, false } });
    feature.setPropertyValue("byte", new Short[][] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } });
    feature.setPropertyValue("short", new Short[][] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } });
    feature.setPropertyValue("integer", new Integer[][] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } });
    feature.setPropertyValue("long", new Long[][] { { 1l, 2l, 3l }, { 4l, 5l, 6l }, { 7l, 8l, 9l } });
    feature.setPropertyValue("float", new Float[][] { { 1f, 2f, 3f }, { 4f, 5f, 6f }, { 7f, 8f, 9f } });
    feature.setPropertyValue("double", new Double[][] { { 1d, 2d, 3d }, { 4d, 5d, 6d }, { 7d, 8d, 9d } });
    feature.setPropertyValue("string", new String[][] { { "1", "2", "3" }, { "4", "5", "6" }, { "7", "8", "9" } });
    List<ResourceId> addedIds = store.addFeatures(resType.getName().toString(), Collections.singleton(feature));
    assertEquals(1, addedIds.size());
    assertEquals(FF.resourceId("1"), addedIds.get(0));
    final Session session = store.createSession(false);
    final FeatureCollection col = session.getFeatureCollection(new Query(resType.getName()));
    assertEquals(1, col.size());
    // Postgis allow NULL in arrays, so returned array are not primitive types
    final FeatureIterator ite = col.iterator();
    try {
        final Feature resFeature = ite.next();
        assertNotNull(resFeature);
        assertArrayEquals((Boolean[][]) feature.getPropertyValue("boolean"), (Boolean[][]) resFeature.getPropertyValue("boolean"));
        assertArrayEquals((Short[][]) feature.getPropertyValue("byte"), (Short[][]) resFeature.getPropertyValue("byte"));
        assertArrayEquals((Short[][]) feature.getPropertyValue("short"), (Short[][]) resFeature.getPropertyValue("short"));
        assertArrayEquals((Integer[][]) feature.getPropertyValue("integer"), (Integer[][]) resFeature.getPropertyValue("integer"));
        assertArrayEquals((Long[][]) feature.getPropertyValue("long"), (Long[][]) resFeature.getPropertyValue("long"));
        assertArrayEquals((Float[][]) feature.getPropertyValue("float"), (Float[][]) resFeature.getPropertyValue("float"));
        assertArrayEquals((Double[][]) feature.getPropertyValue("double"), (Double[][]) resFeature.getPropertyValue("double"));
        assertArrayEquals((String[][]) feature.getPropertyValue("string"), (String[][]) resFeature.getPropertyValue("string"));
    } finally {
        ite.close();
    }
}
Also used : FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) FeatureType(org.opengis.feature.FeatureType) Query(org.geotoolkit.storage.feature.query.Query) ResourceId(org.opengis.filter.ResourceId) FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) Feature(org.opengis.feature.Feature) Session(org.geotoolkit.storage.feature.session.Session) Test(org.junit.Test)

Example 7 with Session

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

the class ShapefileReadWriteTest method test.

private void test(final FeatureType type, final FeatureCollection original, final File tmp, final ShapefileProvider maker, final boolean memorymapped, final Charset charset) throws IOException, MalformedURLException, Exception {
    ShapefileFeatureStore shapefile;
    GenericName typeName = type.getName();
    final ParameterValueGroup params = maker.getOpenParameters().createValue();
    params.parameter(ShapefileProvider.LOCATION).setValue(tmp.toURI());
    params.parameter(ShapefileProvider.MEMORY_MAPPED.getName().toString()).setValue(memorymapped);
    params.parameter(ShapefileProvider.DBFCHARSET.getName().toString()).setValue(charset);
    shapefile = (ShapefileFeatureStore) maker.open(params);
    shapefile.createFeatureType(type);
    Session session = shapefile.createSession(true);
    session.addFeatures(typeName.toString(), original);
    session.commit();
    assertFalse(session.hasPendingChanges());
    FeatureCollection copy = session.getFeatureCollection(new Query(typeName));
    compare(original, copy);
    // review open
    ShapefileFeatureStore review = new ShapefileFeatureStore(tmp.toURI(), memorymapped, charset);
    typeName = review.getNames().iterator().next();
    FeatureCollection again = review.createSession(true).getFeatureCollection(new Query(typeName));
    compare(copy, again);
    compare(original, again);
}
Also used : GenericName(org.opengis.util.GenericName) Query(org.geotoolkit.storage.feature.query.Query) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) Session(org.geotoolkit.storage.feature.session.Session)

Example 8 with Session

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

the class ShapefileTest method testHolyPolygons.

@Test
public void testHolyPolygons() throws Exception {
    final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
    ftb.setName("test");
    ftb.addAttribute(MultiPolygon.class).setName("a").addRole(AttributeRole.DEFAULT_GEOMETRY);
    final FeatureType type = ftb.build();
    Collection<Feature> features = new ArrayList<>();
    File tmpFile = getTempFile();
    tmpFile.delete();
    // write features
    ShapefileProvider make = new ShapefileProvider();
    String pathId = ShapefileProvider.PATH.getName().getCode();
    FeatureStore s = (FeatureStore) make.create(Parameters.toParameter(Collections.singletonMap(pathId, tmpFile.toURI().toURL()), make.getOpenParameters()));
    s.createFeatureType(type);
    GenericName typeName = type.getName();
    Session session = s.createSession(true);
    session.addFeatures(typeName.toString(), features);
    session.commit();
    s = new ShapefileFeatureStore(tmpFile.toURI());
    typeName = s.getNames().iterator().next();
    FeatureCollection fc = s.createSession(true).getFeatureCollection(new Query(typeName));
    ShapefileReadWriteTest.compare(features, fc);
}
Also used : FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) FeatureType(org.opengis.feature.FeatureType) Query(org.geotoolkit.storage.feature.query.Query) ArrayList(java.util.ArrayList) Feature(org.opengis.feature.Feature) GenericName(org.opengis.util.GenericName) FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) File(java.io.File) FeatureStore(org.geotoolkit.storage.feature.FeatureStore) Session(org.geotoolkit.storage.feature.session.Session) Test(org.junit.Test)

Example 9 with Session

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

the class IndexedShapefileDataStoreTest method testTestTransaction.

@Test
public void testTestTransaction() throws Exception {
    final IndexedShapefileFeatureStore sds = createDataStore();
    final long idx = sds.getCount(new Query(sds.getName()));
    final Session session = sds.createSession(true);
    Feature[] newFeatures1 = new Feature[1];
    Feature[] newFeatures2 = new Feature[2];
    GeometryFactory fac = org.geotoolkit.geometry.jts.JTS.getFactory();
    newFeatures1[0] = sds.getFeatureType().newInstance();
    newFeatures1[0].setPropertyValue("a", fac.createPoint(new Coordinate(0, 0)));
    newFeatures2[0] = sds.getFeatureType().newInstance();
    newFeatures2[0].setPropertyValue("a", fac.createPoint(new Coordinate(0, 0)));
    newFeatures2[1] = sds.getFeatureType().newInstance();
    newFeatures2[1].setPropertyValue("a", fac.createPoint(new Coordinate(0, 0)));
    session.addFeatures(sds.getName().toString(), FeatureStoreUtilities.collection(newFeatures1));
    session.addFeatures(sds.getName().toString(), FeatureStoreUtilities.collection(newFeatures2));
    session.commit();
    assertEquals(idx + 3, sds.getCount(new Query(sds.getName())));
    sds.close();
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Query(org.geotoolkit.storage.feature.query.Query) Coordinate(org.locationtech.jts.geom.Coordinate) Feature(org.opengis.feature.Feature) Session(org.geotoolkit.storage.feature.session.Session) Test(org.junit.Test)

Example 10 with Session

use of org.geotoolkit.storage.feature.session.Session 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);
}
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) FeatureStore(org.geotoolkit.storage.feature.FeatureStore) Session(org.geotoolkit.storage.feature.session.Session) ShapefileProvider(org.geotoolkit.data.shapefile.ShapefileProvider)

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