use of org.opengis.filter.ResourceId in project geotoolkit by Geomatys.
the class FidQueryTest method testDeleteFeature.
@Test
public void testDeleteFeature() throws Exception {
FeatureIterator features = ds.getFeatureReader(new Query(name));
Feature feature;
try {
feature = features.next();
} finally {
if (features != null)
features.close();
}
final ResourceId createFidFilter = FeatureExt.getId(feature);
session.removeFeatures(name.toString(), createFidFilter);
session.commit();
fids.remove(FeatureExt.getId(feature).getIdentifier());
assertEquals(fids.size(), ds.getCount(new Query(name)));
features = ds.getFeatureReader(Query.filtered(name.toString(), createFidFilter));
try {
assertFalse(features.hasNext());
} finally {
if (features != null)
features.close();
}
this.assertFidsMatch();
}
use of org.opengis.filter.ResourceId in project geotoolkit by Geomatys.
the class FidQueryTest method testAddFeature.
@Test
@Ignore
public void testAddFeature() throws Exception {
final FeatureType schema = ds.getFeatureType(ds.getName().toString());
final Feature newFeature = schema.newInstance();
final GeometryFactory gf = org.geotoolkit.geometry.jts.JTS.getFactory();
newFeature.setPropertyValue("a", gf.createPoint((new Coordinate(0, 0))));
newFeature.setPropertyValue("b", new Long(0));
newFeature.setPropertyValue("c", new Long(0));
newFeature.setPropertyValue("d", "Hey");
final Collection<Feature> collection = new ArrayList<>();
collection.add(newFeature);
final List<ResourceId> newFids;
try (FeatureWriter writer = ds.getFeatureWriter(Query.filtered(name.toString(), Filter.exclude()))) {
newFids = FeatureStoreUtilities.write(writer, collection);
}
assertEquals(1, newFids.size());
// this.assertFidsMatch();
final Filter filter = newFids.iterator().next();
final Query query = new Query();
query.setTypeName(schema.getName());
query.setSelection(filter);
final FeatureIterator features = ds.getFeatureReader(query);
try {
final Feature feature = features.next();
for (PropertyType desc : schema.getProperties(true)) {
final Object value = feature.getPropertyValue(desc.getName().toString());
final Object newValue = newFeature.getPropertyValue(desc.getName().toString());
if (value instanceof Geometry) {
assertTrue(((Geometry) newValue).equals((Geometry) value));
} else {
assertEquals(newValue, value);
}
}
assertFalse(features.hasNext());
} finally {
if (features != null)
features.close();
}
}
use of org.opengis.filter.ResourceId in project geotoolkit by Geomatys.
the class JDBCAddDelta method commit.
@Override
public Map<String, String> commit(FeatureStore store) throws DataStoreException {
final DefaultJDBCFeatureStore jdbcstore = (DefaultJDBCFeatureStore) store;
final Connection cnx = ((JDBCSession) session).getTransaction();
final List<ResourceId> createdIds = jdbcstore.addFeatures(type, features, cnx, null);
// iterator and list should have the same size
final Map<String, String> updates = new HashMap<>();
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 = (String) f.getPropertyValue(AttributeConvention.IDENTIFIER);
updates.put(id, createdIds.get(i).getIdentifier());
i++;
}
}
} finally {
ite.close();
}
features.clear();
return updates;
}
use of org.opengis.filter.ResourceId in project geotoolkit by Geomatys.
the class JDBCSession method removeFeatures.
/**
* {@inheritDoc }
* Override here split remove query in order to avoid
* "stack depth limit exceeded" exception.
*/
@Override
public void removeFeatures(final String groupName, final Filter filter) throws DataStoreException {
checkVersion();
// will raise an error if the name doesn't exist
store.getFeatureType(groupName);
if (isAsynchrone()) {
List<Filter<Object>> removeIdFilters = new ArrayList<>();
// split Id filter
if (filter instanceof ResourceId) {
final ResourceId removed = (ResourceId) filter;
removeIdFilters.add(removed);
} else {
Set<ResourceId<Object>> identifiers = new HashSet<>();
final Query qb = new Query(groupName);
qb.setSelection(filter);
final FeatureIterator ite = getFeatureIterator(qb);
try {
while (ite.hasNext()) {
identifiers.add(FeatureExt.getId(ite.next()));
// flush in list of filters
if (identifiers.size() == MAX_ID_IN_REQUEST) {
removeIdFilters.addAll(identifiers);
identifiers.clear();
}
}
if (!identifiers.isEmpty()) {
removeIdFilters.addAll(identifiers);
}
} finally {
ite.close();
}
if (removeIdFilters.isEmpty()) {
// no feature match this filter, no need to create to remove delta
return;
}
}
for (final Filter removeIdFilter : removeIdFilters) {
getDiff().add(createRemoveDelta(this, groupName, removeIdFilter));
}
fireSessionChanged();
} else {
store.removeFeatures(groupName, filter);
}
}
use of org.opengis.filter.ResourceId in project geotoolkit by Geomatys.
the class ListingPropertyVisitor method visit.
@Override
public Object visit(final FeatureTypeStyle featureTypeStyle, Object data) {
final ResourceId ids = featureTypeStyle.getFeatureInstanceIDs();
if (ids != null) {
visit(ids, (Collection<String>) data);
}
final List<? extends Rule> rules = featureTypeStyle.rules();
if (rules != null) {
for (Rule r : rules) {
data = r.accept(this, data);
}
}
return data;
}
Aggregations