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);
}
}
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;
}
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();
}
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);
}
}
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);
}
Aggregations