Package org.geotools.data

Examples of org.geotools.data.DefaultTransaction


        assertEquals(1, count(reader));
    }

    @Test
    public void testGetFeatureReaderFilterTransaction() throws Exception {
        Transaction t = new DefaultTransaction();
        SimpleFeatureType type = data.getSchema(getRoadTypeName());
        FeatureReader<SimpleFeatureType, SimpleFeature> reader;

        reader = data.getFeatureReader(new Query(getRoadTypeName(), Filter.EXCLUDE), t);

        // TODO: remove this silly check!
        // assertTrue(reader instanceof EmptyFeatureReader);
        assertEquals(type, reader.getFeatureType());
        assertEquals(0, count(reader));

        reader = data.getFeatureReader(new Query(getRoadTypeName()), t);
        assertTrue(reader instanceof DiffFeatureReader);
        assertEquals(type, reader.getFeatureType());
        assertEquals(roadFeatures.length, count(reader));

        reader = data.getFeatureReader(new Query(getRoadTypeName(), rd1Filter), t);

        // assertTrue(reader instanceof DiffFeatureReader);//Currently wrapped by a filtering
        // feature reader
        assertEquals(type, reader.getFeatureType());
        assertEquals(1, count(reader));

        SimpleFeatureStore store = (SimpleFeatureStore) data.getFeatureSource(getRoadTypeName());
        store.setTransaction(t);
        store.removeFeatures(rd1Filter);

        reader = data.getFeatureReader(new Query(getRoadTypeName(), Filter.EXCLUDE), t);
        assertEquals(0, count(reader));

        reader = data.getFeatureReader(new Query(getRoadTypeName()), t);
        assertEquals(roadFeatures.length - 1, count(reader));

        reader = data.getFeatureReader(new Query(getRoadTypeName(), rd1Filter), t);
        assertEquals(0, count(reader));

        t.rollback();
        reader = data.getFeatureReader(new Query(getRoadTypeName(), Filter.EXCLUDE), t);
        assertEquals(0, count(reader));

        reader = data.getFeatureReader(new Query(getRoadTypeName()), t);
        assertEquals(roadFeatures.length, count(reader));
View Full Code Here


    /**
     * Test two transactions one removing feature, and one adding a feature.
     */
    @Test
    public void testGetFeatureWriterTransaction() throws Exception {
        Transaction t1 = new DefaultTransaction();
        Transaction t2 = new DefaultTransaction();
        FeatureWriter<SimpleFeatureType, SimpleFeature> writer1 = data.getFeatureWriter(
                getRoadTypeName(), rd1Filter, t1);
        FeatureWriter<SimpleFeatureType, SimpleFeature> writer2 = data.getFeatureWriterAppend(
                getRoadTypeName(), t2);

        SimpleFeatureType road = data.getSchema(getRoadTypeName());
        FeatureReader<SimpleFeatureType, SimpleFeature> reader;
        SimpleFeature feature;
        SimpleFeature[] ORIGIONAL = roadFeatures;
        SimpleFeature[] REMOVE = new SimpleFeature[ORIGIONAL.length - 1];
        SimpleFeature[] ADD = new SimpleFeature[ORIGIONAL.length + 1];
        SimpleFeature[] FINAL = new SimpleFeature[ORIGIONAL.length];
        int i;
        int index;
        index = 0;

        for (i = 0; i < ORIGIONAL.length; i++) {
            feature = ORIGIONAL[i];

            if (!feature.getID().equals(roadFeatures[0].getID())) {
                REMOVE[index++] = feature;
            }
        }

        for (i = 0; i < ORIGIONAL.length; i++) {
            ADD[i] = ORIGIONAL[i];
        }

        ADD[i] = newRoad;

        for (i = 0; i < REMOVE.length; i++) {
            FINAL[i] = REMOVE[i];
        }

        FINAL[i] = newRoad;

        // start of with ORIGINAL
        final Query allRoadsQuery = new Query(getRoadTypeName());
        reader = data.getFeatureReader(allRoadsQuery, Transaction.AUTO_COMMIT);
        assertTrue(covers(reader, ORIGIONAL));

        // writer 1 removes road.rd1 on t1
        // -------------------------------
        // - tests transaction independence from DataStore
        while (writer1.hasNext()) {
            feature = (SimpleFeature) writer1.next();
            assertEquals(roadFeatures[0].getID(), feature.getID());
            writer1.remove();
        }

        // still have ORIGIONAL and t1 has REMOVE
        reader = data.getFeatureReader(allRoadsQuery, Transaction.AUTO_COMMIT);

        assertTrue(covers(reader, ORIGIONAL));

        reader = data.getFeatureReader(allRoadsQuery, t1);
        assertTrue(covers(reader, REMOVE));

        // close writer1
        // --------------
        // ensure that modification is left up to transaction commmit
        writer1.close();

        // We still have ORIGIONAL and t1 has REMOVE
        reader = data.getFeatureReader(allRoadsQuery, Transaction.AUTO_COMMIT);
        assertTrue(covers(reader, ORIGIONAL));
        reader = data.getFeatureReader(allRoadsQuery, t1);
        assertTrue(covers(reader, REMOVE));

        // writer 2 adds road.rd4 on t2
        // ----------------------------
        // - tests transaction independence from each other
        feature = (SimpleFeature) writer2.next();
        feature.setAttributes(newRoad.getAttributes());
        writer2.write();

        // We still have ORIGIONAL and t2 has ADD
        reader = data.getFeatureReader(allRoadsQuery, Transaction.AUTO_COMMIT);
        assertTrue(covers(reader, ORIGIONAL));
        reader = data.getFeatureReader(allRoadsQuery, t2);
        assertTrue(coversLax(reader, ADD));

        // close writer2
        // -------------
        // ensure that modification is left up to transaction commmit
        writer2.close();

        // Still have ORIGIONAL and t2 has ADD
        reader = data.getFeatureReader(allRoadsQuery, Transaction.AUTO_COMMIT);
        assertTrue(covers(reader, ORIGIONAL));
        reader = data.getFeatureReader(allRoadsQuery, t2);
        assertTrue(coversLax(reader, ADD));

        // commit t1
        // ---------
        // -ensure that delayed writing of transactions takes place
        //
        t1.commit();

        // We now have REMOVE, as does t1 (which has not additional diffs)
        // t2 will have FINAL
        reader = data.getFeatureReader(allRoadsQuery, Transaction.AUTO_COMMIT);
        assertTrue(covers(reader, REMOVE));
        reader = data.getFeatureReader(allRoadsQuery, t1);
        assertTrue(covers(reader, REMOVE));
        reader = data.getFeatureReader(allRoadsQuery, t2);
        assertTrue(coversLax(reader, FINAL));

        // commit t2
        // ---------
        // -ensure that everyone is FINAL at the end of the day
        t2.commit();

        // We now have Number( remove one and add one)
        reader = data.getFeatureReader(allRoadsQuery, Transaction.AUTO_COMMIT);
        reader = data.getFeatureReader(allRoadsQuery, Transaction.AUTO_COMMIT);
        assertTrue(coversLax(reader, FINAL));
View Full Code Here

        assertEquals(1, road.getFeatures().size());
    }

    @Test
    public void testGetFeatureStoreTransactionSupport() throws Exception {
        Transaction t1 = new DefaultTransaction();
        Transaction t2 = new DefaultTransaction();

        SimpleFeatureStore road = (SimpleFeatureStore) data.getFeatureSource(getRoadTypeName());
        SimpleFeatureStore road1 = (SimpleFeatureStore) data.getFeatureSource(getRoadTypeName());
        SimpleFeatureStore road2 = (SimpleFeatureStore) data.getFeatureSource(getRoadTypeName());

        road1.setTransaction(t1);
        road2.setTransaction(t2);

        SimpleFeature feature;
        SimpleFeature[] ORIGINAL = roadFeatures;
        SimpleFeature[] REMOVE = new SimpleFeature[ORIGINAL.length - 1];
        SimpleFeature[] ADD = new SimpleFeature[ORIGINAL.length + 1];
        SimpleFeature[] FINAL = new SimpleFeature[ORIGINAL.length];
        int i;
        int index;
        index = 0;

        for (i = 0; i < ORIGINAL.length; i++) {
            feature = ORIGINAL[i];

            if (!feature.getID().equals(roadFeatures[0].getID())) {
                REMOVE[index++] = feature;
            }
        }

        for (i = 0; i < ORIGINAL.length; i++) {
            ADD[i] = ORIGINAL[i];
        }

        ADD[i] = newRoad;

        for (i = 0; i < REMOVE.length; i++) {
            FINAL[i] = REMOVE[i];
        }

        FINAL[i] = newRoad;

        // start of with ORIGINAL
        assertTrue(covers(road.getFeatures().features(), ORIGINAL));

        // road1 removes road.rd1 on t1
        // -------------------------------
        // - tests transaction independence from DataStore
        road1.removeFeatures(rd1Filter);

        // still have ORIGIONAL and t1 has REMOVE
        assertTrue(covers(road.getFeatures().features(), ORIGINAL));
        assertTrue(covers(road1.getFeatures().features(), REMOVE));

        // road2 adds road.rd4 on t2
        // ----------------------------
        // - tests transaction independence from each other
        SimpleFeatureCollection collection = DataUtilities
                .collection(new SimpleFeature[] { newRoad, });
        road2.addFeatures(collection);

        // We still have ORIGIONAL, t1 has REMOVE, and t2 has ADD
        assertTrue(covers(road.getFeatures().features(), ORIGINAL));
        assertTrue(covers(road1.getFeatures().features(), REMOVE));
        assertTrue(coversLax(road2.getFeatures().features(), ADD));

        // commit t1
        // ---------
        // -ensure that delayed writing of transactions takes place
        //
        t1.commit();

        // We now have REMOVE, as does t1 (which has not additional diffs)
        // t2 will have FINAL
        assertTrue(covers(road.getFeatures().features(), REMOVE));
        assertTrue(covers(road1.getFeatures().features(), REMOVE));
        assertTrue(coversLax(road2.getFeatures().features(), FINAL));

        // commit t2
        // ---------
        // -ensure that everyone is FINAL at the end of the day
        t2.commit();

        // We now have Number( remove one and add one)
        assertTrue(coversLax(road.getFeatures().features(), FINAL));
        assertTrue(coversLax(road1.getFeatures().features(), FINAL));
        assertTrue(coversLax(road2.getFeatures().features(), FINAL));
View Full Code Here

            road.unLockFeatures();
            fail("unlock should fail due on AUTO_COMMIT");
        } catch (IOException expected) {
        }

        Transaction t = new DefaultTransaction();
        road.setTransaction(t);

        try {
            road.unLockFeatures();
            fail("unlock should fail due lack of authorization");
        } catch (IOException expected) {
        }

        t.addAuthorization(lock.getAuthorization());
        road.unLockFeatures();
    }
