Package org.geotools.data

Examples of org.geotools.data.Transaction


    @Test
    public void testFeatureWriter_RowIDSDE_Transaction() throws IOException,
            UnavailableConnectionException {
        final String tableName = seRowidSdeTable;
        final Transaction transaction = new DefaultTransaction();
        try {
            FeatureWriter<SimpleFeatureType, SimpleFeature> writer;

            writer = addFeatures(tableName, transaction);
            /*
             * This one works regardless of the database being MSSQL or not because the table IS
             * being created as versioned by testData.createTestTable.
             * <http://support.esri.com/index.cfm?fa=knowledgebase.techarticles.articleShow&d=32190>
             */
            assertEquals(0, ds.getFeatureSource(tableName).getCount(Query.ALL));
            transaction.commit();
            writer.close();
            assertEquals(2, ds.getFeatureSource(tableName).getCount(Query.ALL));
        } finally {
            transaction.close();
        }
    }
View Full Code Here


        testFeatureWriterAutoCommit(tableName);
    }

    private void testFeatureWriterAutoCommit(final String tableName) throws IOException,
            CQLException, UnavailableConnectionException {
        final Transaction transaction = Transaction.AUTO_COMMIT;
        FeatureWriter<SimpleFeatureType, SimpleFeature> writer;

        writer = addFeatures(tableName, transaction);
        writer.close();
        assertEquals(2, ds.getFeatureSource(tableName).getCount(Query.ALL));
View Full Code Here

    @Test
    public void testFeatureWriter_RowID_USER_Transaction() throws IOException,
            UnavailableConnectionException {
        final String tableName = seRowidUserTable;
        final Transaction transaction = new DefaultTransaction();
        try {
            FeatureWriter<SimpleFeatureType, SimpleFeature> writer;

            writer = addFeatures(tableName, transaction);
            if (databaseIsMsSqlServer) {
                /*
                 * SQL Server always is at READ UNCOMMITTED isolation level iff the table is not
                 * versioned. And this one can't be versioned cause it has no sde maintained row id
                 * <
                 * http://support.esri.com/index.cfm?fa=knowledgebase.techarticles.articleShow&d=32190
                 * >
                 */
                assertEquals(2, ds.getFeatureSource(tableName).getCount(Query.ALL));
            } else {
                assertEquals(0, ds.getFeatureSource(tableName).getCount(Query.ALL));
            }
            transaction.commit();
            writer.close();
            assertEquals(2, ds.getFeatureSource(tableName).getCount(Query.ALL));
        } finally {
            transaction.close();
        }
    }
View Full Code Here

    @Test
    public void testFetureStore_ROWID_SDE_Transaction() throws IOException,
            UnavailableConnectionException {
        String tableName = seRowidSdeTable;

        Transaction transaction = new DefaultTransaction();
        try {
            List<FeatureId> fids = testFeatureStore(tableName, transaction);
            assertEquals(1, fids.size());

            assertEquals(0, ds.getFeatureSource(tableName).getCount(Query.ALL));
            transaction.commit();
            assertEquals(1, ds.getFeatureSource(tableName).getCount(Query.ALL));
        } finally {
            transaction.close();
        }
    }
View Full Code Here

    @Test
    public void testFetureStore_ROWID_USER_Transaction() throws IOException,
            UnavailableConnectionException {
        String tableName = seRowidUserTable;

        Transaction transaction = new DefaultTransaction();
        try {
            List<FeatureId> fids = testFeatureStore(tableName, transaction);
            assertEquals(1, fids.size());

            if (databaseIsMsSqlServer) {
                /*
                 * SQL Server always is at READ UNCOMMITTED isolation level iff the table is not
                 * versioned. And this one can't be versioned cause it has no sde maintained row id
                 * <
                 * http://support.esri.com/index.cfm?fa=knowledgebase.techarticles.articleShow&d=32190
                 * >
                 */
                assertEquals(1, ds.getFeatureSource(tableName).getCount(Query.ALL));
            } else {
                assertEquals(0, ds.getFeatureSource(tableName).getCount(Query.ALL));
            }
            transaction.commit();
            assertEquals(1, ds.getFeatureSource(tableName).getCount(Query.ALL));
        } finally {
            transaction.close();
        }
    }
View Full Code Here

        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

        testFeatures = testData.createTestFeatures(LineString.class, featureCount);

        final DataStore ds = testData.getDataStore();
        final SimpleFeatureStore fStore;
        fStore = (SimpleFeatureStore) ds.getFeatureSource(typeName);
        final Transaction transaction = new DefaultTransaction("testInsertTransactionAndQueryByFid");
        fStore.setTransaction(transaction);
        try {
            final List<FeatureId> addedFids = fStore.addFeatures(testFeatures);
            final FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);

            final Set<FeatureId> fids = new HashSet<FeatureId>();
            for (FeatureId fid : addedFids) {
                fids.add(fid);
            }
            final Id newFidsFilter = ff.id(fids);

            SimpleFeatureCollection features;
            features = fStore.getFeatures(newFidsFilter);
            assertEquals(2, features.size());
            transaction.commit();
        } catch (Exception e) {
            transaction.rollback();
            throw e;
        } finally {
            transaction.close();
        }
    }
