Package org.geotools.data

Examples of org.geotools.data.DefaultTransaction


        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

     */
    public void startTransaction(){
        if(transaction!=null){
            throw new IllegalStateException("Transaction already open!");
        }
        this.transaction = new DefaultTransaction("MosaicCreationTransaction"+ System.nanoTime());
    }
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

      return ff;
    }
   
    public static void doDelete(DataStore ds,SimpleFeatureType ft, Id ff) throws NoSuchElementException, IllegalAttributeException, IOException{
      assertNotNull("doInsertFailed?",ff);
      Transaction t = new DefaultTransaction();
      SimpleFeatureStore fs = (SimpleFeatureStore)ds.getFeatureSource(ft.getTypeName());
      fs.setTransaction(t);
     
      System.out.println("Delete Read 1");
      SimpleFeatureIterator fr = fs.getFeatures().features();
      int count1 = 0;
      while(fr.hasNext()){
        count1 ++; fr.next();
      }
        fr.close();

      System.out.println("Delete Remove "+ff);
      fs.removeFeatures(ff);

      System.out.println("Delete Read 2");
      fr = fs.getFeatures().features();
      int count2 = 0;
      while(fr.hasNext()){
        count2 ++;
        if(count2<5)
          System.out.println("# == "+count2+" "+fr.next().getID());
        else
          fr.next();
      }
        fr.close();
      assertTrue("Read 1 == "+count1+" Read 2 == "+count2,count2<count1);

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

      System.out.println("Delete Read 3");
      fr = fs.getFeatures().features();
      int count3 = 0;
      while(fr.hasNext()){
View Full Code Here

        fr.close();
      assertTrue(count2==count3);
    }
   
    public static void doUpdate(DataStore ds,SimpleFeatureType ft, String attributeToChange, Object newValue ) throws IllegalFilterException, FactoryRegistryException, NoSuchElementException, IOException, IllegalAttributeException{
      Transaction t = new DefaultTransaction();
      SimpleFeatureStore fs = (SimpleFeatureStore)ds.getFeatureSource(ft.getTypeName());
      fs.setTransaction(t);
     
      AttributeDescriptor at = ft.getDescriptor(attributeToChange);
      assertNotNull("Attribute "+attributeToChange+" does not exist",at);
     
      FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory(null);
        Filter f = filterFactory.equals(filterFactory.property(at.getLocalName()), filterFactory
                .literal(newValue));

      System.out.println("Update Read 1");
      SimpleFeatureIterator fr = fs.getFeatures(f).features();
     
      int count1 = 0;
      Object oldValue=null;
        if(fr!=null)
      while(fr.hasNext()){
        count1 ++; oldValue=fr.next().getAttribute(attributeToChange);
      }

        fr.close();
      System.out.println("Update Modify");
      fs.modifyFeatures(at,newValue,Filter.INCLUDE);

      System.out.println("Update Read 2");
      fr = fs.getFeatures(f).features();
      int count2 = 0;
      while(fr.hasNext()){
        count2 ++;
//        System.out.println(fr.next());
        fr.next();
      }
        fr.close();
//System.out.println("Read 1 == "+count1+" Read 2 == "+count2);
      assertTrue("Read 1 == "+count1+" Read 2 == "+count2,count2>count1);

      System.out.println("Update Commit");
        try {
            t.commit();

            assertTrue(((WFSTransactionState) t.getState(ds)).getFids(ft.getTypeName()) != null);

            System.out.println("Update Read 3");
            fr = fs.getFeatures(f).features();
            int count3 = 0;
            while( fr.hasNext() ) {
                count3++;
                fr.next();
            }
            fr.close();
            assertEquals(count2, count3);
        } finally {
            // cleanup
            fs.modifyFeatures(at, oldValue, Filter.INCLUDE);
            t.commit();
        }
    }
View Full Code Here

       
        SimpleFeature feat = new SimpleFeatureImpl(Arrays.asList(new Object[]{myPoint, "mypoint""pics/x.jpg", "pics/y.jpg"}), featureType1, new FeatureIdImpl("myid") );
       
        collection.add(feat);
       
        Transaction transaction = new DefaultTransaction();
        store.setTransaction(transaction);
       
        List<FeatureId> fids = store.addFeatures((SimpleFeatureCollection) collection);       
        assertEquals(1, fids.size());
       
        Filter filterRemove = filterfac.id(filterfac.featureId("poi.2"));       
        store.removeFeatures(filterRemove);
       
        Filter filterUpdate = filterfac.id(filterfac.featureId("poi.3"));       
        store.modifyFeatures("NAME", "blah", filterUpdate);
               
        transaction.commit();
       
        ContentFeatureCollection coll = store.getFeatures();
        FeatureIterator it= coll.features();
        while (it.hasNext()) {
            System.err.println(it.next());
View Full Code Here

    @Test
    public void testFeatureEvents() throws Exception {
        SimpleFeatureStore store1 = (SimpleFeatureStore) data.getFeatureSource(getRoadTypeName());
        SimpleFeatureStore store2 = (SimpleFeatureStore) data.getFeatureSource(getRoadTypeName());
        store1.setTransaction(new DefaultTransaction());
        class Listener implements FeatureListener {
            String name;

            List<FeatureEvent> events = new ArrayList<FeatureEvent>();
View Full Code Here

TOP

Related Classes of org.geotools.data.DefaultTransaction

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.