View Full Code Here

    @SuppressWarnings("unchecked")
    @Test
    public void testLockFeatureInteraction() throws IOException {
        FeatureLock lockA = new FeatureLock("LockA", 3600);
        FeatureLock lockB = new FeatureLock("LockB", 3600);
        Transaction t1 = new DefaultTransaction();
        Transaction t2 = new DefaultTransaction();
        FeatureLocking<SimpleFeatureType, SimpleFeature> road1;
        FeatureLocking<SimpleFeatureType, SimpleFeature> road2;

        {
            SimpleFeatureSource source = data.getFeatureSource(getRoadTypeName());
            if (!(source instanceof FeatureLocking)) {
                LOGGER.info("testLockFeatureInteraction ignored, store does not support locking");
                return;
            }

            road1 = (FeatureLocking<SimpleFeatureType, SimpleFeature>) source;

            source = data.getFeatureSource(getRoadTypeName());
            if (!(source instanceof FeatureLocking)) {
                LOGGER.info("testLockFeatureInteraction ignored, store does not support locking");
                return;
            }
            road2 = (FeatureLocking<SimpleFeatureType, SimpleFeature>) source;
        }
        road1.setTransaction(t1);
        road2.setTransaction(t2);
        road1.setFeatureLock(lockA);
        road2.setFeatureLock(lockB);

        assertFalse(isLocked(getRoadTypeName(), roadFeatures[0].getID()));
        assertFalse(isLocked(getRoadTypeName(), roadFeatures[1].getID()));
        assertFalse(isLocked(getRoadTypeName(), roadFeatures[2].getID()));

        road1.lockFeatures(rd1Filter);
        assertTrue(isLocked(getRoadTypeName(), roadFeatures[0].getID()));
        assertFalse(isLocked(getRoadTypeName(), roadFeatures[1].getID()));
        assertFalse(isLocked(getRoadTypeName(), roadFeatures[2].getID()));

        road2.lockFeatures(rd2Filter);
        assertTrue(isLocked(getRoadTypeName(), roadFeatures[0].getID()));
        assertTrue(isLocked(getRoadTypeName(), roadFeatures[1].getID()));
        assertFalse(isLocked(getRoadTypeName(), roadFeatures[2].getID()));

        try {
            road1.unLockFeatures(rd1Filter);
            fail("need authorization");
        } catch (IOException expected) {
        }

        t1.addAuthorization(lockA.getAuthorization());

        try {
            road1.unLockFeatures(rd2Filter);
            fail("need correct authorization");
        } catch (IOException expected) {
        }

        road1.unLockFeatures(rd1Filter);
        assertFalse(isLocked(getRoadTypeName(), roadFeatures[0].getID()));
        assertTrue(isLocked(getRoadTypeName(), roadFeatures[1].getID()));
        assertFalse(isLocked(getRoadTypeName(), roadFeatures[2].getID()));

        t2.addAuthorization(lockB.getAuthorization());
        road2.unLockFeatures(rd2Filter);
        assertFalse(isLocked(getRoadTypeName(), roadFeatures[0].getID()));
        assertFalse(isLocked(getRoadTypeName(), roadFeatures[1].getID()));
        assertFalse(isLocked(getRoadTypeName(), roadFeatures[2].getID()));
    }
