transaction.commit(); } catch (Exception e) { transaction.rollback(); throw e; } finally {
transaction.rollback(); } catch (IOException e) { String msg =
@Override public void remove() throws IOException { try { super.remove(); } catch (IOException e) { state.getTransaction().rollback(); throw e; } }
@Override public void write() throws IOException { try { super.write(); String typeName = feature.getFeatureType().getTypeName(); state.addChange(typeName); } catch (IOException e) { state.getTransaction().rollback(); throw e; } }
} finally { if (rollback) { t.rollback();
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()); }
@Override public void rollback() throws IOException { transaction.rollback(); if (!writeMode) { featureBuffer.clear(); } }
listener2.events.clear(); store1.getTransaction().rollback();
@Override public void remove() throws IOException { try { super.remove(); } catch (IOException e) { state.getTransaction().rollback(); throw e; } }
tx.rollback(); throw new IOException(ex); } finally {
/** * 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); } } }
t.rollback(); assertTrue(mockListener.onRollbackCalled);
@Override public void write() throws IOException { try { super.write(); String typeName = feature.getFeatureType().getTypeName(); state.addChange(typeName); } catch (IOException e) { state.getTransaction().rollback(); throw e; } }
private void buildShapeFile(File shapeFile, VectorLayer layer, SimpleFeatureCollection collection, SimpleFeatureType type) throws Exception, DeskmanagerException { Map<String, Serializable> params = new HashMap<String, Serializable>(); params.put("url", shapeFile.toURI().toURL()); params.put("create spatial index", Boolean.FALSE); ShapefileDataStoreFactory sfDataStoreFactory = new ShapefileDataStoreFactory(); ShapefileDataStore sfDataStore = (ShapefileDataStore) sfDataStoreFactory.createNewDataStore(params); sfDataStore.createSchema(type); sfDataStore.forceSchemaCRS(layerService.getCrs(layer)); String typeName = sfDataStore.getTypeNames()[0]; SimpleFeatureSource sfSource = sfDataStore.getFeatureSource(typeName); if (sfSource instanceof SimpleFeatureStore) { SimpleFeatureStore sfs = (SimpleFeatureStore) sfSource; Transaction transaction = new DefaultTransaction("create"); sfs.setTransaction(transaction); try { sfs.addFeatures(collection); transaction.commit(); } catch (Exception e) { e.printStackTrace(); transaction.rollback(); throw e; } finally { transaction.close(); } } else { throw new DeskmanagerException(DeskmanagerException.CANNOT_CREATE_SHAPEFILE_FEATURESTORE); } }
/** Helper method that move resource informations from current DB to the new one */ private void moveData(DataStore exDataStore, DataStore newDataStore) throws Exception { Transaction session = new DefaultTransaction("Moving"); try { SimpleFeatureSource exFs = exDataStore.getFeatureSource(STORE_SCHEMA_NAME); SimpleFeatureStore newFs = (SimpleFeatureStore) newDataStore.getFeatureSource(STORE_SCHEMA_NAME); newFs.setTransaction(session); newFs.addFeatures(exFs.getFeatures()); session.commit(); } catch (Throwable t) { session.rollback(); throw new RuntimeException("Error on move data", t); } finally { session.close(); } }
assertEquals(0, count(reader)); defaultTransaction.rollback(); reader = data.getFeatureReader(new Query("road", Filter.EXCLUDE), defaultTransaction); assertEquals(0, count(reader));
t.rollback(); try (FeatureReader<SimpleFeatureType, SimpleFeature> reader = dataStore.getFeatureReader(new Query(tname("road"), Filter.EXCLUDE), t)) {
@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(); } }