@SuppressWarnings("unchecked") public <T> T[] toArray(T[] array) { int size = size(); if (array.length < size) { array = (T[]) java.lang.reflect.Array.newInstance( array.getClass().getComponentType(), size); } FeatureIterator<SimpleFeature> it = features(); try { Object[] result = array; for (int i = 0; it.hasNext() && i < size; i++) { result[i] = it.next(); } if (array.length > size) { array[size] = null; } return array; } finally { if (it != null) { it.close(); } } }
int count(String typeName) throws IOException { // return count(reader(typeName)); // makes use of optimization if any return dataStore.getFeatureSource(typeName).getFeatures().size(); }
public boolean isEmpty() { return size() == 0; }
.id(Collections.singleton(ids.get(0))); ContentFeatureCollection features = featureStore.getFeatures(filter); assertEquals(1, features.size()); SimpleFeature found = DataUtilities.first(features); assertEquals(theValue, found.getAttribute(theProperty));
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 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()); } }
public <T> T[] toArray(T[] array) { int size = size(); if (array.length < size){ array = (T[])java.lang.reflect.Array.newInstance(array.getClass().getComponentType(), size); } Iterator<SimpleFeature> it = iterator(); try { Object[] result = array; for (int i=0; it.hasNext() && i<size; i++){ result[i] = it.next(); } if (array.length > size){ array[size] = null; } return array; } finally { close( it ); } } public String getID() {
void doTestOuterJoin(boolean exposePrimaryKeys) throws Exception { dataStore.setExposePrimaryKeyColumns(exposePrimaryKeys); FilterFactory ff = dataStore.getFilterFactory(); Query q = new Query(tname("ftjoin")); q.getJoins() .add( new Join( tname("ft1"), ff.equal( ff.property(aname("name")), ff.property(aname("stringProperty")), true)) .type(Type.OUTER)); SimpleFeatureCollection features = dataStore.getFeatureSource(tname("ftjoin")).getFeatures(q); assertEquals( dataStore.getFeatureSource(tname("ftjoin")).getFeatures(q).size(), features.size()); try (SimpleFeatureIterator it = features.features()) { while (it.hasNext()) { SimpleFeature f = it.next(); assertEquals(4 + (exposePrimaryKeys ? 1 : 0), f.getAttributeCount()); SimpleFeature g = (SimpleFeature) f.getAttribute(tname("ft1")); if ("three".equals(f.getAttribute(aname("name")))) { assertNull(g); } else { assertNotNull(g); } } } }
dataStore.getFeatureSource(tname("ft1")).getFeatures(q); assertEquals( dataStore.getFeatureSource(tname("ft1")).getFeatures(q).size(), features.size());
dataStore.getFeatureSource(tname("ft1")).getFeatures(q); assertEquals( dataStore.getFeatureSource(tname("ft1")).getFeatures(q).size(), features.size());
dataStore.getFeatureSource(tname("ft1")).getFeatures(q); assertEquals( dataStore.getFeatureSource(tname("ft1")).getFeatures(q).size(), features.size());
try { assertEquals(3, points.getFeatures().size()); assertEquals(2, points.getFeatures().size()); assertEquals(3, dataStore.getFeatureSource(pointsName).getFeatures().size()); assertEquals(2, dataStore.getFeatureSource(pointsName).getFeatures().size()); } catch (Exception e) { tx.rollback(); assertEquals(2, points.getFeatures().size()); assertEquals(0, points.getFeatures(filter).size());
@Test public void testAddFeatures() throws Exception { FeatureCollection<SimpleFeatureType, SimpleFeature> collection; collection = DataUtilities.collection(Arrays.asList((SimpleFeature) points1, (SimpleFeature) points2, (SimpleFeature) points3)); Transaction tx = new DefaultTransaction(); points.setTransaction(tx); assertSame(tx, points.getTransaction()); try { List<FeatureId> addedFeatures = points.addFeatures(collection); assertNotNull(addedFeatures); assertEquals(3, addedFeatures.size()); for (FeatureId id : addedFeatures) { assertFalse(id instanceof ResourceId); assertNotNull(id.getFeatureVersion()); } // assert transaction isolation assertEquals(3, points.getFeatures().size()); assertEquals(0, dataStore.getFeatureSource(pointsName).getFeatures().size()); tx.commit(); assertEquals(3, dataStore.getFeatureSource(pointsName).getFeatures().size()); } catch (Exception e) { tx.rollback(); throw e; } finally { tx.close(); } }
@Test public void testAddFeatures() throws Exception { FeatureCollection<SimpleFeatureType, SimpleFeature> collection; collection = DataUtilities.collection(Arrays.asList((SimpleFeature) points1, (SimpleFeature) points2, (SimpleFeature) points3)); Transaction tx = new DefaultTransaction(); points.setTransaction(tx); assertSame(tx, points.getTransaction()); try { List<FeatureId> addedFeatures = points.addFeatures(collection); assertNotNull(addedFeatures); assertEquals(3, addedFeatures.size()); for (FeatureId id : addedFeatures) { assertFalse(id instanceof ResourceId); assertNotNull(id.getFeatureVersion()); } // assert transaction isolation assertEquals(3, points.getFeatures().size()); assertEquals(0, dataStore.getFeatureSource(pointsName).getFeatures().size()); tx.commit(); assertEquals(3, dataStore.getFeatureSource(pointsName).getFeatures().size()); } catch (Exception e) { tx.rollback(); throw e; } finally { tx.close(); } }
@Test public void testAddFeaturesOnASeparateBranch() throws Exception { final String branchName = "addtest"; final Ref branchRef = geogig.command(BranchCreateOp.class).setName(branchName).call(); dataStore.setHead(branchName); FeatureCollection<SimpleFeatureType, SimpleFeature> collection; collection = DataUtilities.collection(Arrays.asList((SimpleFeature) points1, (SimpleFeature) points2, (SimpleFeature) points3)); Transaction tx = new DefaultTransaction(); points.setTransaction(tx); assertSame(tx, points.getTransaction()); try { List<FeatureId> addedFeatures = points.addFeatures(collection); assertNotNull(addedFeatures); assertEquals(3, addedFeatures.size()); // assert transaction isolation assertEquals(3, points.getFeatures().size()); assertEquals(0, dataStore.getFeatureSource(pointsName).getFeatures().size()); tx.commit(); assertEquals(3, dataStore.getFeatureSource(pointsName).getFeatures().size()); } catch (Exception e) { tx.rollback(); throw e; } finally { tx.close(); } }
@Test public void testAddFeaturesOnASeparateBranch() throws Exception { final String branchName = "addtest"; final Ref branchRef = geogig.command(BranchCreateOp.class).setName(branchName).call(); dataStore.setHead(branchName); FeatureCollection<SimpleFeatureType, SimpleFeature> collection; collection = DataUtilities.collection(Arrays.asList((SimpleFeature) points1, (SimpleFeature) points2, (SimpleFeature) points3)); Transaction tx = new DefaultTransaction(); points.setTransaction(tx); assertSame(tx, points.getTransaction()); try { List<FeatureId> addedFeatures = points.addFeatures(collection); assertNotNull(addedFeatures); assertEquals(3, addedFeatures.size()); // assert transaction isolation assertEquals(3, points.getFeatures().size()); assertEquals(0, dataStore.getFeatureSource(pointsName).getFeatures().size()); tx.commit(); assertEquals(3, dataStore.getFeatureSource(pointsName).getFeatures().size()); } catch (Exception e) { tx.rollback(); throw e; } finally { tx.close(); } }
@Test public void testTransactionCommitMessage() throws Exception { FeatureCollection<SimpleFeatureType, SimpleFeature> collection; collection = DataUtilities.collection(Arrays.asList((SimpleFeature) points1, (SimpleFeature) points2, (SimpleFeature) points3)); DefaultTransaction tx = new DefaultTransaction(); points.setTransaction(tx); assertSame(tx, points.getTransaction()); try { points.addFeatures(collection); tx.putProperty(GeogigTransactionState.VERSIONING_COMMIT_AUTHOR, "John Doe"); tx.putProperty(GeogigTransactionState.VERSIONING_COMMIT_MESSAGE, "test message"); tx.commit(); assertEquals(3, dataStore.getFeatureSource(pointsName).getFeatures().size()); } catch (Exception e) { tx.rollback(); throw e; } finally { tx.close(); } List<RevCommit> commits = toList(geogig.command(LogOp.class).call()); assertFalse(commits.isEmpty()); assertTrue(commits.get(0).getAuthor().getName().isPresent()); assertEquals("John Doe", commits.get(0).getAuthor().getName().get()); assertEquals("test message", commits.get(0).getMessage()); }
@Test public void testTransactionCommitMessage() throws Exception { FeatureCollection<SimpleFeatureType, SimpleFeature> collection; collection = DataUtilities.collection(Arrays.asList((SimpleFeature) points1, (SimpleFeature) points2, (SimpleFeature) points3)); DefaultTransaction tx = new DefaultTransaction(); points.setTransaction(tx); assertSame(tx, points.getTransaction()); try { points.addFeatures(collection); tx.putProperty(GeogigTransactionState.VERSIONING_COMMIT_AUTHOR, "John Doe"); tx.putProperty(GeogigTransactionState.VERSIONING_COMMIT_MESSAGE, "test message"); tx.commit(); assertEquals(3, dataStore.getFeatureSource(pointsName).getFeatures().size()); } catch (Exception e) { tx.rollback(); throw e; } finally { tx.close(); } List<RevCommit> commits = toList(geogig.command(LogOp.class).call()); assertFalse(commits.isEmpty()); assertTrue(commits.get(0).getAuthor().getName().isPresent()); assertEquals("John Doe", commits.get(0).getAuthor().getName().get()); assertEquals("test message", commits.get(0).getMessage()); }
@Test public void testTransactionCommitAuthorAndEmail() throws Exception { FeatureCollection<SimpleFeatureType, SimpleFeature> collection; collection = DataUtilities.collection(Arrays.asList((SimpleFeature) points1, (SimpleFeature) points2, (SimpleFeature) points3)); DefaultTransaction tx = new DefaultTransaction(); points.setTransaction(tx); assertSame(tx, points.getTransaction()); try { points.addFeatures(collection); tx.putProperty(GeogigTransactionState.VERSIONING_COMMIT_AUTHOR, "john"); tx.putProperty(GeogigTransactionState.VERSIONING_COMMIT_MESSAGE, "test message"); tx.putProperty("fullname", "John Doe"); tx.putProperty("email", "jd@example.com"); tx.commit(); assertEquals(3, dataStore.getFeatureSource(pointsName).getFeatures().size()); } catch (Exception e) { tx.rollback(); throw e; } finally { tx.close(); } List<RevCommit> commits = toList(geogig.command(LogOp.class).call()); assertFalse(commits.isEmpty()); assertTrue(commits.get(0).getAuthor().getName().isPresent()); assertEquals("John Doe", commits.get(0).getAuthor().getName().orNull()); assertEquals("jd@example.com", commits.get(0).getAuthor().getEmail().orNull()); }