Search in sources :

Example 16 with VersioningException

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

the class Copy method insert.

private void insert(GenericName name, final Session sourceSS, final Session targetSS, Query query, final boolean erase, final boolean newVersion) throws DataStoreException {
    FeatureType type = sourceSS.getFeatureStore().getFeatureType(name.toString());
    // Change * to featureType default geometry name
    if (query != null && query.getSelection() != null) {
        final Filter newFilter = (Filter) new BBOXFilterVisitor(type).visit((Filter) query.getSelection());
        final Query builder = new Query();
        builder.copy(query);
        builder.setSelection(newFilter);
        query = builder;
    }
    final FeatureCollection collection = sourceSS.getFeatureCollection(query);
    // get the real FeatureType of collection (in case of reprojection, CRS is different).
    type = collection.getType();
    if (targetSS.getFeatureStore().getNames().contains(name)) {
        // ERASE
        if (erase) {
            targetSS.getFeatureStore().deleteFeatureType(name.toString());
            targetSS.getFeatureStore().createFeatureType(type);
        }
    } else {
        targetSS.getFeatureStore().createFeatureType(type);
    }
    // get the created name, namespace might change
    name = targetSS.getFeatureStore().getFeatureType(type.getName().tip().toString()).getName();
    if (targetSS.getFeatureStore().getQueryCapabilities().handleVersioning()) {
        try {
            targetSS.getFeatureStore().getVersioning(name.toString()).startVersioning();
        } catch (VersioningException ex) {
            throw new DataStoreException(ex.getLocalizedMessage(), ex);
        }
    }
    // NEW VERSION (remove old features)
    if (newVersion) {
        targetSS.removeFeatures(name.toString(), Filter.include());
    }
    // Logger
    final StringBuilder logMsg = new StringBuilder("Insert ");
    logMsg.append(collection.size()).append(" features ");
    logMsg.append("in type ").append(name.tip().toString());
    logMsg.append(" [");
    if (erase) {
        logMsg.append("ERASE");
        if (newVersion)
            logMsg.append(", NEWVERSION");
    }
    if (newVersion)
        logMsg.append("NEWVERSION");
    logMsg.append("]");
    LOGGER.log(Level.INFO, logMsg.toString());
    // APPEND
    targetSS.addFeatures(name.toString(), collection);
}
Also used : FeatureType(org.opengis.feature.FeatureType) DataStoreException(org.apache.sis.storage.DataStoreException) Query(org.geotoolkit.storage.feature.query.Query) Filter(org.opengis.filter.Filter) FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) VersioningException(org.geotoolkit.version.VersioningException)

Aggregations

VersioningException (org.geotoolkit.version.VersioningException)16 Connection (java.sql.Connection)10 SQLException (java.sql.SQLException)10 Statement (java.sql.Statement)8 ResultSet (java.sql.ResultSet)6 DataStoreException (org.apache.sis.storage.DataStoreException)6 Version (org.geotoolkit.version.Version)5 FeatureAssociationRole (org.opengis.feature.FeatureAssociationRole)4 PropertyType (org.opengis.feature.PropertyType)4 IOException (java.io.IOException)3 Timestamp (java.sql.Timestamp)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 Query (org.geotoolkit.storage.feature.query.Query)3 FeatureType (org.opengis.feature.FeatureType)3 ScriptRunner (org.geotoolkit.internal.sql.ScriptRunner)2 VersionControl (org.geotoolkit.version.VersionControl)2 Filter (org.opengis.filter.Filter)2 GenericName (org.opengis.util.GenericName)2 FileNotFoundException (java.io.FileNotFoundException)1