Package org.geotools.data

Examples of org.geotools.data.Transaction


            ReferencedEnvelope before = getBounds(new Query(getSchema().getTypeName(), filter));
            if (before != null && !before.isEmpty()) {
                affectedBounds = before;
            }
        }
        final Transaction transaction = getTransaction();

        FeatureReader<SimpleFeatureType, SimpleFeature> oldFeatures = getReader(filter);
        try {
            if (!oldFeatures.hasNext()) {
                // don't bother
                oldFeatures.close();
                return;
            }
        } catch (IOException e) {
            oldFeatures.close();
            throw e;
        } catch (RuntimeException e) {
            oldFeatures.close();
            throw e;
        }

        if (Transaction.AUTO_COMMIT.equals(transaction)) {
            // we're in auto commit. Do a batch update and commit right away
            WFSLocalTransactionState localState = getState().getLocalTransactionState();
            WFSRemoteTransactionState committingState = new WFSRemoteTransactionState(
                    getDataStore());
            committingState.watch(localState.getState());

            WFSDiff diff = localState.getDiff();

            ReferencedEnvelope bounds;
            bounds = diff.batchModify(properties, values, filter, oldFeatures, contentState);
            affectedBounds.expandToInclude(bounds);
            committingState.commit();

        } else {
            // we're in a transaction, record to local state and wait for commit to be called
            WFSLocalTransactionState localState;
            localState = (WFSLocalTransactionState) transaction.getState(getEntry());
            WFSDiff diff = localState.getDiff();

            ReferencedEnvelope bounds;
            bounds = diff.batchModify(properties, values, filter, oldFeatures, contentState);
            affectedBounds.expandToInclude(bounds);
View Full Code Here


            reader = new ReTypeFeatureReader(reader, destType, cloneContents);
        }
       
        reader = applyReprojectionDecorator(reader, localQuery, request);

        Transaction transaction = getTransaction();
        if (!Transaction.AUTO_COMMIT.equals(transaction)) {
            ContentEntry entry = getEntry();
            State state = transaction.getState(entry);
            WFSLocalTransactionState wfsState = (WFSLocalTransactionState) state;
            if (wfsState != null) {
                WFSDiff diff = wfsState.getDiff();
                reader = new DiffFeatureReader<SimpleFeatureType, SimpleFeature>(reader, diff, localQuery.getFilter());
            }
View Full Code Here

*/
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

TOP

Related Classes of org.geotools.data.Transaction

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.