Search in sources :

Example 1 with Version

use of org.geotoolkit.version.Version in project geotoolkit by Geomatys.

the class Copy method execute.

/**
 *  {@inheritDoc }
 */
@Override
protected void execute() throws ProcessException {
    final FeatureStore sourceDS = inputParameters.getValue(SOURCE_STORE);
    final FeatureStore targetDS = inputParameters.getValue(TARGET_STORE);
    Session targetSS = inputParameters.getValue(TARGET_SESSION);
    final Boolean eraseParam = inputParameters.getValue(ERASE);
    final Boolean newVersion = inputParameters.getValue(NEW_VERSION);
    // Type name can be removed, it's embedded in the query param.
    final String typenameParam = inputParameters.getValue(TYPE_NAME);
    final Query queryParam = inputParameters.getValue(QUERY);
    final boolean doCommit = targetSS == null;
    final Session sourceSS = sourceDS.createSession(false);
    if (targetSS == null) {
        if (targetDS != null) {
            targetSS = targetDS.createSession(true);
        } else {
            throw new ProcessException("Input target_session or target_datastore missing.", this, null);
        }
    }
    boolean reBuildQuery = false;
    final String queryName;
    if (queryParam != null) {
        queryName = queryParam.getTypeName();
        reBuildQuery = true;
    } else if (typenameParam != null) {
        queryName = typenameParam;
    } else {
        queryName = "*";
    }
    final Set<GenericName> names;
    if ("*".equals(queryName)) {
        // all values
        try {
            names = sourceDS.getNames();
        } catch (DataStoreException ex) {
            throw new ProcessException(ex.getMessage(), this, ex);
        }
    } else {
        // pick only the wanted names
        names = new HashSet<>();
        final List<String> wanted = UnmodifiableArrayList.wrap(queryName.split(","));
        for (String s : wanted) {
            try {
                final FeatureType type = sourceDS.getFeatureType(s);
                names.add(type.getName());
            } catch (DataStoreException ex) {
                throw new ProcessException(ex.getMessage(), this, ex);
            }
        }
    }
    final float size = names.size();
    int inc = 0;
    for (GenericName n : names) {
        fireProgressing("Copying " + n + ".", (int) ((inc * 100f) / size), false);
        try {
            Query query;
            if (reBuildQuery) {
                Query builder = new Query();
                builder.copy(queryParam);
                builder.setTypeName(n);
                query = builder;
            } else {
                query = queryParam != null ? queryParam : new Query(n);
            }
            insert(n, sourceSS, targetSS, query, eraseParam, newVersion);
        } catch (DataStoreException ex) {
            throw new ProcessException(ex.getMessage(), this, ex);
        }
        inc++;
    }
    try {
        Date lastVersionDate = null;
        if (doCommit) {
            LOGGER.log(Level.INFO, "Commit all changes");
            targetSS.commit();
            // find last version
            for (GenericName n : names) {
                if (targetSS.getFeatureStore().getQueryCapabilities().handleVersioning()) {
                    final List<Version> versions = targetSS.getFeatureStore().getVersioning(n.toString()).list();
                    if (!versions.isEmpty()) {
                        if (lastVersionDate == null || versions.get(versions.size() - 1).getDate().getTime() > lastVersionDate.getTime()) {
                            lastVersionDate = versions.get(versions.size() - 1).getDate();
                        }
                    }
                }
            }
        }
        if (lastVersionDate != null) {
            outputParameters.getOrCreate(VERSION).setValue(lastVersionDate);
        }
    } catch (DataStoreException ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    } catch (VersioningException ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    }
}
Also used : FeatureType(org.opengis.feature.FeatureType) DataStoreException(org.apache.sis.storage.DataStoreException) Query(org.geotoolkit.storage.feature.query.Query) Date(java.util.Date) ProcessException(org.geotoolkit.process.ProcessException) GenericName(org.opengis.util.GenericName) Version(org.geotoolkit.version.Version) VersioningException(org.geotoolkit.version.VersioningException) FeatureStore(org.geotoolkit.storage.feature.FeatureStore) Session(org.geotoolkit.storage.feature.session.Session)

