[PATCH 1 of 5] issu1393/SedimentLoadFactory: Handle off_epoch type queries
Wald Commits
scm-commit at wald.intevation.org
Wed Jul 31 11:26:36 CEST 2013
# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1375263120 -7200
# Node ID 7ea933f9c6ea842adeb7424a2f3040cfbd1e2c03
# Parent 0baf7abffcc63587905bc88f498a6457207871b7
issu1393/SedimentLoadFactory: Handle off_epoch type queries.
diff -r 0baf7abffcc6 -r 7ea933f9c6ea artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java Wed Jul 31 11:13:41 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java Wed Jul 31 11:32:00 2013 +0200
@@ -35,10 +35,12 @@
/** Private logger to use here. */
private static Logger log = Logger.getLogger(SedimentLoadFactory.class);
+ // Cache name/keys
public static final String LOADS_CACHE_NAME = "sedimentloads";
public static final String LOAD_DATA_CACHE_NAME = "sedimentload-data";
- /** Query to get km and ws for wst_id and column_pos. */
+ /** Query to get description and start year of single type
+ * sediment_yields. */
public static final String SQL_SELECT_SINGLES =
"SELECT DISTINCT " +
" sy.description AS description, " +
@@ -51,7 +53,23 @@
" AND ti.stop_time IS NULL " +
" AND syv.station BETWEEN :startKm AND :endKm";
- /** Query to get name for wst_id and column_pos. */
+ /** Query to get description, name and time range for official
+ * epoch-type sediment yields. */
+ public static final String SQL_SELECT_OFFEPOCHS =
+ "SELECT DISTINCT " +
+ " ti.start_time AS startYear, " +
+ " ti.stop_time AS end " +
+ " FROM sediment_yield sy " +
+ " JOIN rivers r ON sy.river_id = r.id " +
+ " JOIN sediment_yield_values syv ON sy.id = syv.sediment_yield_id " +
+ " JOIN time_intervals ti ON sy.time_interval_id = ti.id " +
+ " WHERE r.name = :name " +
+ " AND ti.stop_time IS NOT NULL " +
+ " AND syv.station BETWEEN :startKm AND :endKm " +
+ " AND sy.kind = 1";
+
+ /** Query to get description, name and time range for epoch-type
+ * sediment yields. */
public static final String SQL_SELECT_EPOCHS =
"SELECT DISTINCT " +
" sy.description AS description, " +
@@ -145,7 +163,8 @@
}
/**
- *
+ * @param river name of river.
+ * @param type
*/
public static SedimentLoad[] getLoads(
String river,
@@ -289,6 +308,30 @@
}
return loads;
}
+ else if (type.equals("off_epoch")) {
+ sqlQuery = session.createSQLQuery(SQL_SELECT_OFFEPOCHS)
+ .addScalar("startYear", StandardBasicTypes.DATE)
+ .addScalar("end", StandardBasicTypes.DATE);
+ sqlQuery.setString("name", river);
+ sqlQuery.setDouble("startKm", startKm);
+ sqlQuery.setDouble("endKm", endKm);
+ List<Object []> results = sqlQuery.list();
+
+ SedimentLoad[] loads = new SedimentLoad[results.size()];
+ for (int i = 0; i < results.size(); i++) {
+ Object[] row = results.get(i);
+ loads[i] = new SedimentLoad(
+ ((Date) row[0]).toString() + (Date) row[1],
+ (Date) row[0],
+ (Date) row[1],
+ true,
+ "");
+ }
+ return loads;
+ }
+ else {
+ log.warn("getSedimentLoadsUncached does not understand type " + type);
+ }
return new SedimentLoad[0];
}
More information about the Dive4elements-commits
mailing list