Examples of DefaultTransaction


Examples of org.geotools.data.DefaultTransaction

        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);
View Full Code Here

Examples of org.geotools.data.DefaultTransaction

        FeatureCollection<SimpleFeatureType, SimpleFeature> collection;
        collection = DataUtilities.collection(Arrays.asList((SimpleFeature) points1,
                (SimpleFeature) points2, (SimpleFeature) points3));

        Transaction tx = new DefaultTransaction();
        points.setTransaction(tx);
        try {
            List<FeatureId> newFids = points.addFeatures(collection);
            assertNotNull(newFids);
            assertEquals(3, newFids.size());

            FeatureId fid1 = newFids.get(0);
            FeatureId fid2 = newFids.get(1);
            FeatureId fid3 = newFids.get(2);

            // new ids should have been generated...
            assertFalse(idP1.equals(fid1.getID()));
            assertFalse(idP1.equals(fid1.getID()));
            assertFalse(idP1.equals(fid1.getID()));

            // now force the use of provided feature ids
            points1.getUserData().put(Hints.USE_PROVIDED_FID, Boolean.TRUE);
            points2.getUserData().put(Hints.USE_PROVIDED_FID, Boolean.TRUE);
            points3.getUserData().put(Hints.USE_PROVIDED_FID, Boolean.TRUE);

            List<FeatureId> providedFids = points.addFeatures(collection);
            assertNotNull(providedFids);
            assertEquals(3, providedFids.size());

            FeatureId fid11 = providedFids.get(0);
            FeatureId fid21 = providedFids.get(1);
            FeatureId fid31 = providedFids.get(2);

            // ids should match provided
            assertEquals(idP1, fid11.getID());
            assertEquals(idP2, fid21.getID());
            assertEquals(idP3, fid31.getID());

            tx.commit();

            assertEquals(1, points.getFeatures(ff.id(Collections.singleton(fid1))).size());
            assertEquals(1, points.getFeatures(ff.id(Collections.singleton(fid2))).size());
            assertEquals(1, points.getFeatures(ff.id(Collections.singleton(fid3))).size());

            assertEquals(1, points.getFeatures(ff.id(Collections.singleton(fid11))).size());
            assertEquals(1, points.getFeatures(ff.id(Collections.singleton(fid21))).size());
            assertEquals(1, points.getFeatures(ff.id(Collections.singleton(fid31))).size());

        } catch (Exception e) {
            tx.rollback();
            throw e;
        } finally {
            tx.close();
        }
    }
View Full Code Here

Examples of org.geotools.data.DefaultTransaction

        // independent of the addFeatures functionality
        insertAndAdd(lines1, lines2, lines3, 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 value
            SimpleFeature initial = points.getFeatures(filter).features().next();
            assertEquals("StringProp1_1", initial.getAttribute("sp"));

            // modify
            points.modifyFeatures("sp", "modified", filter);

            // modified value before commit
            SimpleFeature modified = points.getFeatures(filter).features().next();
            assertEquals("modified", modified.getAttribute("sp"));

            // unmodified value before commit on another store instance (tx isolation)
            assertEquals("StringProp1_1",
                    dataStore.getFeatureSource(pointsTypeName).getFeatures(filter).features()
                            .next().getAttribute("sp"));

            tx.commit();

            // modified value after commit on another store instance
            assertEquals("modified", dataStore.getFeatureSource(pointsTypeName).getFeatures(filter)
                    .features().next().getAttribute("sp"));
        } catch (Exception e) {
            tx.rollback();
            throw e;
        } finally {
            tx.close();
        }
        points.setTransaction(Transaction.AUTO_COMMIT);
        SimpleFeature modified = points.getFeatures(filter).features().next();
        assertEquals("modified", modified.getAttribute("sp"));
    }
View Full Code Here

Examples of org.geotools.data.DefaultTransaction

        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());
    }
View Full Code Here

Examples of org.geotools.data.DefaultTransaction

        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(pointsTypeName).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());
View Full Code Here

Examples of org.geotools.data.DefaultTransaction

        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(pointsTypeName).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());
View Full Code Here

Examples of org.geotools.data.DefaultTransaction

        assertTrue("visitor completed", progress.completed);
        assertEquals("visitor 100%", 100f, progress.progress);
        assertNull("visitor no problems", progress.exception);

        // we are going to use this transaction to modify and commit
        DefaultTransaction t1 = new DefaultTransaction("Transaction 1");
        SimpleFeatureStore featureStore1 = (SimpleFeatureStore) dataStore
                .getFeatureSource(typeName);
        featureStore1.setTransaction(t1);
        TestFeatureListener listener1 = new TestFeatureListener();
        featureStore1.addFeatureListener(listener1);
        // we are going to use this transaction to modify and rollback
        DefaultTransaction t2 = new DefaultTransaction("Transaction 2");
        SimpleFeatureStore featureStore2 = (SimpleFeatureStore) dataStore
                .getFeatureSource(typeName);
        featureStore2.setTransaction(t2);
        TestFeatureListener listener2 = new TestFeatureListener();
        featureStore2.addFeatureListener(listener2);