View Full Code Here

            e.setBounds(collection.getBounds());
        }

        create(e, collection.getSchema());

        Transaction tx = new DefaultTransaction();
        SimpleFeatureWriter w = writer(e, true, null, tx);
        SimpleFeatureIterator it = collection.features();
        try {
            while(it.hasNext()) {
                SimpleFeature f = it.next();
                SimpleFeature g = w.next();
                for (PropertyDescriptor pd : collection.getSchema().getDescriptors()) {
                    String name = pd.getName().getLocalPart();
                    g.setAttribute(name, f.getAttribute(name));
                }
                                            
                w.write();
            }
            tx.commit();
        }
        catch(Exception ex) {
            tx.rollback();
            throw new IOException(ex);
        }
        finally {
            w.close();
            it.close();
            tx.close();
        }

        entry.init(e);
    }
View Full Code Here

        Filter filter = fac.equals(fac.property("NAME"), fac.literal("E 58th St"));

        Query query = new Query("tiger:tiger_roads", filter);
        FeatureReader<SimpleFeatureType, SimpleFeature> reader = wfs.getFeatureReader(query,
                new DefaultTransaction());
        int expected = 0;
        while (reader.hasNext()) {
            expected++;
            reader.next();
        }
        query = new Query("tiger:tiger_roads", filter, 100, new String[] { "CFCC" }, "");
        reader = wfs.getFeatureReader(query, new DefaultTransaction());
        int count = 0;
        while (reader.hasNext()) {
            count++;
            reader.next();
        }
View Full Code Here

     
      String[] ps = new String []{"wkb_geometry","statel","countyl","stater","countyr"};
      Query q = new DefaultQuery("county_boundary",or,ps);        
      
        
      FeatureReader fr = ds.getFeatureReader(q, new DefaultTransaction() );
  
        while (fr.hasNext())
        {
          Feature f= fr.next();
          if (!alreadyThere(f.getDefaultGeometry()))
View Full Code Here

           
          };
      Query q = new DefaultQuery("delme_major",like,ps);        
      
        
      FeatureReader fr = ds.getFeatureReader(q, new DefaultTransaction() );
  
        while (fr.hasNext())
        {
          Feature f= fr.next();
         
View Full Code Here

     
      String[] ps = new String []{"wkb_geometry","tlid"};
      Query q = new DefaultQuery("completechain",cf,ps);        
      
        
      FeatureReader fr = ds.getFeatureReader(q, new DefaultTransaction() );
  
        while (fr.hasNext())
        {
          Feature f= fr.next();
         
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.