View Full Code Here

        final Filter oldValueFilter = CQL.toFilter("INT32_COL = 3");
        final Query oldValueQuery = new Query(typeName, oldValueFilter);
        final Filter newValueFilter = CQL.toFilter("INT32_COL = -1000");
        final Query newValueQuery = new Query(typeName, newValueFilter);

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

        FeatureReader<SimpleFeatureType, SimpleFeature> reader;

        try {
            try {
                assertTrue(writer.hasNext());
                SimpleFeature feature = writer.next();
                feature.setAttribute("INT32_COL", Integer.valueOf(-1000));
                writer.write();
                assertFalse(writer.hasNext());
            } finally {
                writer.close();
            }

            reader = ds.getFeatureReader(oldValueQuery, Transaction.AUTO_COMMIT);
            try {
                if (databaseIsMsSqlServer) {
                    // SQL Server always is at READ UNCOMMITTED isolation level...
                    assertFalse(reader.hasNext());
                } else {
                    assertTrue(reader.hasNext());
                }
            } finally {
                reader.close();
            }

            reader = ds.getFeatureReader(newValueQuery, Transaction.AUTO_COMMIT);
            try {
                if (databaseIsMsSqlServer) {
                    // SQL Server always is at READ UNCOMMITTED isolation level...
                    assertTrue(reader.hasNext());
                } else {
                    assertFalse(reader.hasNext());
                }
            } finally {
                reader.close();
            }

            reader = ds.getFeatureReader(oldValueQuery, transaction);
            try {
                assertFalse(reader.hasNext());
            } finally {
                reader.close();
            }

            reader = ds.getFeatureReader(newValueQuery, transaction);
            try {
                assertTrue(reader.hasNext());
            } finally {
                reader.close();
            }

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

        reader = ds.getFeatureReader(newValueQuery, Transaction.AUTO_COMMIT);
        try {
            assertTrue(reader.hasNext());
View Full Code Here

        } finally {
            iterator.close();
        }

        {
            final Transaction transaction = new DefaultTransaction("testModifyFeaturesTransaction");
            store.setTransaction(transaction);

            try {
                final AttributeDescriptor propDescriptor = schema.getDescriptor("INT32_COL");
                store.modifyFeatures(propDescriptor.getName(), Integer.valueOf(-1000),
                        oldValueFilter);
                transaction.commit();
            } catch (Exception e) {
                transaction.rollback();
            } finally {
                transaction.close();
            }
        }
        store.setTransaction(Transaction.AUTO_COMMIT);

        final Query oldValueQuery = new Query(typeName, oldValueFilter);
View Full Code Here

            } finally {
                writer.close();
            }
        }

        final Transaction transaction = new DefaultTransaction("testUpdateAdjacentPolygons");
        store.setTransaction(transaction);
        final FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
        Filter fid1Filter = ff.id(Collections.singleton(ff.featureId(fid1)));
        Filter fid2Filter = ff.id(Collections.singleton(ff.featureId(fid2)));
        try {
            store.modifyFeatures(defaultGeometry.getName(), modif2, fid2Filter);
            store.modifyFeatures(defaultGeometry.getName(), modif1, fid1Filter);
            transaction.commit();
        } catch (Exception e) {
            transaction.rollback();
            throw e;
        } finally {
            transaction.close();
        }
        store.setTransaction(Transaction.AUTO_COMMIT);

        try {
            SimpleFeatureCollection features;
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.