Package org.geotools.data

Examples of org.geotools.data.Transaction


        .createNewDataStore(params);
    SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
    tb.setName("shapefile");
    tb.add("the_geom", Point.class);
    ds.createSchema(tb.buildFeatureType());
    Transaction transaction = Transaction.AUTO_COMMIT;
    FeatureWriter<SimpleFeatureType, SimpleFeature> writer = ds.getFeatureWriter(ds.getTypeNames()[0], Transaction.AUTO_COMMIT);
    SimpleFeature feature = writer.next();
    feature.setAttribute(0, null);
    writer.close();
    transaction.commit();
    ds.dispose();

    // Read the same file and check the geometry is null
    ShpFiles shpFiles = new ShpFiles(shpUrl);
    ShapefileReader reader = new ShapefileReader(shpFiles, false, true,
View Full Code Here


        ShapefileDataStore sds = createDataStore();

        int idx = loadFeatures(sds).size();

        while (idx > 0) {
            Transaction t = new DefaultTransaction();
            FeatureWriter<SimpleFeatureType, SimpleFeature> writer = null;

            try {
                writer = sds.getFeatureWriter(sds.getTypeNames()[0],
                        Filter.INCLUDE, t);
                writer.next();
                writer.remove();
            } finally {
                if (writer != null) {
                    writer.close();
                    writer = null;
                }
            }
            t.commit();
            t.close();
            assertEquals(--idx, loadFeatures(sds).size());
        }
        sds.dispose();
    }
View Full Code Here

        int idx = sds.getFeatureSource().getCount(Query.ALL);

        SimpleFeatureStore store = (SimpleFeatureStore) sds.getFeatureSource(sds
                .getTypeNames()[0]);

        Transaction transaction = new DefaultTransaction();
        store.setTransaction(transaction);
        SimpleFeature[] newFeatures1 = new SimpleFeature[1];
        SimpleFeature[] newFeatures2 = new SimpleFeature[2];
        GeometryFactory fac = new GeometryFactory();
        newFeatures1[0] = DataUtilities.template(sds.getSchema());
        newFeatures1[0].setDefaultGeometry(fac
                .createPoint(new Coordinate(0, 0)));
        newFeatures2[0] = DataUtilities.template(sds.getSchema());
        newFeatures2[0].setDefaultGeometry(fac
                .createPoint(new Coordinate(0, 0)));
        newFeatures2[1] = DataUtilities.template(sds.getSchema());
        newFeatures2[1].setDefaultGeometry(fac
                .createPoint(new Coordinate(0, 0)));

        store.addFeatures(DataUtilities.collection(newFeatures1));
        store.addFeatures(DataUtilities.collection(newFeatures2));
        transaction.commit();
        transaction.close();
        assertEquals(idx + 3, sds.getCount(Query.ALL));
        sds.dispose();

    }
View Full Code Here

        tmpFile.createNewFile();
        ShapefileDataStore s = new ShapefileDataStore(tmpFile.toURI().toURL());
        s.createSchema(type);
       
        // was failing in GEOT-2427
        Transaction t= new DefaultTransaction();
        FeatureWriter<SimpleFeatureType, SimpleFeature> writer = s.getFeatureWriter(s.getTypeNames()[0], t);
        SimpleFeature feature1 = writer.next();
        writer.close();
        s.dispose();
    }
View Full Code Here

        // http://jira.codehaus.org/browse/GEOT-2357
       
        final ShapefileDataStore ds = createDataStore();
        SimpleFeatureStore store;
        store = (SimpleFeatureStore) ds.getFeatureSource();
        Transaction t = new DefaultTransaction();
        store.setTransaction(t);
       
        int initialCount = store.getCount(Query.ALL);
       
        SimpleFeatureIterator features = store.getFeatures().features();
View Full Code Here

            FeatureWriter<SimpleFeatureType, SimpleFeature> writer) {
        this.store = store;
        this.writer = writer;
        this.state = store.getState();
       
        Transaction t = state.getTransaction();
        if( t != Transaction.AUTO_COMMIT ){
            // auto commit does not issue batch events
            t.putState(this,new EventContentTransactionState());
        }
    }