Example 2 with Version

use of org.geotoolkit.version.Version in project geotoolkit by Geomatys.

the class PostgresVersionControl method list.

@Override
public synchronized List<Version> list() throws VersioningException {
    if (!isVersioned()) {
        return Collections.EMPTY_LIST;
    }
    final List<Version> versions = new ArrayList<Version>();
    final String schemaName = featureStore.getDatabaseSchema();
    final String tableName = getHSTableName();
    Connection cnx = null;
    Statement stmt = null;
    ResultSet rs = null;
    try {
        cnx = featureStore.getDataSource().getConnection();
        stmt = cnx.createStatement();
        final StringBuilder sb = new StringBuilder("SELECT distinct(sub.date) as date FROM (");
        sb.append("SELECT \"HS_Begin\" AS date from ");
        dialect.encodeSchemaAndTableName(sb, schemaName, tableName);
        sb.append(" UNION ");
        sb.append("SELECT \"HS_End\" AS date from ");
        dialect.encodeSchemaAndTableName(sb, schemaName, tableName);
        sb.append(" WHERE \"HS_End\" IS NOT NULL");
        sb.append(") AS sub ORDER BY date ASC");
        rs = stmt.executeQuery(sb.toString());
        while (rs.next()) {
            final Timestamp ts = rs.getTimestamp(1);
            final Version v = new Version(this, ts.toString(), ts);
            versions.add(v);
        }
    } catch (SQLException ex) {
        throw new VersioningException(ex.getMessage(), ex);
    } finally {
        JDBCFeatureStoreUtilities.closeSafe(featureStore.getLogger(), cnx, stmt, null);
    }
    return versions;
}
Also used : Version(org.geotoolkit.version.Version) SQLException(java.sql.SQLException) Statement(java.sql.Statement) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) VersioningException(org.geotoolkit.version.VersioningException) Timestamp(java.sql.Timestamp)

Example 3 with Version

use of org.geotoolkit.version.Version in project geotoolkit by Geomatys.

the class PostgresVersioningTest method testTrimVersioning.

