Search in sources :

Example 16 with ResourceId

use of org.opengis.filter.ResourceId in project geotoolkit by Geomatys.

the class AddDelta method commit.

/**
 * {@inheritDoc }
 */
@Override
public Map<String, String> commit(final FeatureStore store) throws DataStoreException {
    final List<ResourceId> createdIds = store.addFeatures(type.toString(), features);
    // iterator and list should have the same size
    final Map<String, String> updates = new HashMap<String, String>();
    final FeatureIterator ite = features.iterator();
    int i = 0;
    try {
        if (createdIds != null && !createdIds.isEmpty()) {
            while (ite.hasNext()) {
                final Feature f = ite.next();
                final String id = FeatureExt.getId(f).getIdentifier();
                updates.put(id, createdIds.get(i).getIdentifier());
                i++;
            }
        }
    } finally {
        ite.close();
    }
    features.clear();
    return updates;
}
Also used : FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) ResourceId(org.opengis.filter.ResourceId) HashMap(java.util.HashMap) Feature(org.opengis.feature.Feature)

Example 17 with ResourceId

use of org.opengis.filter.ResourceId in project geotoolkit by Geomatys.

the class IdTest method testFeatureId.

@Test
public void testFeatureId() {
    String strid = "testFeatureType.1";
    ResourceId id1 = FF.resourceId(strid);
    ResourceId id2 = FF.resourceId(strid);
    assertEquals(strid, id1.getIdentifier());
    assertEquals(id1, id2);
}
Also used : ResourceId(org.opengis.filter.ResourceId) Test(org.junit.Test)

Example 18 with ResourceId

use of org.opengis.filter.ResourceId in project geotoolkit by Geomatys.

the class FIDFixVisitorTest method testReplacement1.

@Test
public void testReplacement1() {
    Filter filter = FF.equal(FF.property(AttributeConvention.IDENTIFIER), FF.literal("river.1"));
    filter = (Filter) FIDFixVisitor.INSTANCE.visit(filter);
    assertNotNull(filter);
    assertTrue(filter instanceof ResourceId);
    ResourceId fid = (ResourceId) filter;
    assertEquals("river.1", fid.getIdentifier());
}
Also used : Filter(org.opengis.filter.Filter) ResourceId(org.opengis.filter.ResourceId) Test(org.junit.Test)

Example 19 with ResourceId

use of org.opengis.filter.ResourceId in project geotoolkit by Geomatys.

the class FIDFixVisitorTest method testReplacement2.

@Test
public void testReplacement2() {
    Filter filter = FF.equal(FF.literal("river.1"), FF.property(AttributeConvention.IDENTIFIER));
    filter = (Filter) FIDFixVisitor.INSTANCE.visit(filter);
    assertNotNull(filter);
    assertTrue(filter instanceof ResourceId);
    ResourceId fid = (ResourceId) filter;
    assertEquals("river.1", fid.getIdentifier());
}
Also used : Filter(org.opengis.filter.Filter) ResourceId(org.opengis.filter.ResourceId) Test(org.junit.Test)

Example 20 with ResourceId

use of org.opengis.filter.ResourceId in project geotoolkit by Geomatys.

the class JDBCFeatureWriterUpdate method write.

@Override
public void write() throws FeatureStoreRuntimeException {
    if (last == null) {
        throw new FeatureStoreRuntimeException("Cursor is not on a record.");
    }
    try {
        // figure out what the fid is
        final PrimaryKey key = store.getDatabaseModel().getPrimaryKey(type.getName().toString());
        final String fid = key.encodeFID(rs);
        final FilterFactory ff = store.getFilterFactory();
        final ResourceId filter = ff.resourceId(fid);
        // figure out which attributes changed
        final Map<String, Object> changes = new HashMap<>();
        for (final PropertyType att : type.getProperties(true)) {
            if (att instanceof FeatureAssociationRole || att instanceof Operation || AttributeConvention.contains(att.getName())) {
                // not a writable property
                continue;
            }
            changes.put(att.getName().tip().toString(), last.getPropertyValue(att.getName().toString()));
        }
        // do the write
        store.updateSingle(type, changes, filter, st.getConnection());
    } catch (Exception e) {
        throw new FeatureStoreRuntimeException(e);
    }
}
Also used : ResourceId(org.opengis.filter.ResourceId) HashMap(java.util.HashMap) FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException) PrimaryKey(org.geotoolkit.db.reverse.PrimaryKey) PropertyType(org.opengis.feature.PropertyType) Operation(org.opengis.feature.Operation) FeatureAssociationRole(org.opengis.feature.FeatureAssociationRole) FilterFactory(org.opengis.filter.FilterFactory) IOException(java.io.IOException) SQLException(java.sql.SQLException) DataStoreException(org.apache.sis.storage.DataStoreException) FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException)

Aggregations

ResourceId (org.opengis.filter.ResourceId)45 Feature (org.opengis.feature.Feature)26 Test (org.junit.Test)23 FeatureIterator (org.geotoolkit.storage.feature.FeatureIterator)20 FeatureType (org.opengis.feature.FeatureType)20 Query (org.geotoolkit.storage.feature.query.Query)18 HashMap (java.util.HashMap)11 Coordinate (org.locationtech.jts.geom.Coordinate)11 Point (org.locationtech.jts.geom.Point)10 Filter (org.opengis.filter.Filter)10 DataStoreException (org.apache.sis.storage.DataStoreException)9 Session (org.geotoolkit.storage.feature.session.Session)9 Geometry (org.locationtech.jts.geom.Geometry)9 Date (java.util.Date)8 PropertyType (org.opengis.feature.PropertyType)8 ArrayList (java.util.ArrayList)7 FeatureCollection (org.geotoolkit.storage.feature.FeatureCollection)7 Version (org.geotoolkit.version.Version)6 VersionControl (org.geotoolkit.version.VersionControl)6 IOException (java.io.IOException)5