protected void connect() throws Exception { super.connect(); source = (JDBCFeatureStore) dataStore.getFeatureSource(tname("ft1")); collection = source.getFeatures(); }
public void testAssignedSinglePKeyView() throws Exception { JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("assignedsinglepk")); assertEquals(1, fs.getPrimaryKey().getColumns().size()); assertTrue( fs.getPrimaryKey().getColumns().get(0) instanceof NonIncrementingPrimaryKeyColumn); FeatureCollection features = fs.getFeatures(); assertPrimaryKeyValues(features, 3); }
public void testMultiColumnPrimaryKey() throws Exception { JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("multi")); assertEquals(2, fs.getPrimaryKey().getColumns().size()); FeatureCollection features = fs.getFeatures(); assertMultiPrimaryKeyValues(features, 3); addFeature(fs.getSchema(), fs); assertMultiPrimaryKeyValues(features, 4); // test with a filter FilterFactory ff = dataStore.getFilterFactory(); Id id = ff.id(Collections.singleton(ff.featureId(tname("multi") + ".1.x"))); features = fs.getFeatures(id); assertEquals(1, features.size()); }
public void testNonIncrementingPrimaryKey() throws Exception { JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("noninc")); assertEquals(1, fs.getPrimaryKey().getColumns().size()); assertTrue( fs.getPrimaryKey().getColumns().get(0) instanceof NonIncrementingPrimaryKeyColumn); FeatureCollection features = fs.getFeatures(); assertPrimaryKeyValues(features, 3); addFeature(fs.getSchema(), fs); assertPrimaryKeyValues(features, 4); }
public void testSequencedPrimaryKey() throws Exception { JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("seq")); assertEquals(1, fs.getPrimaryKey().getColumns().size()); assertTrue(fs.getPrimaryKey().getColumns().get(0) instanceof SequencedPrimaryKeyColumn); FeatureCollection features = fs.getFeatures(); assertPrimaryKeyValues(features, 3); addFeature(fs.getSchema(), fs); assertPrimaryKeyValues(features, 4); }
public void testSequencedPrimaryKey() throws Exception { JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("seqtable")); assertEquals(1, fs.getPrimaryKey().getColumns().size()); assertTrue(fs.getPrimaryKey().getColumns().get(0) instanceof SequencedPrimaryKeyColumn); ContentFeatureCollection features = fs.getFeatures(); assertPrimaryKeyValues(features, 3); addFeature(fs.getSchema(), fs); assertPrimaryKeyValues(features, 4); }
assertEquals(4, featureStore.getFeatures().size()); assertEquals(3, featureStore2.getFeatures().size()); assertEquals(4, featureStore.getFeatures().size()); assertEquals(3, featureStore2.getFeatures().size()); assertEquals(4, featureStore.getFeatures().size()); assertEquals(4, featureStore2.getFeatures().size());
public void testSetFeatures() throws IOException { SimpleFeatureBuilder b = new SimpleFeatureBuilder(featureStore.getSchema()); DefaultFeatureCollection collection = new DefaultFeatureCollection(null, featureStore.getSchema()); for (int i = 3; i < 6; i++) { b.set(aname("intProperty"), Integer.valueOf(i)); b.set(aname("geometry"), new GeometryFactory().createPoint(new Coordinate(i, i))); collection.add(b.buildFeature(null)); } try (FeatureReader<SimpleFeatureType, SimpleFeature> reader = new CollectionFeatureReader( (SimpleFeatureCollection) collection, collection.getSchema())) { featureStore.setFeatures(reader); } SimpleFeatureCollection features = featureStore.getFeatures(); assertEquals(3, features.size()); try (SimpleFeatureIterator iterator = features.features()) { HashSet<Integer> numbers = new HashSet<Integer>(); numbers.add(Integer.valueOf(3)); numbers.add(Integer.valueOf(4)); numbers.add(Integer.valueOf(5)); for (int i = 3; iterator.hasNext(); i++) { SimpleFeature feature = (SimpleFeature) iterator.next(); assertTrue( numbers.contains( ((Number) feature.getAttribute(aname("intProperty"))).intValue())); numbers.remove(feature.getAttribute(aname("intProperty"))); } } }
public void testUniqueIndex() throws Exception { JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("uniq")); assertEquals(1, fs.getPrimaryKey().getColumns().size()); assertTrue( fs.getPrimaryKey().getColumns().get(0) instanceof NonIncrementingPrimaryKeyColumn); assertNull(fs.getSchema().getDescriptor(fs.getPrimaryKey().getColumns().get(0).getName())); FeatureCollection features = fs.getFeatures(); assertPrimaryKeyValues(features, 3); addFeature(fs.getSchema(), fs); assertPrimaryKeyValues(features, 4); }
public void testAutoGeneratedPrimaryKey() throws Exception { JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("auto")); assertEquals(1, fs.getPrimaryKey().getColumns().size()); assertTrue(fs.getPrimaryKey().getColumns().get(0) instanceof AutoGeneratedPrimaryKeyColumn); assertNull(fs.getSchema().getDescriptor(fs.getPrimaryKey().getColumns().get(0).getName())); FeatureCollection features = fs.getFeatures(); assertPrimaryKeyValues(features, 3); addFeature(fs.getSchema(), fs); assertPrimaryKeyValues(features, 4); }
public void testAssignedMultiPKeyView() throws Exception { JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("assignedmultipk")); assertEquals(2, fs.getPrimaryKey().getColumns().size()); assertTrue( fs.getPrimaryKey().getColumns().get(0) instanceof NonIncrementingPrimaryKeyColumn); assertTrue( fs.getPrimaryKey().getColumns().get(1) instanceof NonIncrementingPrimaryKeyColumn); try (FeatureIterator i = fs.getFeatures().features()) { for (int j = 1; i.hasNext(); j++) { SimpleFeature f = (SimpleFeature) i.next(); assertEquals(tname("assignedmultipk") + "." + j + "." + (j + 1), f.getID()); } } }
public void testAddInTransaction() throws IOException { SimpleFeatureBuilder b = new SimpleFeatureBuilder(featureStore.getSchema()); DefaultFeatureCollection collection = new DefaultFeatureCollection(null, featureStore.getSchema()); b.set(aname("intProperty"), Integer.valueOf(3)); b.set(aname("geometry"), new GeometryFactory().createPoint(new Coordinate(3, 3))); collection.add(b.buildFeature(null)); FeatureEventWatcher watcher = new FeatureEventWatcher(); try (Transaction t = new DefaultTransaction()) { featureStore.setTransaction(t); featureStore.addFeatureListener(watcher); JDBCFeatureStore featureStore2 = (JDBCFeatureStore) dataStore.getFeatureSource(featureStore.getName().getLocalPart()); List<FeatureId> fids = featureStore.addFeatures((SimpleFeatureCollection) collection); assertEquals(1, fids.size()); // check the store with the transaction sees the new features, but the other store does // not assertEquals(4, featureStore.getFeatures().size()); assertEquals(3, featureStore2.getFeatures().size()); // check that after the commit everybody sees 4 t.commit(); assertEquals(4, featureStore.getFeatures().size()); assertEquals(4, featureStore2.getFeatures().size()); } }
SimpleFeatureBuilder.createDefaultFeatureIdentifier(typeName + ".50"))); SimpleFeatureCollection features = featureStore.getFeatures(); assertEquals(6, features.size()); Id filter = ff.id(Collections.singleton(identifier)); features = featureStore.getFeatures(filter); assertEquals(1, features.size());
SimpleFeatureCollection features = featureStore.getFeatures(); assertEquals(6, features.size()); Id filter = ff.id(Collections.singleton(identifier)); features = featureStore.getFeatures(filter); assertEquals(1, features.size());
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"))); } } }
public void testRemoveFeatures() throws IOException { FilterFactory ff = dataStore.getFilterFactory(); Filter filter = ff.equals(ff.property(aname("intProperty")), ff.literal(1)); SimpleFeatureCollection features = featureStore.getFeatures(); assertEquals(3, features.size()); featureStore.removeFeatures(filter); assertEquals(2, features.size()); featureStore.removeFeatures(Filter.INCLUDE); assertEquals(0, features.size()); }
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"))); } } }
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()); } } } }