View Full Code Here

Examples of org.geotools.data.DefaultTransaction

        // public Transaction.AUTO_COMMIT view of the world
        // is as expected.
        assertEquals(8, origional.getCount(Query.ALL));

        // we are going to use this transaction to modify and commit
        DefaultTransaction t1 = new DefaultTransaction("Transaction 1");
        SimpleFeatureStore featureStore1 = (SimpleFeatureStore) dataStore
                .getFeatureSource(typeName);
        featureStore1.setTransaction(t1);
        TestFeatureListener listener1 = new TestFeatureListener();
        featureStore1.addFeatureListener(listener1);

        // verify they are all working
        assertEquals(8, origional.getCount(Query.ALL));
        assertEquals(8, featureStore1.getCount(Query.ALL));

        SimpleFeatureType schema = origional.getSchema();
        SimpleFeatureBuilder build = new SimpleFeatureBuilder(schema);

        int value = 24;
        build.add(Integer.valueOf(value));
        build.add(Short.valueOf((short) value));
        build.add(new Float(value / 10.0F));
        build.add(new Double(value / 10D));
        build.add("FEATURE_" + value);

        Calendar cal = Calendar.getInstance();
        cal.set(2004, 06, value, 0, 0, 0);
        build.add(cal);

        WKTReader reader = new WKTReader();
        build.add(reader.read("POINT(1 1)"));

        SimpleFeature newFeature = build.buildFeature(null);
        SimpleFeatureCollection newFeatures = DataUtilities.collection(newFeature);

        List<FeatureId> newFids = featureStore1.addFeatures(newFeatures);
        assertEquals(0, listener.list.size());
        assertEquals(1, listener1.list.size());

        FeatureEvent e = listener1.list.get(0);
        Id id = (Id) e.getFilter();
        assertTrue(id.getIdentifiers().containsAll(newFids));
        // remember the FeatureId with a strong reference
        FeatureId tempFeatureId = (FeatureId) id.getIdentifiers().iterator().next();
        assertTrue(newFids.contains(tempFeatureId));

        t1.commit();
        assertEquals(1, listener.list.size());
        assertEquals(2, listener1.list.size());

        BatchFeatureEvent batch = (BatchFeatureEvent) listener1.list.get(2);
        assertFalse("confirm tempFid is not in the commit",
View Full Code Here

Examples of org.geotools.data.DefaultTransaction

        final DataStore ds = testData.getDataStore();

        final SimpleFeatureType ftype = testFeatures.getSchema();
        final SimpleFeatureIterator iterator = testFeatures.features();

        final Transaction transaction = new DefaultTransaction();
        final FeatureWriter<SimpleFeatureType, SimpleFeature> writer;
        writer = ds.getFeatureWriter(typeName, transaction);

        FeatureReader<SimpleFeatureType, SimpleFeature> reader;
        final Query query = new Query(typeName);
        try {
            try {
                while (iterator.hasNext()) {
                    SimpleFeature addFeature = iterator.next();
                    SimpleFeature newFeature = writer.next();
                    for (int i = 0; i < ftype.getAttributeCount(); i++) {
                        String localName = ftype.getDescriptor(i).getLocalName();
                        newFeature.setAttribute(localName, addFeature.getAttribute(localName));
                    }
                    writer.write();
                }
            } catch (Exception e) {
                transaction.rollback();
                transaction.close();
            } finally {
                writer.close();
            }

            reader = ds.getFeatureReader(query, Transaction.AUTO_COMMIT);
            boolean hasNext;
            try {
                hasNext = reader.hasNext();
            } finally {
                reader.close();
            }
            if (databaseIsMsSqlServer) {
                // SQL Server always is at READ UNCOMMITTED isolation level...
                assertTrue(hasNext);
            } else {
                assertFalse("Features added, transaction not commited", hasNext);
            }

            try {
                transaction.commit();
            } catch (Exception e) {
                transaction.rollback();
                throw e;
            }
        } finally {
            transaction.close();
        }

        try {
            reader = ds.getFeatureReader(query, Transaction.AUTO_COMMIT);
            for (int i = 0; i < featureCount; i++) {
View Full Code Here

Examples of org.geotools.data.DefaultTransaction

        testMultiVersionSupport(Transaction.AUTO_COMMIT);
    }

    @Test
    public void testMultiVersionSupportTransaction() throws IOException {
        DefaultTransaction transaction = new DefaultTransaction();
        testMultiVersionSupport(transaction);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.