Search in sources :

Example 6 with Transaction

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);
}
Also used : Transaction(org.geotools.data.Transaction)

Example 7 with 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);
}
Also used : Transaction(org.geotools.data.Transaction) Name(org.opengis.feature.type.Name)

Example 8 with 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")));
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Transaction(org.geotools.data.Transaction) DefaultTransaction(org.geotools.data.DefaultTransaction) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Query(org.geotools.data.Query) LineString(com.vividsolutions.jts.geom.LineString) GeometryBuilder(org.geotools.geometry.jts.GeometryBuilder) DefaultTransaction(org.geotools.data.DefaultTransaction) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Test(org.junit.Test)

Example 9 with Transaction

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());
}
Also used : Transaction(org.geotools.data.Transaction) DefaultTransaction(org.geotools.data.DefaultTransaction) ResourceId(org.opengis.filter.identity.ResourceId) ObjectId(org.locationtech.geogig.api.ObjectId) Id(org.opengis.filter.Id) FeatureId(org.opengis.filter.identity.FeatureId) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) DefaultTransaction(org.geotools.data.DefaultTransaction) Test(org.junit.Test)

Example 10 with Transaction

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);
}
Also used : FeatureId(org.opengis.filter.identity.FeatureId) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Transaction(org.geotools.data.Transaction) DefaultTransaction(org.geotools.data.DefaultTransaction) ObjectId(org.locationtech.geogig.api.ObjectId) RevParse(org.locationtech.geogig.api.plumbing.RevParse) SimpleFeature(org.opengis.feature.simple.SimpleFeature) DefaultTransaction(org.geotools.data.DefaultTransaction) Test(org.junit.Test)

Aggregations

Transaction (org.geotools.data.Transaction)11 DefaultTransaction (org.geotools.data.DefaultTransaction)9 SimpleFeature (org.opengis.feature.simple.SimpleFeature)8 Test (org.junit.Test)7 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)7 FeatureId (org.opengis.filter.identity.FeatureId)6 ObjectId (org.locationtech.geogig.api.ObjectId)5 ResourceId (org.opengis.filter.identity.ResourceId)3 Function (com.google.common.base.Function)2 Optional (com.google.common.base.Optional)2 IOException (java.io.IOException)2 SimpleFeatureStore (org.geotools.data.simple.SimpleFeatureStore)2 BaseFeatureCollection (org.geotools.feature.collection.BaseFeatureCollection)2 DelegateFeatureIterator (org.geotools.feature.collection.DelegateFeatureIterator)2 NodeRef (org.locationtech.geogig.api.NodeRef)2 ProgressListener (org.locationtech.geogig.api.ProgressListener)2 RevFeature (org.locationtech.geogig.api.RevFeature)2 RevTree (org.locationtech.geogig.api.RevTree)2 CommitOp (org.locationtech.geogig.api.porcelain.CommitOp)2 Feature (org.opengis.feature.Feature)2