Package org.geotools.data

Examples of org.geotools.data.FeatureLock


        assertFalse(isLocked("road", "road.rd1"));
        road.lockFeatures();
        assertTrue(isLocked("road", "road.rd1"));
    }
    public void testUnLockFeatures() throws IOException {
        FeatureLock lock = new FeatureLock("test", 3600);
        FeatureLocking<SimpleFeatureType, SimpleFeature> road = (FeatureLocking<SimpleFeatureType, SimpleFeature>) data.getFeatureSource("road");
        road.setFeatureLock(lock);
        road.lockFeatures();

        try {
            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


        }
        t.addAuthorization(lock.getAuthorization());
        road.unLockFeatures();
    }
    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>) data.getFeatureSource("road");
        FeatureLocking<SimpleFeatureType, SimpleFeature> road2 = (FeatureLocking<SimpleFeatureType, SimpleFeature>) data.getFeatureSource("road");
        road1.setTransaction(t1);
        road2.setTransaction(t2);
        road1.setFeatureLock(lockA);
        road2.setFeatureLock(lockB);

        assertFalse(isLocked("road", "road.rd1"));
        assertFalse(isLocked("road", "road.rd2"));
        assertFalse(isLocked("road", "road.rd3"));

        road1.lockFeatures(rd1Filter);
        assertTrue(isLocked("road", "road.rd1"));
        assertFalse(isLocked("road", "road.rd2"));
        assertFalse(isLocked("road", "road.rd3"));

        road2.lockFeatures(rd2Filter);
        assertTrue(isLocked("road", "road.rd1"));
        assertTrue(isLocked("road", "road.rd2"));
        assertFalse(isLocked("road", "road.rd3"));

        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("road", "road.rd1"));
        assertTrue(isLocked("road", "road.rd2"));
        assertFalse(isLocked("road", "road.rd3"));

        t2.addAuthorization(lockB.getAuthorization());
        road2.unLockFeatures(rd2Filter);
        assertFalse(isLocked("road", "road.rd1"));
        assertFalse(isLocked("road", "road.rd2"));
        assertFalse(isLocked("road", "road.rd3"));
    }
