Search in sources :

Example 6 with VersioningException

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

the class PGVersionControl method dropVersion.

@Override
public void dropVersion(Version version) throws VersioningException {
    try {
        final PyramidalCoverageResource ref = (PyramidalCoverageResource) store.findResource(name, version);
        final Collection<Pyramid> pyramids = Pyramids.getPyramids(ref);
        for (Pyramid p : pyramids) {
            ref.removeModel(p.getIdentifier());
        }
    } catch (DataStoreException ex) {
        throw new VersioningException(ex.getMessage(), ex);
    }
}
Also used : Pyramid(org.geotoolkit.data.multires.Pyramid) DataStoreException(org.apache.sis.storage.DataStoreException) PyramidalCoverageResource(org.geotoolkit.storage.coverage.PyramidalCoverageResource) VersioningException(org.geotoolkit.version.VersioningException)

Example 7 with VersioningException

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

the class PGVersionControl method list.

@Override
public List<Version> list() throws VersioningException {
    final StringBuilder sql = new StringBuilder();
    sql.append("SELECT distinct(pp.value) FROM ");
    sql.append(store.encodeTableName("Layer"));
    sql.append(" AS l ");
    sql.append("INNER JOIN ");
    sql.append(store.encodeTableName("Pyramid"));
    sql.append(" AS p ON p.\"layerId\" = l.id ");
    sql.append("LEFT OUTER JOIN ");
    sql.append(store.encodeTableName("PyramidProperty"));
    sql.append(" AS pp ON pp.\"pyramidId\" = p.id AND pp.key = 'version' ");
    sql.append("WHERE l.name = '");
    sql.append(name.tip()).append('\'');
    final ISODateParser dateparser = new ISODateParser();
    final List<Date> dates = new ArrayList<>();
    Connection cnx = null;
    Statement stmt = null;
    ResultSet rs = null;
    final Date unset = new Date();
    try {
        cnx = store.getDataSource().getConnection();
        stmt = cnx.createStatement();
        rs = stmt.executeQuery(sql.toString());
        while (rs.next()) {
            final String dateiso = rs.getString(1);
            if (dateiso == null || dateiso.isEmpty()) {
                dates.add(unset);
            } else {
                dates.add(dateparser.parseToDate(dateiso));
            }
        }
    } catch (SQLException ex) {
        throw new VersioningException(ex.getMessage(), ex);
    } finally {
        store.closeSafe(cnx, stmt, rs);
    }
    Collections.sort(dates);
    final List<Version> versions = new ArrayList<Version>(dates.size());
    for (Date d : dates) {
        if (d == unset) {
            versions.add(new Version(this, UNSET, d));
        } else {
            versions.add(new Version(this, d.toString(), d));
        }
    }
    return versions;
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) Date(java.util.Date) ISODateParser(org.geotoolkit.temporal.object.ISODateParser) Version(org.geotoolkit.version.Version) ResultSet(java.sql.ResultSet) VersioningException(org.geotoolkit.version.VersioningException)

Example 8 with VersioningException

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

the class PostgresQueryBuilder method selectSQL.

@Override
public String selectSQL(final FeatureType featureType, final Query query) throws SQLException, DataStoreException {
    Date vdate = query.getVersionDate();
    String vlabel = query.getVersionLabel();
    if (vdate == null && vlabel == null) {
        // no versioning, fallback on default method
        return super.selectSQL(featureType, query);
    }
    // search version date
    final PostgresVersionControl versionControl;
    try {
        versionControl = (PostgresVersionControl) store.getVersioning(featureType.getName().toString());
        if (vlabel != null) {
            vdate = versionControl.getVersion(vlabel).getDate();
        }
    } catch (VersioningException ex) {
        throw new DataStoreException(ex.getMessage(), ex);
    }
    final StringBuilder sql = new StringBuilder("SELECT ");
    final PrimaryKey key = store.getDatabaseModel().getPrimaryKey(featureType.getName().toString());
    // column names
    encodeSelectColumnNames(sql, featureType, query.getHints());
    sql.append(" FROM ");
    dialect.encodeSchemaAndTableName(sql, databaseSchema, versionControl.getHSTableName());
    // filtering and version/time filter
    Filter filter = query.getSelection();
    final FilterFactory ff = store.getFilterFactory();
    Filter tempFilter = ff.and(ff.lessOrEqual(ff.property("HS_Begin"), ff.literal(vdate)), ff.or(ff.greater(ff.property("HS_End"), ff.literal(vdate)), ff.isNull(ff.property("HS_End"))));
    filter = ff.and(filter, tempFilter);
    filter = (Filter) SimplifyingFilterVisitor.INSTANCE.visit(filter);
    if (!Filter.include().equals(filter)) {
        // encode filter
        sql.append(" WHERE ");
        sql.append(dialect.encodeFilter(filter, featureType));
    }
    // sorting
    encodeSortBy(featureType, QueryUtilities.getSortProperties(query.getSortBy()), key, sql);
    // finally encode limit/offset, if necessary
    dialect.encodeLimitOffset(sql, !query.getLimit().isPresent() ? null : (int) query.getLimit().getAsLong(), (int) query.getOffset());
    return sql.toString();
}
Also used : DataStoreException(org.apache.sis.storage.DataStoreException) Filter(org.opengis.filter.Filter) VersioningException(org.geotoolkit.version.VersioningException) PrimaryKey(org.geotoolkit.db.reverse.PrimaryKey) Date(java.util.Date) FilterFactory(org.opengis.filter.FilterFactory)

Example 9 with VersioningException

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

the class PostgresStore method dropHSFunctions.

/**
 * Uninstall the ISO-13249:7 History functions.
 * @throws VersioningException
 */
public synchronized void dropHSFunctions() throws VersioningException {
    hasHSFunctions = null;
    Connection cnx = null;
    try {
        cnx = getDataSource().getConnection();
        final ScriptRunner scriptRunner = new ScriptRunner(cnx);
        scriptRunner.run(PostgresStore.class.getResourceAsStream("/org/geotoolkit/db/postgres/HS_DropFunctions.sql"));
    } catch (IOException ex) {
        throw new VersioningException(ex.getMessage(), ex);
    } catch (SQLException ex) {
        throw new VersioningException(ex.getMessage(), ex);
    } finally {
        JDBCFeatureStoreUtilities.closeSafe(getLogger(), cnx);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) VersioningException(org.geotoolkit.version.VersioningException) IOException(java.io.IOException) ScriptRunner(org.geotoolkit.internal.sql.ScriptRunner)

Example 10 with VersioningException

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

the class PGCoverageStore method createCoverageReference.

private GridCoverageResource createCoverageReference(final GenericName name, Version version) throws DataStoreException {
    if (version == null) {
        try {
            // grab the latest
            VersionControl vc = new PGVersionControl(this, name);
            final List<Version> versions = vc.list();
            if (versions.isEmpty()) {
                final Calendar cal = Calendar.getInstance(PGVersionControl.GMT0);
                cal.setTimeInMillis(0);
                version = vc.createVersion(cal.getTime());
            } else {
                version = versions.get(versions.size() - 1);
            }
        } catch (VersioningException ex) {
            throw new DataStoreException(ex.getMessage(), ex);
        }
    }
    return new PGCoverageResource(this, name, version);
}
Also used : DataStoreException(org.apache.sis.storage.DataStoreException) Version(org.geotoolkit.version.Version) Calendar(java.util.Calendar) VersioningException(org.geotoolkit.version.VersioningException) VersionControl(org.geotoolkit.version.VersionControl)

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