View Full Code Here

     * </p>
     *
     * @see org.geotools.data.FeatureWriter#close()
     */
    public void close() throws IOException {
        Transaction t = state.getTransaction();
        if (t != Transaction.AUTO_COMMIT ){
            t.removeState(this);
        }
        if( writer != null ){
            writer.close();
            writer = null;
        }
View Full Code Here

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

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

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

        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!
        // 45.52, -122.681944, Portland, 800, 2014
        GeometryFactory gf = JTSFactoryFinder.getGeometryFactory();
        Point portland = gf.createPoint(new Coordinate( 45.52, -122.681944));
        SimpleFeature feature = SimpleFeatureBuilder.build(type, new Object[] { portland, "Portland", 800, 2014 }, "locations.1");
        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");

        fileContents("transactionExample",file);
View Full Code Here

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

        Transaction t = new DefaultTransaction("locations");
        try {
            FeatureWriter<SimpleFeatureType, SimpleFeature> writer = store.getFeatureWriter(
                    "locations", Filter.INCLUDE, t);

            SimpleFeature feature;
            try {
                while (writer.hasNext()) {
                    feature = writer.next();
                    System.out.println("remove " + feature.getID());
                    writer.remove(); // marking contents for removal
                }
            } finally {
                writer.close();
            }
            System.out.println("commit " + t); // now the contents are removed
            t.commit();
        } catch (Throwable eek) {
            t.rollback();
        } finally {
            t.close();
            store.dispose();
        }
        // removeAllExample end
        System.out.println("\nremoveAllExample end\n");
       
View Full Code Here

    public WFSDataStoreWriteOnlineTest(){
        Logger.global.setLevel(Level.SEVERE);
    }
   
    public static Id doInsert(DataStore ds,SimpleFeatureType ft,SimpleFeatureCollection insert) throws NoSuchElementException, IOException, IllegalAttributeException{
      Transaction t = new DefaultTransaction();
      WFSFeatureStore fs = (WFSFeatureStore)ds.getFeatureSource(ft.getTypeName());
      fs.setTransaction(t);
      System.out.println("Insert Read 1");
      SimpleFeatureIterator fr = fs.getFeatures().features();
      int count1 = 0;
      while(fr.hasNext()){
        count1 ++; fr.next();
      }
        fr.close();
      System.out.println("Insert Add Features");
      List<FeatureId> fids1 = fs.addFeatures(insert);

      System.out.println("Insert Read 2");
      fr = fs.getFeatures().features();
      int count2 = 0;
      while(fr.hasNext()){
        count2 ++; fr.next();
      }
        fr.close();
      assertEquals(count1+insert.size(), count2);

        FilterFactory fac=CommonFactoryFinder.getFilterFactory(null);
        Set<FeatureId> featureIds = new HashSet<FeatureId>();
        for(FeatureId id : fids1){
            featureIds.add(id);
        }
        Id fidfilter = fac.id(featureIds);
       
        System.out.println("Remove Inserted Features");
        fs.removeFeatures(fidfilter);
       
        System.out.println("Insert Read 3");
        fr = fs.getFeatures().features();
        count2 = 0;
        while(fr.hasNext()){
            count2 ++; fr.next();
        }
        fr.close();
        assertEquals(count1, count2);
       
        System.out.println("Insert Add Features");
        fs.addFeatures(insert);

        System.out.println("Insert Read 2");
        fr = fs.getFeatures().features();
        count2 = 0;
        while(fr.hasNext()){
            count2 ++; fr.next();
        }
        fr.close();
        assertEquals(count1+insert.size(), count2);

       
      System.out.println("Insert Commit");
      t.commit();

      System.out.println("Insert Read 3");
      fr = fs.getFeatures().features();
      int count3 = 0;
      while(fr.hasNext()){
        count3 ++; fr.next();
      }
        fr.close();
      assertEquals(count2,count3);
     
      WFSTransactionState ts = (WFSTransactionState)t.getState(ds);
      String[] fids = ts.getFids(ft.getTypeName());
      assertNotNull(fids);
     
        Set ids = new HashSet();
        for(int i=0;i<fids.length;i++){
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.