@Test
public void testTrimVersioning() throws DataStoreException, VersioningException {
    reload(true);
    List<Version> versions;
    Feature feature;
    ResourceId fid;
    Version v0;
    Version v1;
    Version v2;
    FeatureIterator ite;
    Query qb = new Query();
    // create table
    final FeatureType refType = FTYPE_SIMPLE;
    store.createFeatureType(refType);
    assertEquals(1, store.getNames().size());
    // get version control
    final VersionControl vc = store.getVersioning(refType.getName().toString());
    assertNotNull(vc);
    assertTrue(vc.isEditable());
    assertFalse(vc.isVersioned());
    // start versioning /////////////////////////////////////////////////////
    vc.startVersioning();
    assertTrue(vc.isVersioned());
    versions = vc.list();
    assertTrue(versions.isEmpty());
    // make an insert ///////////////////////////////////////////////////////
    final Point firstPoint = GF.createPoint(new Coordinate(56, 45));
    feature = refType.newInstance();
    feature.setPropertyValue("id", "0");
    feature.setPropertyValue("boolean", Boolean.TRUE);
    feature.setPropertyValue("integer", 14);
    feature.setPropertyValue("point", firstPoint);
    feature.setPropertyValue("string", "someteststring");
    store.addFeatures(refType.getName().toString(), Collections.singleton(feature));
    // we should have one version
    versions = vc.list();
    assertEquals(1, versions.size());
    // get identifier
    // ensure normal reading is correct without version----------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feature = ite.next();
        fid = FeatureExt.getId(feature);
    } finally {
        ite.close();
    }
    try {
        // wait a bit just to have some space between version dates
        Thread.sleep(1000);
    } catch (InterruptedException ex) {
        fail(ex.getMessage());
    }
    // make an update ///////////////////////////////////////////////////////
    final Point secondPoint = GF.createPoint(new Coordinate(-12, 21));
    final Map<String, Object> updates = new HashMap<>();
    updates.put("boolean", Boolean.FALSE);
    updates.put("integer", -3);
    updates.put("point", secondPoint);
    updates.put("string", "anothertextupdated");
    store.updateFeatures(refType.getName().toString(), fid, updates);
    try {
        // wait a bit just to have some space between version dates
        Thread.sleep(1000);
    } catch (InterruptedException ex) {
        fail(ex.getMessage());
    }
    // make a 2nd update ///////////////////////////////////////////////////////
    final Point thirdPoint = GF.createPoint(new Coordinate(145, -221));
    final Map<String, Object> updates2 = new HashMap<>();
    updates2.put("boolean", Boolean.FALSE);
    updates2.put("integer", 150);
    updates2.put("point", thirdPoint);
    updates2.put("string", "secondtextupdated");
    store.updateFeatures(refType.getName().toString(), fid, updates2);
    // get all versions organized in increase dates order.
    versions = vc.list();
    assertEquals(3, versions.size());
    v0 = versions.get(0);
    v1 = versions.get(1);
    v2 = versions.get(2);
    /* first trim between v1 date and v2 date (named middle date) to verify
         * deletion of first version and update v1 date at trim date.*/
    final Date middle = new Date((v1.getDate().getTime() + v2.getDate().getTime()) >> 1);
    vc.trim(middle);
    versions = vc.list();
    assertEquals(2, versions.size());
    // ensure version 0 does not exist
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v0.getLabel());
    try {
        store.createSession(true).getFeatureCollection(qb).isEmpty();
        fail("should not find version");
    } catch (FeatureStoreRuntimeException ex) {
    // ok
    }
    // ensure version v1 begin at middle date.
    assertEquals(vc.list().get(0).getDate().getTime(), middle.getTime());
    /* second trim at exactely the begining of the third version to verify,
         * deletion of second version and third version existence.*/
    vc.trim(v2);
    versions = vc.list();
    assertEquals(1, versions.size());
    // ensure version 1 does not exist
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v1.getLabel());
    try {
        store.createSession(true).getFeatureCollection(qb).isEmpty();
        fail("should not find version");
    } catch (FeatureStoreRuntimeException ex) {
    // ok
    }
    // ensure version v2 begin time doesn't change.
    assertEquals(vc.list().get(0).getDate().getTime(), v2.getDate().getTime());
    /* third trim just after v3 version date, to verify that v3
         * version date become trim date */
    final long lastDate = v2.getDate().getTime() + 400;
    vc.trim(new Date(lastDate));
    versions = vc.list();
    assertEquals(1, versions.size());
    // ensure version v2 begin time become lastDate.
    assertEquals(vc.list().get(0).getDate().getTime(), lastDate);
}
Also used : FeatureType(org.opengis.feature.FeatureType) Query(org.geotoolkit.storage.feature.query.Query) HashMap(java.util.HashMap) Point(org.locationtech.jts.geom.Point) Feature(org.opengis.feature.Feature) VersionControl(org.geotoolkit.version.VersionControl) Date(java.util.Date) FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) Version(org.geotoolkit.version.Version) ResourceId(org.opengis.filter.ResourceId) Coordinate(org.locationtech.jts.geom.Coordinate) FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException) Test(org.junit.Test)

Example 4 with Version

use of org.geotoolkit.version.Version in project geotoolkit by Geomatys.

the class PostgresVersioningTest method testRevertVersioning.

