Package org.geotools.data

Examples of org.geotools.data.VersioningFeatureStore


        assertEquals(3, states.size());
    }

    public void testDeleteReinsert() throws Exception {
        // grab the datastore
        VersioningFeatureStore restricted = (VersioningFeatureStore) synchStore
                .getFeatureSource("restricted");
        SimpleFeatureType schema = restricted.getSchema();

        // remove
        Id removeFilter = ff.id(singleton(ff
                .featureId("restricted.d91fe390-bdc7-4b22-9316-2cd6c8737ef5")));
        Transaction t = new DefaultTransaction();
        restricted.setTransaction(t);
        restricted.removeFeatures(removeFilter);
        String v1 = restricted.getVersion();
        t.commit();

        // revert
        String v2 = restricted.getVersion();
        restricted.rollback("FIRST", null, null);
        t.commit();
        t.close();
       
        restricted.setTransaction(Transaction.AUTO_COMMIT);

        // grab the two readers, separate
        FeatureDiffReader r1 = restricted.getDifferences("FIRST", v1, null, null);
        FeatureDiffReader r2 = restricted.getDifferences(v1, v2, null, null);

        // build a merging one, it should report the same resuls
        MergingFeatureDiffReader merge = new MergingFeatureDiffReader(r1, r2);
       
        assertFalse(merge.hasNext());
View Full Code Here


        merge.close();
    }
   
    public void testMergeMulti() throws Exception {
        // grab the datastore
        VersioningFeatureStore restricted = (VersioningFeatureStore) synchStore
                .getFeatureSource("restricted");
        SimpleFeatureType schema = restricted.getSchema();

        // first update
        Id updateFilter = ff.id(singleton(ff
                .featureId("restricted.be7cafea-d0b7-4257-9b9c-1ed3de3f7ef4")));
        Transaction t = new DefaultTransaction();
        restricted.setTransaction(t);
        restricted.modifyFeatures(schema.getDescriptor("cat"), -48, updateFilter);
        String v1 = restricted.getVersion();
        t.commit();
       
        // second update
        WKTReader wkt = new WKTReader();
        Geometry g = wkt.read("MULTIPOLYGON(((0 0, 0 10, 10 10, 10 0, 0 0)))");
        restricted.modifyFeatures(schema.getDescriptor("the_geom"), g, updateFilter);
        String v2 = restricted.getVersion();
        t.commit();
       
        // clean up
        t.close();
        restricted.setTransaction(Transaction.AUTO_COMMIT);

        // grab the two readers, separate
        FeatureDiffReader r1 = restricted.getDifferences("FIRST", v1, null, null);
        FeatureDiffReader r2 = restricted.getDifferences(v1, v2, null, null);

        // build a merging one, it should report the same resuls
        MergingFeatureDiffReader merge = new MergingFeatureDiffReader(r1, r2);
       
        assertTrue(merge.hasNext());
View Full Code Here

                    long clientCentralRevision = client.getCentralRevision(layerName);

                    // compute the diff that we have to send the client. Notice that we have
                    // to skip over the local change occurred when we last performed a GetDiff
                    // against the client
                    VersioningFeatureStore fs = (VersioningFeatureStore) ds
                            .getFeatureSource(tableName);
                    fs.setTransaction(transaction);
                    String fromRevision = clientCentralRevision == -1 ? "FIRST" : String
                            .valueOf(clientCentralRevision);
                    TransactionType centralChanges;
                    LOGGER.log(Level.INFO, "About to compute PostDiff changes. Last central revision known to client " + clientCentralRevision + ", last GetDiff central revision " + getDiffCentralRevision);
                    if (getDiffCentralRevision == null || clientCentralRevision >= getDiffCentralRevision) {
                        // either first time or we don't need to make jumps
                        LOGGER.log(Level.INFO, "First PostDiff or clientRevion same as the last central one, computing diff from " + fromRevision +  " to LAST");
                        FeatureDiffReader fdr = fs.getDifferences(fromRevision, "LAST", null, null);
                        centralChanges = new VersioningTransactionConverter().convert(fdr,
                                TransactionType.class);
                    } else  {
                        // we need to jump over the last local changes
                        String before = String.valueOf(getDiffCentralRevision - 1);
                        String after = String.valueOf(getDiffCentralRevision);
                        LOGGER.log(Level.INFO, "Client revision lower than the server one, computing diff from " + fromRevision +  " to " + before + " and merging with diffs from " + after + " to LAST");
                        FeatureDiffReader fdr1 = fs.getDifferences(fromRevision, before, null, null);
                        FeatureDiffReader fdr2 = fs.getDifferences(after, "LAST", null, null);
                        FeatureDiffReader[] fdr = new FeatureDiffReader[] { fdr1, fdr2 };
                        centralChanges = new VersioningTransactionConverter().convert(fdr,
                                TransactionType.class);
                    }

                    // what is the latest change on this layer? (worst case it's the last GetDiff
                    // from this Unit)
                    long lastCentralRevision = clientCentralRevision;
                    li = fs.getLog("LAST", fromRevision, null, null, 1).features();
                    if (li.hasNext()) {
                        lastCentralRevision = (Long) li.next().getAttribute("revision");
                    }
                    li.close();

                    // finally run the PostDiff
                    PostDiffType postDiff = new PostDiffType();
                    postDiff.setTypeName(layerName);
                    postDiff.setFromVersion(clientCentralRevision);
                    postDiff.setToVersion(lastCentralRevision);
                    postDiff.setTransaction(centralChanges);
                    client.postDiff(postDiff);

                    // grab the changes from the client and apply them locally
                    GetDiffType getDiff = new GetDiffType();
                    getDiff.setFromVersion(lastUnitRevision == null ? -1 : lastUnitRevision);
                    getDiff.setTypeName(layerName);
                    GetDiffResponseType gdr = client.getDiff(getDiff);
                    TransactionType unitChanges = gdr.getTransaction();
                    core.applyChanges(unitChanges, fs);
                   
                    // mark down this layer as succesfully synchronised
                    FeatureStore<SimpleFeatureType, SimpleFeature> tuMetadata = (FeatureStore<SimpleFeatureType, SimpleFeature>) ds
                            .getFeatureSource(SYNCH_UNIT_TABLES);
                    tuMetadata.setTransaction(transaction);
                    SimpleFeatureType tuSchema = tuMetadata.getSchema();
                    int unitChangeCount = core.countChanges(unitChanges);
                    int centralChangeCount = core.countChanges(centralChanges);
                    if (unitChangeCount == 0 && centralChangeCount == 0) {
                        // just update the last_synch marker, as nothing else happened and
                        // this way we can avoid eating away central revision number (which
                        // might go up very rapidly otherwise)
                        AttributeDescriptor[] atts = new AttributeDescriptor[] { tuSchema
                                .getDescriptor("last_synchronization") };
                        Object[] values = new Object[] { new Date() };
                        Filter filter = ff.and(ff.equals(ff.property("table_id"), ff
                                .literal(tableId)), ff.equals(ff.property("unit_id"), ff
                                .literal(unitId)));
                        tuMetadata.modifyFeatures(atts, values, filter);
                    } else {
                        AttributeDescriptor[] atts = new AttributeDescriptor[] {
                                tuSchema.getDescriptor("last_synchronization"),
                                tuSchema.getDescriptor("getdiff_central_revision"),
                                tuSchema.getDescriptor("last_unit_revision") };
                        Object[] values = new Object[] { new Date(),
                                Long.parseLong(fs.getVersion()), gdr.getToVersion() };
                        Filter filter = ff.and(ff.equals(ff.property("table_id"), ff
                                .literal(tableId)), ff.equals(ff.property("unit_id"), ff
                                .literal(unitId)));
                        tuMetadata.modifyFeatures(atts, values, filter);
                    }
View Full Code Here

        assertXpathEvaluatesTo("0", "count(/gss:GetDiffResponse/gss:Changes/*)", dom);
    }
   
    public void testCleanMerge() throws Exception {
        // grab the datastore
        VersioningFeatureStore restricted = (VersioningFeatureStore) synchStore.getFeatureSource("restricted");
        SimpleFeatureType schema = restricted.getSchema();
        // make the same changes as in the post diff
        Id updateFilter = ff.id(singleton(ff.featureId("restricted.be7cafea-d0b7-4257-9b9c-1ed3de3f7ef4")));
        restricted.modifyFeatures(schema.getDescriptor("cat"), -48, updateFilter);
        // remove the third feature
        Id removeFilter = ff.id(singleton(ff.featureId("restricted.d91fe390-bdc7-4b22-9316-2cd6c8737ef5")));
        restricted.removeFeatures(removeFilter);
        assertEquals(3, restricted.getCount(Query.ALL));
       

        // get the response and do the basic checks
        MockHttpServletResponse response = postAsServletResponse(root(true),
                loadTextResource("PostDiffInitial.xml"));
View Full Code Here

        assertXpathEvaluatesTo("0", "count(/gss:GetDiffResponse/gss:Changes/*)", dom);
    }
   
    public void testNoConflictingChanges() throws Exception {
        // grab the datastore so that we can make some changes that will not generate conflicts
        VersioningFeatureStore restricted = (VersioningFeatureStore) synchStore.getFeatureSource("restricted");
        SimpleFeatureType schema = restricted.getSchema();
        // modify the fourth feature, change its cat from 400 to 450
        Id updateFilter = ff.id(singleton(ff.featureId("restricted.1b99be2b-2480-4742-ad52-95c294efda3b")));
        restricted.modifyFeatures(schema.getDescriptor("cat"), 450, updateFilter);
        // remove the third feature
        Id removeFilter = ff.id(singleton(ff.featureId("restricted.c15e76ab-e44b-423e-8f85-f6d9927b878a")));
        restricted.removeFeatures(removeFilter);
        assertEquals(3, restricted.getCount(Query.ALL));
       
        // execute the postDiff
        MockHttpServletResponse response = postAsServletResponse(root(true),
                loadTextResource("PostDiffInitial.xml"));
        checkPostDiffSuccessResponse(response);
View Full Code Here

   
    /**
     * This time we mix some conflicting and non conflicting changes
     */
    public void testConflicts() throws Exception {
        VersioningFeatureStore restricted = (VersioningFeatureStore) synchStore.getFeatureSource("restricted");
        SimpleFeatureType schema = restricted.getSchema();
        // modify the fourth feature, change its cat from 400 to 450
        Id updateFilter = ff.id(singleton(ff.featureId("restricted.1b99be2b-2480-4742-ad52-95c294efda3b")));
        restricted.modifyFeatures(schema.getDescriptor("cat"), 450, updateFilter);
        // a update that will generate a conflict
        updateFilter = ff.id(singleton(ff.featureId("restricted.d91fe390-bdc7-4b22-9316-2cd6c8737ef5")));
        restricted.modifyFeatures(schema.getDescriptor("cat"), 347, updateFilter);
        // an update that will generate a clean merge
        updateFilter = ff.id(singleton(ff.featureId("restricted.be7cafea-d0b7-4257-9b9c-1ed3de3f7ef4")));
        restricted.modifyFeatures(schema.getDescriptor("cat"), -48, updateFilter);

        // execute the postDiff
        MockHttpServletResponse response = postAsServletResponse(root(true),
                loadTextResource("PostDiffInitial.xml"));
        checkPostDiffSuccessResponse(response);
View Full Code Here

    @Override
    protected void setUp() throws Exception {
        super.setUp();
       
        // create a feature store
        VersioningFeatureStore mockStore = createNiceMock(VersioningFeatureStore.class);
        mockStore.removeFeatures(Filter.INCLUDE);
        expect(mockStore.getSchema()).andReturn(DataUtilities.createType(SCHEMA, "id:int"));
        replay(mockStore);

        // create a data store
        mock = createNiceMock(VersioningDataStore.class);
        expect(mock.getFeatureSource(SCHEMA)).andReturn(mockStore);
View Full Code Here

        assertXpathEvaluatesTo("0", "count(/gss:GetDiffResponse/gss:Changes/*)", dom);
    }
   
    public void testCleanMerge() throws Exception {
        // grab the datastore
        VersioningFeatureStore restricted = (VersioningFeatureStore) synchStore.getFeatureSource("restricted");
        SimpleFeatureType schema = restricted.getSchema();
        // make the same changes as in the post diff
        Id updateFilter = ff.id(singleton(ff.featureId("restricted.be7cafea-d0b7-4257-9b9c-1ed3de3f7ef4")));
        restricted.modifyFeatures(schema.getDescriptor("cat"), -48, updateFilter);
        // remove the third feature
        Id removeFilter = ff.id(singleton(ff.featureId("restricted.d91fe390-bdc7-4b22-9316-2cd6c8737ef5")));
        restricted.removeFeatures(removeFilter);
        assertEquals(3, restricted.getCount(Query.ALL));
       

        // get the response and do the basic checks
        MockHttpServletResponse response = postAsServletResponse(root(true),
                loadTextResource("PostDiffInitial.xml"));
View Full Code Here

        assertXpathEvaluatesTo("0", "count(/gss:GetDiffResponse/gss:Changes/*)", dom);
    }
   
    public void testNoConflictingChanges() throws Exception {
        // grab the datastore so that we can make some changes that will not generate conflicts
        VersioningFeatureStore restricted = (VersioningFeatureStore) synchStore.getFeatureSource("restricted");
        SimpleFeatureType schema = restricted.getSchema();
        // modify the fourth feature, change its cat from 400 to 450
        Id updateFilter = ff.id(singleton(ff.featureId("restricted.1b99be2b-2480-4742-ad52-95c294efda3b")));
        restricted.modifyFeatures(schema.getDescriptor("cat"), 450, updateFilter);
        // remove the third feature
        Id removeFilter = ff.id(singleton(ff.featureId("restricted.c15e76ab-e44b-423e-8f85-f6d9927b878a")));
        restricted.removeFeatures(removeFilter);
        assertEquals(3, restricted.getCount(Query.ALL));
       
        // execute the postDiff
        MockHttpServletResponse response = postAsServletResponse(root(true),
                loadTextResource("PostDiffInitial.xml"));
        checkPostDiffSuccessResponse(response);
View Full Code Here

   
    /**
     * This time we mix some conflicting and non conflicting changes
     */
    public void testConflicts() throws Exception {
        VersioningFeatureStore restricted = (VersioningFeatureStore) synchStore.getFeatureSource("restricted");
        SimpleFeatureType schema = restricted.getSchema();
        // modify the fourth feature, change its cat from 400 to 450
        Id updateFilter = ff.id(singleton(ff.featureId("restricted.1b99be2b-2480-4742-ad52-95c294efda3b")));
        restricted.modifyFeatures(schema.getDescriptor("cat"), 450, updateFilter);
        // a update that will generate a conflict
        updateFilter = ff.id(singleton(ff.featureId("restricted.d91fe390-bdc7-4b22-9316-2cd6c8737ef5")));
        restricted.modifyFeatures(schema.getDescriptor("cat"), 347, updateFilter);
        // an update that will generate a clean merge
        updateFilter = ff.id(singleton(ff.featureId("restricted.be7cafea-d0b7-4257-9b9c-1ed3de3f7ef4")));
        restricted.modifyFeatures(schema.getDescriptor("cat"), -48, updateFilter);

        // execute the postDiff
        MockHttpServletResponse response = postAsServletResponse(root(true),
                loadTextResource("PostDiffInitial.xml"));
        checkPostDiffSuccessResponse(response);
View Full Code Here

TOP

Related Classes of org.geotools.data.VersioningFeatureStore

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.