@Override public void setTransaction(Transaction transaction) { super.setTransaction(transaction); // keep this feature store in sync JDBCFeatureStore.this.setTransaction(transaction); } };
public void testDeleteLockedFeatures() throws Exception { FeatureLock lock = FeatureLockFactory.generate(tname("ft1"), 60 * 60 * 1000); try (Transaction tx = new DefaultTransaction()) { store.setTransaction(tx); store.setFeatureLock(lock); tx.addAuthorization(lock.getAuthorization()); FilterFactory ff = dataStore.getFilterFactory(); Filter f1 = ff.id(Collections.singleton(ff.featureId(tname("ft1") + ".1"))); assertEquals(1, store.lockFeatures(f1)); try (Transaction tx1 = new DefaultTransaction()) { store.setTransaction(tx1); try { store.removeFeatures(f1); fail("Locked feature should not be deleted."); } catch (FeatureLockException e) { } } store.setTransaction(tx); store.removeFeatures(f1); tx.commit(); } }
public void testAcceptsVisitor() throws Exception { class TotalVisitor implements FeatureVisitor { int total = 0; public void visit(Feature feature) { total++; } } TotalVisitor visitor = new TotalVisitor(); // initial test on Transaction.AUTO_COMMIT int count = featureSource.getCount(Query.ALL); featureSource.accepts(Query.ALL, visitor, null); assertEquals(count, visitor.total); visitor.total = 0; // reset // test on a transaction JDBCFeatureStore ft1 = (JDBCFeatureStore) dataStore.getFeatureSource(tname("ft1")); try (Transaction transaction = new DefaultTransaction()) { ft1.setTransaction(transaction); Connection connection = ft1.getDataStore().getConnection(ft1.getState()); assertFalse("connection established", connection.isClosed()); ft1.accepts(Query.ALL, visitor, null); assertFalse("connection maintained", connection.isClosed()); } } }
@Override public void setTransaction(Transaction transaction) { super.setTransaction(transaction); //keep this feature store in sync JDBCFeatureStore.this.setTransaction(transaction); } };
@Override public void setTransaction(Transaction transaction) { super.setTransaction(transaction); //keep this feature store in sync JDBCFeatureStore.this.setTransaction(transaction); } };
store.setTransaction(tx); store.setFeatureLock(lock); tx.addAuthorization(lock.getAuthorization()); Integer v; try (Transaction tx1 = new DefaultTransaction()) { store.setTransaction(tx1); store.setTransaction(tx); store.modifyFeatures(ad, v, f1); tx.commit();
public void testLockFeaturesWithInvalidFilter() throws Exception { FeatureLock lock = FeatureLockFactory.generate(tname("ft1"), 60 * 60 * 1000); try (Transaction tx = new DefaultTransaction()) { store.setTransaction(tx); store.setFeatureLock(lock); // lock features FilterFactory ff = dataStore.getFilterFactory(); PropertyIsEqualTo f = ff.equals(ff.property(aname("invalidProperty")), ff.literal(1)); try { store.lockFeatures(f); fail("Should have failed with an exception, the filter is not valid"); } catch (Exception e) { // fine } } }
store.setTransaction(tx); store.setFeatureLock(lock);
public void testLockFeaturesWithInvalidQuery() throws Exception { FeatureLock lock = FeatureLockFactory.generate(tname("ft1"), 60 * 60 * 1000); try (Transaction tx = new DefaultTransaction()) { store.setTransaction(tx); store.setFeatureLock(lock); // lock features FilterFactory ff = dataStore.getFilterFactory(); PropertyIsEqualTo f = ff.equals(ff.property(aname("invalidProperty")), ff.literal(1)); try { store.lockFeatures(new Query(store.getSchema().getTypeName(), f)); fail("Should have failed with an exception, the filter is not valid"); } catch (Exception e) { // fine } } }
conn.setAutoCommit(false); try (Transaction t = dataStore.buildTransaction(conn)) { featureStore.setTransaction(t); featureStore.addFeatureListener(watcher); JDBCFeatureStore featureStore2 =
public void testUnlockFeaturesInvalidFilter() throws Exception { FeatureLock lock = FeatureLockFactory.generate(tname("ft1"), 60 * 60 * 1000); try (Transaction tx = new DefaultTransaction()) { store.setTransaction(tx); store.setFeatureLock(lock); tx.addAuthorization(lock.getAuthorization()); store.lockFeatures(); // uhnlock features FilterFactory ff = dataStore.getFilterFactory(); PropertyIsEqualTo f = ff.equals(ff.property(aname("invalidProperty")), ff.literal(1)); try { store.unLockFeatures(new Query(store.getSchema().getTypeName(), f)); fail("Should have failed with an exception, the filter is not valid"); } catch (Exception e) { // fine } store.unLockFeatures(); } }
store.setTransaction(tx); store.setFeatureLock(lock);
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()); } }
DefaultFeatureCollection collection = new DefaultFeatureCollection(null, featureStore.getSchema()); featureStore.setTransaction(t); for (int i = 3; i < 6; i++) { b.set(aname("intProperty"), Integer.valueOf(i));
store.setTransaction(tx); store.setFeatureLock(lock);