@Test
public void testRevertVersioning() throws DataStoreException, VersioningException {
    reload(true);
    List<Version> versions;
    Feature feature;
    ResourceId fid;
    Version v0;
    Version v1;
    Version v2;
    FeatureIterator ite;
    Query qb = new Query();
    // create table
    final FeatureType refType = FTYPE_SIMPLE;
    store.createFeatureType(refType);
    assertEquals(1, store.getNames().size());
    // get version control
    final VersionControl vc = store.getVersioning(refType.getName().toString());
    assertNotNull(vc);
    assertTrue(vc.isEditable());
    assertFalse(vc.isVersioned());
    // start versioning /////////////////////////////////////////////////////
    vc.startVersioning();
    assertTrue(vc.isVersioned());
    versions = vc.list();
    assertTrue(versions.isEmpty());
    // make an insert ///////////////////////////////////////////////////////
    final Point firstPoint = GF.createPoint(new Coordinate(56, 45));
    feature = refType.newInstance();
    feature.setPropertyValue("id", "0");
    feature.setPropertyValue("boolean", Boolean.TRUE);
    feature.setPropertyValue("integer", 14);
    feature.setPropertyValue("point", firstPoint);
    feature.setPropertyValue("string", "someteststring");
    store.addFeatures(refType.getName().toString(), Collections.singleton(feature));
    // we should have one version
    versions = vc.list();
    assertEquals(1, versions.size());
    // get identifier
    // ensure normal reading is correct without version----------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feature = ite.next();
        fid = FeatureExt.getId(feature);
    } finally {
        ite.close();
    }
    try {
        // wait a bit just to have some space between version dates
        Thread.sleep(1000);
    } catch (InterruptedException ex) {
        fail(ex.getMessage());
    }
    // make an update ///////////////////////////////////////////////////////
    final Point secondPoint = GF.createPoint(new Coordinate(-12, 21));
    final Map<String, Object> updates = new HashMap<>();
    updates.put("boolean", Boolean.FALSE);
    updates.put("integer", -3);
    updates.put("point", secondPoint);
    updates.put("string", "anothertextupdated");
    store.updateFeatures(refType.getName().toString(), fid, updates);
    try {
        // wait a bit just to have some space between version dates
        Thread.sleep(1000);
    } catch (InterruptedException ex) {
        fail(ex.getMessage());
    }
    // make a remove ///////////////////////////////////////////////////////
    store.removeFeatures(refType.getName().toString(), fid);
    // ensure test table is empty
    qb = new Query();
    qb.setTypeName(refType.getName());
    assertTrue(store.createSession(true).getFeatureCollection(qb).isEmpty());
    // get all versions organized in increase dates order.
    versions = vc.list();
    assertEquals(3, versions.size());
    v0 = versions.get(0);
    v1 = versions.get(1);
    v2 = versions.get(2);
    /* first revert between v1 date and v2 date (named middle date) to verify
         * re - insertion of feature in the original base and update v2 ending date become null.*/
    // =/2
    final Date middle = new Date((v1.getDate().getTime() + v2.getDate().getTime()) >> 1);
    vc.revert(middle);
    versions = vc.list();
    assertEquals(2, versions.size());
    // ensure version v2 does not exist
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v2.getLabel());
    try {
        store.createSession(true).getFeatureCollection(qb).isEmpty();
        fail("should not find version");
    } catch (FeatureStoreRuntimeException ex) {
    // ok
    }
    // ensure test table contain feature from version 1
    qb = new Query();
    qb.setTypeName(refType.getName());
    assertFalse(store.createSession(true).getFeatureCollection(qb).isEmpty());
    Feature featV1;
    Feature feat;
    // feature from test base result.
    qb = new Query();
    qb.setTypeName(refType.getName());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feat = ite.next();
        fid = FeatureExt.getId(feature);
    } finally {
        ite.close();
    }
    // feature from version v1.
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v1.getLabel());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        featV1 = ite.next();
        fid = FeatureExt.getId(feature);
    } finally {
        ite.close();
    }
    assertTrue(feat.getProperty("boolean").equals(featV1.getProperty("boolean")));
    assertTrue(feat.getProperty("integer").equals(featV1.getProperty("integer")));
    assertTrue(feat.getProperty("point").equals(featV1.getProperty("point")));
    assertTrue(feat.getProperty("string").equals(featV1.getProperty("string")));
    /* second revert at v0 begin date to verify update roll back, and verify
         * feature update from history table into original base.*/
    vc.revert(v0.getDate());
    versions = vc.list();
    assertEquals(1, versions.size());
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v1.getLabel());
    try {
        store.createSession(true).getFeatureCollection(qb).isEmpty();
        fail("should not find version");
    } catch (FeatureStoreRuntimeException ex) {
    // ok
    }
    // ensure test table contain feature from version 1
    qb = new Query();
    qb.setTypeName(refType.getName());
    assertFalse(store.createSession(true).getFeatureCollection(qb).isEmpty());
    // feature from test base result.
    qb = new Query();
    qb.setTypeName(refType.getName());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feat = ite.next();
        fid = FeatureExt.getId(feature);
    } finally {
        ite.close();
    }
    // feature from version v1.
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v0.getLabel());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        featV1 = ite.next();
        fid = FeatureExt.getId(feature);
    } finally {
        ite.close();
    }
    assertTrue(feat.getProperty("boolean").equals(featV1.getProperty("boolean")));
    assertTrue(feat.getProperty("integer").equals(featV1.getProperty("integer")));
    assertTrue(feat.getProperty("point").equals(featV1.getProperty("point")));
    assertTrue(feat.getProperty("string").equals(featV1.getProperty("string")));
}
Also used : FeatureType(org.opengis.feature.FeatureType) Query(org.geotoolkit.storage.feature.query.Query) HashMap(java.util.HashMap) Point(org.locationtech.jts.geom.Point) Feature(org.opengis.feature.Feature) VersionControl(org.geotoolkit.version.VersionControl) Date(java.util.Date) FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) Version(org.geotoolkit.version.Version) ResourceId(org.opengis.filter.ResourceId) Coordinate(org.locationtech.jts.geom.Coordinate) FeatureStoreRuntimeException(org.geotoolkit.storage.feature.FeatureStoreRuntimeException) Test(org.junit.Test)