View Full Code Here

        assertFalse(isLocked("road", "road.rd1"));
        assertFalse(isLocked("road", "road.rd2"));
        assertFalse(isLocked("road", "road.rd3"));
    }
    public void testGetFeatureLockingExpire() throws Exception {
        FeatureLock lock = new FeatureLock("Timed", 500);       
        FeatureLocking<SimpleFeatureType, SimpleFeature> road = (FeatureLocking<SimpleFeatureType, SimpleFeature>) data.getFeatureSource("road");
        road.setFeatureLock(lock);
        assertFalse(isLocked("road", "road.rd1"));
        road.lockFeatures(rd1Filter);
        assertTrue(isLocked("road", "road.rd1"));
View Full Code Here

    /*
     * Test for void lockFeatures()
     */
    public void testLockFeatures() throws IOException {
        FeatureLock lock = FeatureLockFactory.generate("test", LOCK_DURATION);
        FeatureLocking<SimpleFeatureType, SimpleFeature> road = (FeatureLocking<SimpleFeatureType, SimpleFeature>) dataStore.getFeatureSource(tname("road"));
        road.setFeatureLock(lock);

        assertFalse(isLocked(tname("road"), tname("road") + ".1"));
        assertTrue( road.lockFeatures() > 0 );
View Full Code Here

        assertTrue( road.lockFeatures() > 0 );
        assertTrue(isLocked(tname("road"), tname("road") + ".1"));
    }

    public void testUnLockFeatures() throws IOException {
        FeatureLock lock = FeatureLockFactory.generate("test", LOCK_DURATION);
        FeatureLocking<SimpleFeatureType, SimpleFeature> road = (FeatureLocking<SimpleFeatureType, SimpleFeature>) dataStore.getFeatureSource(tname("road"));
        road.setFeatureLock(lock);
        road.lockFeatures();

        try {
            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();
        t.close();
    }
View Full Code Here

        road.unLockFeatures();
        t.close();
    }

    public void testLockFeatureInteraction() throws IOException {
        FeatureLock lockA = FeatureLockFactory.generate("LockA", LOCK_DURATION);
        FeatureLock lockB = FeatureLockFactory.generate("LockB", LOCK_DURATION);
        Transaction t1 = new DefaultTransaction();
        Transaction t2 = new DefaultTransaction();
        FeatureLocking<SimpleFeatureType, SimpleFeature> road1 = (FeatureLocking<SimpleFeatureType, SimpleFeature>) dataStore.getFeatureSource(tname("road"));
        FeatureLocking<SimpleFeatureType, SimpleFeature> road2 = (FeatureLocking<SimpleFeatureType, SimpleFeature>) dataStore.getFeatureSource(tname("road"));
        road1.setTransaction(t1);
        road2.setTransaction(t2);
        road1.setFeatureLock(lockA);
        road2.setFeatureLock(lockB);

        assertFalse(isLocked(tname("road"), tname("road") + ".0"));
        assertFalse(isLocked(tname("road"), tname("road") + ".1"));
        assertFalse(isLocked(tname("road"), tname("road") + ".2"));

        assertEquals( 1, road1.lockFeatures(td.rd1Filter) );
        assertTrue(isLocked(tname("road"), tname("road") + "." + td.initialFidValue ));
        assertFalse(isLocked(tname("road"), tname("road") + "." + (td.initialFidValue+1)));
        assertFalse(isLocked(tname("road"), tname("road") + "." + (td.initialFidValue+2)));

        road2.lockFeatures(td.rd2Filter);
        assertTrue(isLocked(tname("road"), tname("road") + "." + td.initialFidValue));
        assertTrue(isLocked(tname("road"), tname("road") + "." + (td.initialFidValue+1)));
        assertFalse(isLocked(tname("road"), tname("road") + "." + (td.initialFidValue+2)));

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

        t1.addAuthorization(lockA.getAuthorization());

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

        road1.unLockFeatures(td.rd1Filter);
        assertFalse(isLocked(tname("road"), tname("road") + "." + (td.initialFidValue)));
        assertTrue(isLocked(tname("road"), tname("road") + "." + (td.initialFidValue+1)));
        assertFalse(isLocked(tname("road"), tname("road") + "." + (td.initialFidValue+2)));

        t2.addAuthorization(lockB.getAuthorization());
        road2.unLockFeatures(td.rd2Filter);
        assertFalse(isLocked(tname("road"), tname("road") + "." + (td.initialFidValue)));
        assertFalse(isLocked(tname("road"), tname("road") + "." + (td.initialFidValue+1)));
        assertFalse(isLocked(tname("road"), tname("road") + "." + (td.initialFidValue+2)));
View Full Code Here

        t1.close();
        t2.close();
    }

    public void testGetFeatureLockingExpire() throws Exception {
        FeatureLock lock = FeatureLockFactory.generate("Timed", 1000);

        FeatureLocking<SimpleFeatureType, SimpleFeature> road = (FeatureLocking<SimpleFeatureType, SimpleFeature>) dataStore.getFeatureSource(tname("road"));
        road.setFeatureLock(lock);
        assertFalse(isLocked(tname("road"), tname("road") + "." + (td.initialFidValue)));
View Full Code Here

     *             if a lock failed and the lock specified all locks, or if an
     *             another error occurred processing the lock operation
     */
    public LockFeatureResponseType lockFeature(LockFeatureType request)
        throws WFSException {
        FeatureLock fLock = null;

        try {
            // check we are dealing with a well formed request, there is at
            // least on lock request?
            List locks = request.getLock();

            if ((locks == null) || locks.isEmpty()) {
                String msg = "A LockFeature request must contain at least one LOCK element";
                throw new WFSException(msg);
            }

            LOGGER.info("locks size is " + locks.size());

            // create a new lock (token used to manage locks across datastores)
            fLock = newFeatureLock(request);

            // prepare the response object
            LockFeatureResponseType response = WfsFactory.eINSTANCE.createLockFeatureResponseType();
            response.setLockId(fLock.getAuthorization());
            response.setFeaturesLocked(WfsFactory.eINSTANCE.createFeaturesLockedType());
            response.setFeaturesNotLocked(WfsFactory.eINSTANCE.createFeaturesNotLockedType());

            // go thru each lock request, and try to perform locks on a feature
            // by feature basis
            // in order to allow for both "all" and "some" lock behaviour
            // TODO: if the lock is the default this default, lock the whole
            // query directly, should be a lot faster
            for (int i = 0, n = locks.size(); i < n; i++) {
                LockType lock = (LockType) locks.get(i);
                LOGGER.info("curLock is " + lock);

                QName typeName = lock.getTypeName();

                // get out the filter, and default to no filtering if none was
                // provided
                Filter filter = (Filter) lock.getFilter();

                if (filter == null) {
                    filter = Filter.INCLUDE;
                }

                FeatureTypeInfo meta;
                FeatureSource<? extends FeatureType, ? extends Feature> source;
                FeatureCollection<? extends FeatureType, ? extends Feature> features;

                try {
                    meta = catalog.getFeatureTypeByName(typeName.getNamespaceURI(), typeName.getLocalPart());

                    if (meta == null) {
                        throw new WFSException("Unknown feature type " + typeName.getPrefix() + ":"
                            + typeName.getLocalPart());
                    }

                    source = meta.getFeatureSource(null,null);
                   
                    // make sure all geometric elements in the filter have a crs, and that the filter
                    // is reprojected to store's native crs as well
                    CoordinateReferenceSystem declaredCRS = WFSReprojectionUtil.getDeclaredCrs(
                            source.getSchema(), request.getVersion());
                    filter = WFSReprojectionUtil.normalizeFilterCRS(filter, source.getSchema(), declaredCRS);
                   
                    // now gather the features
                    features = source.getFeatures(filter);

                    if (source instanceof FeatureLocking) {
                        ((FeatureLocking) source).setFeatureLock(fLock);
                    }
                } catch (IOException e) {
                    throw new WFSException(e);
                }

                Iterator reader = null;
                int numberLocked = -1;

                try {
                    for (reader = features.iterator(); reader.hasNext();) {
                        SimpleFeature feature = (SimpleFeature) reader.next();

                        FeatureId fid = fid(feature.getID());
                        Id fidFilter = fidFilter(fid);

                        if (!(source instanceof FeatureLocking)) {
                            LOGGER.fine("Lock " + fid + " not supported by data store (authID:"
                                + fLock.getAuthorization() + ")");

                            response.getFeaturesNotLocked().getFeatureId().add(fid);

                            // lockFailedFids.add(fid);
                        } else {
                            // DEFQuery is just some indirection, should be in
                            // the locking interface.
                            // int numberLocked =
                            // ((DEFQueryFeatureLocking)source).lockFeature(feature);
                            // HACK: Query.NO_NAMES isn't working in postgis
                            // right now,
                            // so we'll just use all.
                            Query query = new Query(meta.getName(), (Filter) fidFilter,
                                    Query.DEFAULT_MAX, Query.ALL_NAMES, lock.getHandle());

                            numberLocked = ((FeatureLocking) source).lockFeatures(query);

                            if (numberLocked == 1) {
                                LOGGER.fine("Lock " + fid + " (authID:" + fLock.getAuthorization()
                                    + ")");
                                response.getFeaturesLocked().getFeatureId().add(fid);

                                // lockedFids.add(fid);
                            } else if (numberLocked == 0) {
                                LOGGER.fine("Lock " + fid + " conflict (authID:"
                                    + fLock.getAuthorization() + ")");
                                response.getFeaturesNotLocked().getFeatureId().add(fid);

                                // lockFailedFids.add(fid);
                            } else {
                                LOGGER.warning("Lock " + numberLocked + " " + fid + " (authID:"
                                    + fLock.getAuthorization() + ") duplicated FeatureID!");
                                response.getFeaturesLocked().getFeatureId().add(fid);

                                // lockedFids.add(fid);
                            }
                        }
                    }
                } catch (IOException ioe) {
                    throw new WFSException(ioe);
                } finally {
                    if (reader != null) {
                        features.close(reader);
                    }
                }

                // refresh lock times, so they all start the same instant and we
                // are nearer
                // to the spec when it says the expiry should start when the
                // lock
                // feature response has been totally written
                if (numberLocked > 0) {
                    Transaction t = new DefaultTransaction();

                    try {
                        try {
                            t.addAuthorization(response.getLockId());
                            DataStore dataStore = (DataStore) source.getDataStore();
                            dataStore.getLockingManager().refresh(response.getLockId(), t);
                        } finally {
                            t.commit();
                        }
                    } catch (IOException e) {
                        throw new WFSException(e);
                    } finally {
                        try {
                            t.close();
                        } catch(IOException e) {
                            throw new WFSException(e);
                        }
                    }
                }
            }

            // should we releas all? if not set default to true
            boolean lockAll = !(request.getLockAction() == AllSomeType.SOME_LITERAL);

            if (lockAll && !response.getFeaturesNotLocked().getFeatureId().isEmpty()) {
                // I think we need to release and fail when lockAll fails
                //
                // abort will release the locks
                throw new WFSException("Could not aquire locks for:"
                    + response.getFeaturesNotLocked());
            }

            //remove empty parts of the response object
            if (response.getFeaturesLocked().getFeatureId().isEmpty()) {
                response.setFeaturesLocked(null);
            }

            if (response.getFeaturesNotLocked().getFeatureId().isEmpty()) {
                response.setFeaturesNotLocked(null);
            }

            return response;
        } catch (WFSException e) {
            // release locks when something fails
            if (fLock != null) {
                try {
                    release(fLock.getAuthorization());
                } catch (WFSException e1) {
                    // log it
                    LOGGER.log(Level.SEVERE, "Error occured releasing locks", e1);
                }
            }
View Full Code Here

    final LockingManagement memoryLockManager = new MemoryLockManager(
        "default");
    final Transaction t1 = Transaction.AUTO_COMMIT;
    final DefaultTransaction t2 = new DefaultTransaction();
    t2.addAuthorization("auth1");
    FeatureLock lock = new FeatureLock(
        "auth1",
        1 /* minute */);
    memoryLockManager.lockFeatureID(
        "sometime",
        "f1",
 
View Full Code Here

    final LockingManagement memoryLockManager = new MemoryLockManager(
        "default");
    final Transaction t1 = Transaction.AUTO_COMMIT;
    final DefaultTransaction t2 = new DefaultTransaction();
    t2.addAuthorization("auth1");
    FeatureLock lock = new FeatureLock(
        "auth1",
        1 /* minute */);
    memoryLockManager.lockFeatureID(
        "sometime",
        "f1",
 
View Full Code Here

TOP

Related Classes of org.geotools.data.FeatureLock

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.