Package org.geotools.data

Examples of org.geotools.data.Transaction$State


*/
public abstract class JDBCTransactionTest extends JDBCTestSupport {
    public void testCommit() throws IOException {
        //JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("ft1"));

        Transaction tx = new DefaultTransaction();

        //tx.putState( fs, new JDBCTransactionState( fs ) );
        FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriterAppend(tname("ft1"), tx);
        SimpleFeature feature = writer.next();
        feature.setAttribute(aname("intProperty"), new Integer(100));
        writer.write();
        writer.close();
        tx.commit();
        tx.close();

        SimpleFeatureCollection fc = dataStore.getFeatureSource(tname("ft1")).getFeatures();
        assertEquals(4, fc.size());
    }
View Full Code Here


    }

    public void testNoCommit() throws IOException {
        //JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("ft1"));

        Transaction tx = new DefaultTransaction();

        //tx.putState( fs, new JDBCTransactionState( fs ) );
        FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriterAppend(tname("ft1"), tx);
        SimpleFeature feature = writer.next();
        feature.setAttribute(aname("intProperty"), new Integer(100));
        writer.write();
        writer.close();
        tx.rollback();
        tx.close();

        SimpleFeatureCollection fc = dataStore.getFeatureSource(tname("ft1")).getFeatures();
        assertEquals(3, fc.size());
    }
View Full Code Here

    }

    public void testConcurrentTransactions() throws IOException {
        //JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("ft1"));

        Transaction tx1 = new DefaultTransaction();

        //tx1.putState( fs, new JDBCTransactionState( fs ) );
        Transaction tx2 = new DefaultTransaction();

        //tx2.putState( fs, new JDBCTransactionState( fs ) );
        FeatureWriter<SimpleFeatureType, SimpleFeature> w1 = dataStore.getFeatureWriterAppend(tname("ft1"), tx1);
        FeatureWriter<SimpleFeatureType, SimpleFeature> w2 = dataStore.getFeatureWriterAppend(tname("ft1"), tx2);

        SimpleFeature f1 = w1.next();
        SimpleFeature f2 = w2.next();

        f1.setAttribute(aname("intProperty"), new Integer(100));
        f2.setAttribute(aname("intProperty"), new Integer(101));

        w1.write();
        w2.write();

        w1.close();
        w2.close();

        tx1.commit();
        tx2.commit();
        tx1.close();
        tx2.close();

        SimpleFeatureCollection fc = dataStore.getFeatureSource(tname("ft1")).getFeatures();
        assertEquals(5, fc.size());
    }
View Full Code Here

        b.set(aname("intProperty"), new Integer(100));
        SimpleFeature f1 = b.buildFeature(null);
        DefaultFeatureCollection features = new DefaultFeatureCollection(null,null);
        features.add( f1 );

        Transaction tx1 = new DefaultTransaction();
        st.setTransaction(tx1);
        st.addFeatures( features );
        tx1.commit();
        tx1.close();
        assertEquals(4, dataStore.getFeatureSource(tname("ft1")).getCount(Query.ALL));
       
        Transaction tx2 = new DefaultTransaction();
        st.setTransaction(tx2);
        st.addFeatures( features );
        tx2.commit();
        tx2.close();
        assertEquals(5, dataStore.getFeatureSource(tname("ft1")).getCount(Query.ALL));
    }
View Full Code Here

                    throws IOException {
                return null;
            }
        };
   
        Transaction transaction = new DefaultTransaction();
   
        ContentEntry entry = new ContentEntry(dataStore, new NameImpl("test"));
        ContentState state = entry.getState(transaction);
        new DiffTransactionState(state);
   
        // state is extracted from state cache
        assertSame(state, entry.getState(transaction));
        // and contains our transaction
        assertSame(state.getTransaction(), transaction);
   
        try {
            transaction.close();
           
            // after transaction closing, the old state has been cleared, so
            // a new one is built and returned
            ContentState stateForClosedTransaction = entry.getState(transaction);
            assertNotSame(stateForClosedTransaction, state);
View Full Code Here

        r.close();
    }

    public void testInsertFeatures() throws Exception {
        Transaction transaction = new DefaultTransaction();
        SimpleFeatureStore featureStore = (SimpleFeatureStore) dataStore.getFeatureSource(tname("guid"));
        featureStore.setTransaction(transaction);
        assertEquals(featureStore.getCount(Query.ALL),2);

        SimpleFeatureType type = dataStore.getSchema(tname("guid"));
        SimpleFeature feature = SimpleFeatureBuilder.build(type, new Object[] { uuid3 }, "guid.3");

        SimpleFeatureCollection collection = DataUtilities.collection(feature);
        featureStore.addFeatures(collection);
        transaction.commit();
        assertEquals(featureStore.getCount(Query.ALL),3);
        transaction.close();
    }
