protected void connect() throws Exception { super.connect(); store = (JDBCFeatureStore) dataStore.getFeatureSource(tname("ft1")); store.setFeatureLock(FeatureLock.TRANSACTION); }
assertEquals(0, store.getCount(new Query(tname("ft1"), f0))); FeatureLock lock = FeatureLockFactory.generate(tname("ft1"), 60 * 60 * 1000); tx.addAuthorization(lock.getAuthorization()); Filter f1 = ff.id(Collections.singleton(ff.featureId(tname("ft1") + ".1"))); store.lockFeatures(f1); tx.commit(); assertEquals(1, store.getCount(new Query(tname("ft1"), f0)));
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 testLockFeatures() throws Exception { FeatureLock lock = FeatureLockFactory.generate(tname("ft1"), 60 * 60 * 1000); Query query = new Query(tname("ft1")); try (FeatureReader<SimpleFeatureType, SimpleFeature> reader = dataStore.getFeatureReader(query, tx)) { dataStore.getFeatureWriter(tname("ft1"), tx)) { assertTrue(writer.hasNext()); SimpleFeature feature = writer.next(); dataStore.getFeatureWriter(tname("ft1"), tx)) { assertTrue(writer.hasNext()); SimpleFeature feature = writer.next();
public void testUnlockFeatures() throws Exception { FeatureLock lock = FeatureLockFactory.generate(tname("ft1"), 60 * 60 * 1000); dataStore.getFeatureWriter(tname("ft1"), tx)) { assertTrue(writer.hasNext()); SimpleFeature feature = writer.next(); dataStore.getFeatureWriter(tname("ft1"), tx)) { assertTrue(writer.hasNext());
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 } } }
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 } } }
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(); } }