Refine search
ShapefileDataStore outStore = new ShapefileDataStore(shapeFile.toURI().toURL()); outStore.createSchema(contourSchema); Transaction transaction = new DefaultTransaction("create"); SimpleFeatureStore featureStore = (SimpleFeatureStore) outStore.getFeatureSource(); featureStore.setTransaction(transaction); try { featureStore.addFeatures(contourFeatures); transaction.commit(); } catch (Exception e) { transaction.rollback(); throw e; } finally { transaction.close();
public void purge(Filter filter) throws IOException { DefaultTransaction transaction = null; try { transaction = new DefaultTransaction("CleanupTransaction" + System.nanoTime()); for (String typeName : typeNames) { removeGranules(typeName, filter, transaction); } transaction.commit(); } catch (Throwable e) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Rollback"); } if (transaction != null) { transaction.rollback(); } throw new IOException(e); } finally { try { if (transaction != null) { transaction.close(); } } catch (Throwable t) { } } } }
/** * Builds a transaction object around a user provided connection. The returned transaction * allows the store to work against an externally managed transaction, such as in J2EE * enviroments. It is the duty of the caller to ensure the connection is to the same database * managed by this {@link JDBCDataStore}. * * <p>Calls to {@link Transaction#commit()}, {@link Transaction#rollback()} and {@link * Transaction#close()} will not result in corresponding calls to the provided {@link * Connection} object. * * @param conn The externally managed connection */ public Transaction buildTransaction(Connection cx) { DefaultTransaction tx = new DefaultTransaction(); State state = new JDBCTransactionState(cx, this, true); tx.putState(this, state); return tx; }
config.getDatastoreSpi().createDataStore(config.getParams()); final Set<String> typeNames = new HashSet<>(Arrays.asList(sourceDataStore.getTypeNames())); Transaction t = new DefaultTransaction(); try { t.commit(); netcdfWriter.addLines(path); h2Writer.addLines(collectH2Files(config)); } finally { t.close(); if (sourceDataStore != null) { sourceDataStore.dispose();
JDBCDataStore ds = (JDBCDataStore) dataStore; if (ds.getSqlTypeNameToClassMappings().containsKey("timestamptz")) { ds.getSqlTypeToSqlTypeNameOverrides().put(java.sql.Types.TIMESTAMP, "timestamptz"); Transaction transaction = new DefaultTransaction(); transaction.commit(); if (skipped > 0) { task.addMessage(Level.WARNING,skipped + " features were skipped."); transaction.rollback(); } catch (Exception e1) { LOGGER.log(Level.WARNING, "Error rolling back transaction",e1); transaction.close(); } catch (Exception e) { if (error != null) {
try (Connection cx = gpkgStore.getConnection(Transaction.AUTO_COMMIT); GeopkgGeogigMetadata metadata = new GeopkgGeogigMetadata(cx)) { Transaction gttx = new DefaultTransaction(); try { gpkg.createSchema(source.getSchema()); gttx.commit(); } finally { gttx.close();
public void testCommit() throws IOException { // JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("ft1")); try (Transaction tx = new DefaultTransaction(); FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriterAppend(tname("ft1"), tx)) { SimpleFeature feature = writer.next(); feature.setAttribute(aname("intProperty"), Integer.valueOf(100)); writer.write(); writer.close(); tx.commit(); } SimpleFeatureCollection fc = dataStore.getFeatureSource(tname("ft1")).getFeatures(); assertEquals(4, fc.size()); }
public void testUUIDAsPrimaryKey() throws Exception { try (Transaction transaction = new DefaultTransaction()) { SimpleFeatureStore featureStore = (SimpleFeatureStore) dataStore.getFeatureSource(tname("uuidt")); featureStore.setTransaction(transaction); featureStore.addFeatures(createFeatureCollection()); transaction.commit(); assertEquals(3, featureStore.getCount(Query.ALL)); } }
assertFeatures(store, pointsType.getTypeName(), points1, points2, points3); Transaction gttx = new DefaultTransaction(); try (Connection connection = store.getConnection(gttx); GeopkgGeogigMetadata metadata = new GeopkgGeogigMetadata(connection)) { assertEquals(headCommitId, table.getCommitId()); } finally { gttx.close(); store.dispose();
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(); } }
@Test public void testLockUnlockFilter() throws Exception { SimpleFeatureLocking fl; fl = (SimpleFeatureLocking) rts.getFeatureSource(RENAMED); final FeatureLock lock = FeatureLockFactory.generate(10 * 60 * 1000); Transaction t = new DefaultTransaction(); t.addAuthorization(lock.getAuthorization()); fl.setTransaction(t); fl.setFeatureLock(lock); SimpleFeatureLocking fl2; fl2 = (SimpleFeatureLocking) rts.getFeatureSource(RENAMED); fl.setFeatureLock(lock); fl2.setTransaction(new DefaultTransaction()); assertEquals(1, fl.lockFeatures(fidFilter)); assertEquals(0, fl2.lockFeatures(fidFilter)); fl.unLockFeatures(fidFilter); assertEquals(1, fl2.lockFeatures(fidFilter)); }
public void testUnLockFeatures() throws IOException { FeatureLock lock = new FeatureLock("test", 3600); @SuppressWarnings("unchecked") FeatureLocking<SimpleFeatureType, SimpleFeature> road = (FeatureLocking<SimpleFeatureType, SimpleFeature>) data.getFeatureSource("road"); road.setFeatureLock(lock); road.lockFeatures(); try { road.unLockFeatures(); fail("unlock should fail due on AUTO_COMMIT"); } catch (IOException expected) { } Transaction t = new DefaultTransaction(); road.setTransaction(t); try { road.unLockFeatures(); fail("unlock should fail due lack of authorization"); } catch (IOException expected) { } t.addAuthorization(lock.getAuthorization()); road.unLockFeatures(); t.close(); }
void createVersionedFeatureCollectionView(String typeName) throws IOException { Connection conn = null; Transaction t = new DefaultTransaction(); try { conn = wrapped.getConnection(t); createVersionedFeatureCollectionView(typeName, conn); t.commit(); } finally { JDBCUtils.close(conn, t, null); } }
dataStore.getConnectionLifecycleListeners().add(mockListener); try (Transaction t = new DefaultTransaction()) { SimpleFeatureBuilder b = new SimpleFeatureBuilder(featureStore.getSchema()); DefaultFeatureCollection collection = t.commit(); assertTrue(mockListener.onBorrowCalled); assertTrue(mockListener.onReleaseCalled); t.rollback(); assertTrue(mockListener.onRollbackCalled);
/** * Factors out the boilerplate to create a transaction, run it, commit it if successful, revert * otherwise, and finally close it * * @param store * @param featureStoreConsumer * @throws IOException */ protected void runTransactionOnStore( FeatureStore store, IOConsumer<FeatureStore> featureStoreConsumer) throws IOException { try (Transaction t = new DefaultTransaction()) { store.setTransaction(t); try { featureStoreConsumer.accept(store); t.commit(); } catch (Exception e) { t.rollback(); throw new IOException("Failed to run modification on storage:" + e.getMessage(), e); } } }
tx = new DefaultTransaction("getGranulesTransaction" + System.nanoTime()); ((FeatureStore) featureSource).setTransaction(tx); tx.close();
public void testInsertFeatures() throws Exception { try (Transaction transaction = new DefaultTransaction()) { SimpleFeatureStore featureStore = (SimpleFeatureStore) dataStore.getFeatureSource(tname("guid")); featureStore.setTransaction(transaction); assertEquals(featureStore.getCount(Query.ALL), 2); SimpleFeatureType type = dataStore.getSchema(tname("guid")); SimpleFeature feature = SimpleFeatureBuilder.build(type, new Object[] {uuid3}, "guid.3"); SimpleFeatureCollection collection = DataUtilities.collection(feature); featureStore.addFeatures(collection); transaction.commit(); assertEquals(featureStore.getCount(Query.ALL), 3); } }
/** Create a transaction for being used in this walker */ public void startTransaction() { if (transaction != null) { throw new IllegalStateException("Transaction already open!"); } this.transaction = new DefaultTransaction("MosaicCreationTransaction" + System.nanoTime()); }
transaction = new DefaultTransaction(); transaction.commit(); } catch (Exception eek) { eek.printStackTrace(); try { store.getTransaction().rollback(); } catch (IOException e) { e.printStackTrace(); transaction.close();
public void testNoCommit() throws IOException { try (Transaction tx = new DefaultTransaction(); FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriterAppend(tname("ft1"), tx)) { SimpleFeature feature = writer.next(); feature.setAttribute(aname("intProperty"), Integer.valueOf(100)); writer.write(); tx.rollback(); } SimpleFeatureCollection fc = dataStore.getFeatureSource(tname("ft1")).getFeatures(); assertEquals(3, fc.size()); }