View Full Code Here

        assertEquals(1, featureStore.getCount(Query.ALL));
    }

    public void testUUIDAsPrimaryKey() throws Exception {
        Transaction transaction = new DefaultTransaction();
        SimpleFeatureStore featureStore = (SimpleFeatureStore) dataStore.getFeatureSource(tname("uuidt"));
        featureStore.setTransaction(transaction);

        featureStore.addFeatures(createFeatureCollection());

        transaction.commit();
        assertEquals(3, featureStore.getCount(Query.ALL));
        transaction.close();
    }
View Full Code Here

            // feature by feature way then
            super.modifyFeatures(innerTypes, values, filter);
        } else {
            // let's grab the connection
            Connection cx = null;
            Transaction tx = getState().getTransaction();
            try {
                cx = getDataStore().getConnection(tx);
           
                // we want to support a "batch" update, but we need to be weary of locks
                SimpleFeatureType featureType = getSchema();
View Full Code Here

            // we don't have a fast way to perform this delete, let's do it the
            // feature by feature way then
            super.removeFeatures(filter);
        } else {
            // let's grab the connection
            Transaction tx = getState().getTransaction();
            Connection cx = null;
           
            try {
                cx = getDataStore().getConnection(tx);
               
View Full Code Here

        // transactionExample start
        Map<String, Serializable> params = new HashMap<String, Serializable>();
        params.put("directory", directory);
        DataStore store = DataStoreFinder.getDataStore(params);

        Transaction t1 = new DefaultTransaction("transaction 1");
        Transaction t2 = new DefaultTransaction("transactoin 2");

        SimpleFeatureType type = store.getSchema("example");
        SimpleFeatureStore featureStore = (SimpleFeatureStore) store
                .getFeatureSource("example");
        SimpleFeatureStore featureStore1 = (SimpleFeatureStore) store
                .getFeatureSource("example");
        SimpleFeatureStore featureStore2 = (SimpleFeatureStore) store
                .getFeatureSource("example");

        featureStore1.setTransaction(t1);
        featureStore2.setTransaction(t2);
       
        System.out.println("Step 1");
        System.out.println("------");
        System.out.println("start     auto-commit: "+DataUtilities.fidSet(featureStore.getFeatures()) );
        System.out.println("start              t1: "+DataUtilities.fidSet(featureStore1.getFeatures()) );
        System.out.println("start              t2: "+DataUtilities.fidSet(featureStore2.getFeatures()) );
       
        // select feature to remove
        FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
        Filter filter1 = ff.id(Collections.singleton(ff.featureId("fid1")));
        featureStore1.removeFeatures(filter1); // road1 removes fid1 on t1
       
        System.out.println();
        System.out.println("Step 2 transaction 1 removes feature 'fid1'");
        System.out.println("------");
        System.out.println("t1 remove auto-commit: "+DataUtilities.fidSet(featureStore.getFeatures()) );
        System.out.println("t1 remove          t1: "+DataUtilities.fidSet(featureStore1.getFeatures()) );
        System.out.println("t1 remove          t2: "+DataUtilities.fidSet(featureStore2.getFeatures()) );
        // new feature to add!
        SimpleFeature feature = SimpleFeatureBuilder.build(type, new Object[] {
                5, "chris", null }, "fid5");
        feature.getUserData().put(Hints.USE_PROVIDED_FID,true);
        feature.getUserData().put(Hints.PROVIDED_FID, "fid5");
       
        SimpleFeatureCollection collection = DataUtilities.collection(feature);
        featureStore2.addFeatures(collection);

        System.out.println();
        System.out.println("Step 3 transaction 2 adds a new feature '"+feature.getID()+"'");
        System.out.println("------");
        System.out.println("t2 add    auto-commit: "+DataUtilities.fidSet(featureStore.getFeatures()) );
        System.out.println("t2 add             t1: "+DataUtilities.fidSet(featureStore1.getFeatures()) );
        System.out.println("t1 add             t2: "+DataUtilities.fidSet(featureStore2.getFeatures()) );

        // commit transaction one
        t1.commit();
       
        System.out.println();
        System.out.println("Step 4 transaction 1 commits the removal of feature 'fid1'");
        System.out.println("------");
        System.out.println("t1 commit auto-commit: "+DataUtilities.fidSet(featureStore.getFeatures()) );
        System.out.println("t1 commit          t1: "+DataUtilities.fidSet(featureStore1.getFeatures()) );
        System.out.println("t1 commit          t2: "+DataUtilities.fidSet(featureStore2.getFeatures()) );

        // commit transaction two
        t2.commit();

        System.out.println();
        System.out.println("Step 5 transaction 2 commits the addition of '"+feature.getID()+"'");
        System.out.println("------");
        System.out.println("t2 commit auto-commit: "+DataUtilities.fidSet(featureStore.getFeatures()) );
        System.out.println("t2 commit          t1: "+DataUtilities.fidSet(featureStore1.getFeatures()) );
        System.out.println("t2 commit          t2: "+DataUtilities.fidSet(featureStore2.getFeatures()) );

        t1.close();
        t2.close();
        store.dispose(); // clear out any listeners
        // transactionExample end
        System.out.println("\ntransactionExample end\n");
    }
View Full Code Here

TOP

Related Classes of org.geotools.data.Transaction$State

Copyright © 2018 www.massapicom. 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.