Example 5 with Version

use of org.geotoolkit.version.Version in project geotoolkit by Geomatys.

the class PostgresVersioningTest method testSimpleTypeVersioning.

@Test
public void testSimpleTypeVersioning() throws DataStoreException, VersioningException {
    reload(true);
    List<Version> versions;
    Version version;
    Feature feature;
    ResourceId fid;
    Version v1;
    Version v2;
    Version v3;
    FeatureIterator ite;
    Query qb = new Query();
    // create table
    final FeatureType refType = FTYPE_SIMPLE;
    store.createFeatureType(refType);
    assertEquals(1, store.getNames().size());
    assertNotNull(store.getQueryCapabilities());
    assertTrue(store.getQueryCapabilities().handleVersioning());
    // get version control
    final VersionControl vc = store.getVersioning(refType.getName().toString());
    assertNotNull(vc);
    assertTrue(vc.isEditable());
    assertFalse(vc.isVersioned());
    // //////////////////////////////////////////////////////////////////////
    // start versioning /////////////////////////////////////////////////////
    vc.startVersioning();
    assertTrue(vc.isVersioned());
    versions = vc.list();
    assertTrue(versions.isEmpty());
    // check the version table is not visible in the feature types
    store.refreshMetaModel();
    final Set<GenericName> names = store.getNames();
    assertEquals(1, names.size());
    // //////////////////////////////////////////////////////////////////////
    // make an insert ///////////////////////////////////////////////////////
    final Point firstPoint = GF.createPoint(new Coordinate(56, 45));
    feature = refType.newInstance();
    feature.setPropertyValue("id", "0");
    feature.setPropertyValue("boolean", Boolean.TRUE);
    feature.setPropertyValue("integer", 14);
    feature.setPropertyValue("point", firstPoint);
    feature.setPropertyValue("string", "someteststring");
    store.addFeatures(refType.getName().toString(), Collections.singleton(feature));
    // we should have one version
    versions = vc.list();
    assertEquals(1, versions.size());
    version = versions.get(0);
    Date date = version.getDate();
    // ensure normal reading is correct without version----------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feature = ite.next();
        assertEquals(Boolean.TRUE, feature.getPropertyValue("boolean"));
        assertEquals(14, feature.getPropertyValue("integer"));
        assertEquals(firstPoint, feature.getPropertyValue("point"));
        assertEquals("someteststring", feature.getPropertyValue("string"));
        fid = FeatureExt.getId(feature);
    } finally {
        ite.close();
    }
    // ensure normal reading is correct with version-------------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(version.getLabel());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feature = ite.next();
        assertEquals(Boolean.TRUE, feature.getPropertyValue("boolean"));
        assertEquals(14, feature.getPropertyValue("integer"));
        assertEquals(firstPoint, feature.getPropertyValue("point"));
        assertEquals("someteststring", feature.getPropertyValue("string"));
    } finally {
        ite.close();
    }
    try {
        // wait a bit just to have some space between version dates
        Thread.sleep(1000);
    } catch (InterruptedException ex) {
        fail(ex.getMessage());
    }
    // //////////////////////////////////////////////////////////////////////
    // make an update ///////////////////////////////////////////////////////
    final Point secondPoint = GF.createPoint(new Coordinate(-12, 21));
    final Map<String, Object> updates = new HashMap<>();
    updates.put("boolean", Boolean.FALSE);
    updates.put("integer", -3);
    updates.put("point", secondPoint);
    updates.put("string", "anothertextupdated");
    store.updateFeatures(refType.getName().toString(), fid, updates);
    // we should have two versions
    versions = vc.list();
    assertEquals(2, versions.size());
    v1 = versions.get(0);
    v2 = versions.get(1);
    // should be ordered starting from the oldest
    assertTrue(v1.getDate().compareTo(v2.getDate()) < 0);
    // ensure normal reading is correct without version----------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feature = ite.next();
        assertEquals(Boolean.FALSE, feature.getPropertyValue("boolean"));
        assertEquals(-3, feature.getPropertyValue("integer"));
        assertEquals(secondPoint, feature.getPropertyValue("point"));
        assertEquals("anothertextupdated", feature.getPropertyValue("string"));
    } finally {
        ite.close();
    }
    // ensure normal reading is correct with version-------------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v2.getLabel());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feature = ite.next();
        assertEquals(Boolean.FALSE, feature.getPropertyValue("boolean"));
        assertEquals(-3, feature.getPropertyValue("integer"));
        assertEquals(secondPoint, feature.getPropertyValue("point"));
        assertEquals("anothertextupdated", feature.getPropertyValue("string"));
    } finally {
        ite.close();
    }
    // ensure reading a previous version works ------------------------------
    qb = new Query();
    ;
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v1.getLabel());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feature = ite.next();
        assertEquals(Boolean.TRUE, feature.getPropertyValue("boolean"));
        assertEquals(14, feature.getPropertyValue("integer"));
        assertEquals(firstPoint, feature.getPropertyValue("point"));
        assertEquals("someteststring", feature.getPropertyValue("string"));
    } finally {
        ite.close();
    }
    // ensure reading a previous version using not exact date----------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionDate(new Date(v1.getDate().getTime() + 400));
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feature = ite.next();
        assertEquals(Boolean.TRUE, feature.getPropertyValue("boolean"));
        assertEquals(14, feature.getPropertyValue("integer"));
        assertEquals(firstPoint, feature.getPropertyValue("point"));
        assertEquals("someteststring", feature.getPropertyValue("string"));
    } finally {
        ite.close();
    }
    // //////////////////////////////////////////////////////////////////////
    // delete record ////////////////////////////////////////////////////////
    store.removeFeatures(refType.getName().toString(), fid);
    qb = new Query();
    qb.setTypeName(refType.getName());
    assertEquals(0, store.getCount(qb));
    // we should have three versions
    versions = vc.list();
    assertEquals(3, versions.size());
    v1 = versions.get(0);
    v2 = versions.get(1);
    v3 = versions.get(2);
    // should be ordered starting from the oldest
    assertTrue(v2.getDate().compareTo(v1.getDate()) > 0);
    assertTrue(v3.getDate().compareTo(v2.getDate()) > 0);
    // ensure we have nothing if no version set -----------------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    assertTrue(store.createSession(true).getFeatureCollection(qb).isEmpty());
    // ensure we have nothing if latest version set -------------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v3.getLabel());
    assertTrue(store.createSession(true).getFeatureCollection(qb).isEmpty());
    // ensure we have nothing with date after deletion ----------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionDate(new Date(v3.getDate().getTime() + 400));
    assertTrue(store.createSession(true).getFeatureCollection(qb).isEmpty());
    // ensure reading version 1 works ---------------------------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v1.getLabel());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feature = ite.next();
        assertEquals(Boolean.TRUE, feature.getProperty("boolean").getValue());
        assertEquals(14, feature.getProperty("integer").getValue());
        assertEquals(firstPoint, feature.getProperty("point").getValue());
        assertEquals("someteststring", feature.getProperty("string").getValue());
    } finally {
        ite.close();
    }
    // ensure reading version 2 works ---------------------------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    qb.setVersionLabel(v2.getLabel());
    ite = store.createSession(true).getFeatureCollection(qb).iterator();
    try {
        feature = ite.next();
        assertEquals(Boolean.FALSE, feature.getProperty("boolean").getValue());
        assertEquals(-3, feature.getProperty("integer").getValue());
        assertEquals(secondPoint, feature.getProperty("point").getValue());
        assertEquals("anothertextupdated", feature.getProperty("string").getValue());
    } finally {
        ite.close();
    }
    // //////////////////////////////////////////////////////////////////////
    // drop versioning //////////////////////////////////////////////////////
    vc.dropVersioning();
    assertTrue(vc.isEditable());
    assertFalse(vc.isVersioned());
    versions = vc.list();
    assertTrue(versions.isEmpty());
    // ensure we have no record----------------------------------------------
    qb = new Query();
    qb.setTypeName(refType.getName());
    assertTrue(store.createSession(true).getFeatureCollection(qb).isEmpty());
}
Also used : FeatureType(org.opengis.feature.FeatureType) Query(org.geotoolkit.storage.feature.query.Query) HashMap(java.util.HashMap) Point(org.locationtech.jts.geom.Point) Feature(org.opengis.feature.Feature) VersionControl(org.geotoolkit.version.VersionControl) Date(java.util.Date) FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) GenericName(org.opengis.util.GenericName) Version(org.geotoolkit.version.Version) ResourceId(org.opengis.filter.ResourceId) Coordinate(org.locationtech.jts.geom.Coordinate) Test(org.junit.Test)

Aggregations

Version (org.geotoolkit.version.Version)11 Date (java.util.Date)8 VersionControl (org.geotoolkit.version.VersionControl)8 Query (org.geotoolkit.storage.feature.query.Query)7 Test (org.junit.Test)7 FeatureType (org.opengis.feature.FeatureType)7 HashMap (java.util.HashMap)6 FeatureIterator (org.geotoolkit.storage.feature.FeatureIterator)6 Coordinate (org.locationtech.jts.geom.Coordinate)6 Point (org.locationtech.jts.geom.Point)6 Feature (org.opengis.feature.Feature)6 ResourceId (org.opengis.filter.ResourceId)6 VersioningException (org.geotoolkit.version.VersioningException)5 GenericName (org.opengis.util.GenericName)4 DataStoreException (org.apache.sis.storage.DataStoreException)3 FeatureStoreRuntimeException (org.geotoolkit.storage.feature.FeatureStoreRuntimeException)3 Session (org.geotoolkit.storage.feature.session.Session)3 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2