use of org.geotools.data.Transaction in project GeoGig by boundlessgeo.
the class GeogigFeatureSource method getRootRef.
private String getRootRef() {
GeoGigDataStore dataStore = getDataStore();
Transaction transaction = getTransaction();
return dataStore.getRootRef(transaction);
}
use of org.geotools.data.Transaction in project GeoGig by boundlessgeo.
the class GeogigFeatureSource method getTypeRef.
/**
* @return
*/
NodeRef getTypeRef() {
GeoGigDataStore dataStore = getDataStore();
Name name = getName();
Transaction transaction = getTransaction();
return dataStore.findTypeRef(name, transaction);
}
use of org.geotools.data.Transaction in project GeoGig by boundlessgeo.
the class GeoGigDataStoreTest method testFeatureWriterAppend.
@Test
public void testFeatureWriterAppend() throws Exception {
dataStore.createSchema(linesType);
Transaction tx = new DefaultTransaction();
FeatureWriter<SimpleFeatureType, SimpleFeature> fw = dataStore.getFeatureWriterAppend(linesTypeName.getLocalPart(), tx);
LineString line = new GeometryBuilder().lineString(0, 0, 1, 1);
SimpleFeature f = (SimpleFeature) fw.next();
f.setAttribute("sp", "foo");
f.setAttribute("ip", 10);
f.setAttribute("pp", line);
fw.write();
fw.close();
tx.commit();
FeatureSource<SimpleFeatureType, SimpleFeature> source = dataStore.getFeatureSource(linesTypeName);
assertEquals(1, source.getCount(null));
FeatureReader<SimpleFeatureType, SimpleFeature> r = dataStore.getFeatureReader(new Query(linesTypeName.getLocalPart()), Transaction.AUTO_COMMIT);
assertTrue(r.hasNext());
f = r.next();
assertEquals("foo", f.getAttribute("sp"));
assertEquals(10, f.getAttribute("ip"));
assertTrue(line.equals((Geometry) f.getAttribute("pp")));
}
use of org.geotools.data.Transaction in project GeoGig by boundlessgeo.
the class GeoGigFeatureStoreTest method testRemoveFeatures.
@Test
public void testRemoveFeatures() throws Exception {
// add features circumventing FeatureStore.addFeatures to keep the test
// independent of the
// addFeatures functionality
insertAndAdd(lines1, lines2, lines3);
insertAndAdd(points1, points2, points3);
geogig.command(CommitOp.class).call();
Id filter = ff.id(Collections.singleton(ff.featureId(idP1)));
Transaction tx = new DefaultTransaction();
points.setTransaction(tx);
try {
// initial # of features
assertEquals(3, points.getFeatures().size());
// remove feature
points.removeFeatures(filter);
// #of features before commit on the same store
assertEquals(2, points.getFeatures().size());
// #of features before commit on a different store instance
assertEquals(3, dataStore.getFeatureSource(pointsTypeName).getFeatures().size());
tx.commit();
// #of features after commit on a different store instance
assertEquals(2, dataStore.getFeatureSource(pointsTypeName).getFeatures().size());
} catch (Exception e) {
tx.rollback();
throw e;
} finally {
tx.close();
}
points.setTransaction(Transaction.AUTO_COMMIT);
assertEquals(2, points.getFeatures().size());
assertEquals(0, points.getFeatures(filter).size());
}
use of org.geotools.data.Transaction in project GeoGig by boundlessgeo.
the class GeoGigFeatureStoreTest method testAddFeaturesWhileNotOnABranch.
@Test
public void testAddFeaturesWhileNotOnABranch() throws Exception {
boolean gotIllegalStateException = false;
final ObjectId head = geogig.command(RevParse.class).setRefSpec("HEAD").call().get();
dataStore.setHead(head.toString());
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());
// assert transaction isolation
assertEquals(3, points.getFeatures().size());
assertEquals(0, dataStore.getFeatureSource(pointsTypeName).getFeatures().size());
tx.commit();
assertEquals(3, dataStore.getFeatureSource(pointsTypeName).getFeatures().size());
} catch (IllegalStateException e) {
tx.rollback();
gotIllegalStateException = true;
} catch (Exception e) {
tx.rollback();
throw e;
} finally {
tx.close();
}
assertTrue("Should throw IllegalStateException when trying to modify data in geogig datastore when it is not configured with a branch.", gotIllegalStateException);
}
Aggregations