public void commitTransaction() throws IOException { transaction.commit(); }
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) { } } } }
LOGGER.fine("Committing changes to the DB"); transaction.commit(); } catch (Throwable e) { if (LOGGER.isLoggable(Level.FINE)) {
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) { } } } }
transaction.rollback(); else transaction.commit(); } catch (Exception e) { LOGGER.log(Level.WARNING, "Failure occurred while collecting the granules", e);
static void write(List<SimpleFeature> features, File file) throws IOException { String basename = file.getName(); if (basename.endsWith(FILE_EXTENSION_SHAPEFILE)) { basename = basename.substring(0, basename.length() - 4); } File shapefile = new File(file.getParentFile(), basename + FILE_EXTENSION_SHAPEFILE); ShapefileDataStoreFactory factory = new ShapefileDataStoreFactory(); Map map = Collections.singletonMap("url", shapefile.toURI().toURL()); DataStore dataStore = factory.createNewDataStore(map); SimpleFeature simpleFeature = features.get(0); SimpleFeatureType simpleFeatureType = simpleFeature.getType(); final String typeName = simpleFeatureType.getName().getLocalPart(); dataStore.createSchema(simpleFeatureType); FeatureStore<SimpleFeatureType, SimpleFeature> featureStore = (FeatureStore<SimpleFeatureType, SimpleFeature>) dataStore.getFeatureSource(typeName); DefaultTransaction transaction = new DefaultTransaction("X"); featureStore.setTransaction(transaction); final FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection = DataUtilities.collection(features); featureStore.addFeatures(featureCollection); try { transaction.commit(); } catch (Exception e) { transaction.rollback(); throw new IOException("Cannot write shapefile. Error:\n" + e.getMessage(), e); } finally { dataStore.dispose(); transaction.close(); } } }
featureStore.addFeatures(featureCollection); try { transaction.commit(); } catch (IOException e) { transaction.rollback();
try { featureStore.addFeatures(collection); transaction.commit(); } catch (Exception problem) { transaction.rollback();
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { FeatureStore<SimpleFeatureType, SimpleFeature> store; if (layer.getFeatureSource() instanceof FeatureStore) { store = (FeatureStore<SimpleFeatureType, SimpleFeature>) layer.getFeatureSource(); DefaultTransaction transaction = new DefaultTransaction("trans_maj"); store.setTransaction(transaction); FilterFactory ff = CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints()); Filter filter = ff.id(Collections.singleton(features.get(rowIndex).getIdentifier())); FeatureType schema = store.getSchema(); AttributeDescriptor NAME = (AttributeDescriptor) schema.getDescriptor(getColumnName(columnIndex)); try { store.modifyFeatures(NAME, aValue, filter); transaction.commit(); } catch (IOException ex) { ex.printStackTrace(); try { transaction.rollback(); } catch (IOException e) { e.printStackTrace(); } } setQuery(query); } }
LOGGER.fine("Committing changes to the DB"); transaction.commit(); } catch (Throwable e) { if (LOGGER.isLoggable(Level.FINE)) {
transaction.commit(); } catch (IOException ex) { ex.printStackTrace();
LOGGER.fine("Committing changes to the DB"); transaction.commit(); } catch (Throwable e) { if (LOGGER.isLoggable(Level.FINE)) {
transaction.commit(); } catch (Exception eek) { eek.printStackTrace();
@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()); }
@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()); }