/** * Check null encoding is working properly * * @throws IOException */ public void testModifyNullAttributes() throws IOException { String[] attributeNames = new String[featureStore.getSchema().getAttributeCount()]; for (int i = 0; i < attributeNames.length; i++) { attributeNames[i] = featureStore.getSchema().getDescriptor(i).getLocalName(); } Object[] nulls = new Object[attributeNames.length]; featureStore.modifyFeatures(attributeNames, nulls, Filter.INCLUDE); }
public void testModifyFeaturesInvalidFilter() throws IOException { SimpleFeatureType t = featureStore.getSchema(); FilterFactory ff = CommonFactoryFinder.getFilterFactory(null); PropertyIsEqualTo f = ff.equals(ff.property("invalidAttribute"), ff.literal(5)); try { featureStore.modifyFeatures( new AttributeDescriptor[] {t.getDescriptor(aname("stringProperty"))}, new Object[] {"foo"}, f); fail("This should have failed with an exception reporting the invalid filter"); } catch (Exception e) { // fine } }
public void testModifyFeaturesSingleAttribute() throws IOException { SimpleFeatureType t = featureStore.getSchema(); featureStore.modifyFeatures( t.getDescriptor(aname("stringProperty")), "foo", Filter.INCLUDE); SimpleFeatureCollection features = featureStore.getFeatures(); try (SimpleFeatureIterator i = features.features()) { assertTrue(i.hasNext()); while (i.hasNext()) { SimpleFeature feature = (SimpleFeature) i.next(); assertEquals("foo", feature.getAttribute(aname("stringProperty"))); } } }
store.modifyFeatures(ad, v, f1); fail("Locked feature should not be modified."); } catch (FeatureLockException e) { store.modifyFeatures(ad, v, f1); tx.commit();
public void testModifyGeometry() throws IOException { // GEOT-2371 SimpleFeatureType t = featureStore.getSchema(); GeometryFactory gf = new GeometryFactory(); Point point = gf.createPoint(new Coordinate(-10, 0)); featureStore.modifyFeatures( new AttributeDescriptor[] {t.getDescriptor(aname("geometry"))}, new Object[] {point}, Filter.INCLUDE); SimpleFeatureCollection features = featureStore.getFeatures(); try (SimpleFeatureIterator i = features.features()) { assertTrue(i.hasNext()); while (i.hasNext()) { SimpleFeature feature = (SimpleFeature) i.next(); assertTrue(point.equalsExact((Geometry) feature.getAttribute(aname("geometry")))); } } }
public void testModifyFeatures() throws IOException { FeatureEventWatcher watcher = new FeatureEventWatcher(); SimpleFeatureType t = featureStore.getSchema(); featureStore.addFeatureListener(watcher); featureStore.modifyFeatures( new AttributeDescriptor[] {t.getDescriptor(aname("stringProperty"))}, new Object[] {"foo"}, Filter.INCLUDE); assertTrue("check that at least one event was issued", watcher.count > 0); assertEquals("Should be an update event", Type.CHANGED, watcher.type); assertEquals(Filter.INCLUDE, watcher.filter); SimpleFeatureCollection features = featureStore.getFeatures(); try (SimpleFeatureIterator i = features.features()) { assertTrue(i.hasNext()); while (i.hasNext()) { SimpleFeature feature = (SimpleFeature) i.next(); assertEquals("foo", feature.getAttribute(aname("stringProperty"))); } } }
fs.modifyFeatures(key, 10, filter); fail("expected exception"); } catch (IllegalArgumentException e) { fs.modifyFeatures( new String[] {aname("name"), key, aname("geom")}, new Object[] {"foo", 10, null},
public void testModifyMadeUpGeometry() throws IOException { // GEOT-2371 SimpleFeatureType t = featureStore.getSchema(); GeometryFactory gf = new GeometryFactory(); Point point = gf.createPoint(new Coordinate(-10, 0)); // make up a fake attribute with the same name, something that might happen // in chains of retyping where attributes are rebuilt AttributeTypeBuilder ab = new AttributeTypeBuilder(); ab.binding(Point.class); AttributeDescriptor madeUp = ab.buildDescriptor(aname("geometry")); featureStore.modifyFeatures( new AttributeDescriptor[] {madeUp}, new Object[] {point}, Filter.INCLUDE); SimpleFeatureCollection features = featureStore.getFeatures(); try (SimpleFeatureIterator i = features.features()) { assertTrue(i.hasNext()); while (i.hasNext()) { SimpleFeature feature = (SimpleFeature) i.next(); assertTrue(point.equalsExact((Geometry) feature.getAttribute(aname("geometry")))); } } }
public void testModifyExposedPk() throws IOException { SimpleFeatureType t = featureStore.getSchema(); FilterFactory ff = CommonFactoryFinder.getFilterFactory(); PropertyIsEqualTo filter = ff.equal(ff.property(aname("stringProperty")), ff.literal("zero"), false); featureStore.modifyFeatures( new AttributeDescriptor[] { t.getDescriptor(aname("stringProperty")), t.getDescriptor(aname("id")) }, new Object[] {"foo", 123}, filter); PropertyIsEqualTo idFilter = ff.equal(ff.property(aname("id")), ff.literal(0), false); SimpleFeatureCollection features = featureStore.getFeatures(idFilter); try (SimpleFeatureIterator i = features.features()) { assertTrue(i.hasNext()); while (i.hasNext()) { SimpleFeature feature = (SimpleFeature) i.next(); // this has been updated assertEquals("foo", feature.getAttribute(aname("stringProperty"))); // the pk did not assertEquals(0, ((Number) feature.getAttribute(aname("id"))).intValue()); } } } }