comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataFactory.java @ 8058:fbe3ba5a480e

Sediment load: Fetch kind of sediment load from database to tell if it is official or not.
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 18 Jul 2014 17:43:27 +0200
parents cd35b76f1ef8
children 7e55790da464
comparison
equal deleted inserted replaced
8057:555dc5a9b282 8058:fbe3ba5a480e
30 public static final String SUSPENDED_STRING = "Schwebstoff"; 30 public static final String SUSPENDED_STRING = "Schwebstoff";
31 31
32 public static final String SQL_LOAD_RIVER_SEDIMENT_LOADS = 32 public static final String SQL_LOAD_RIVER_SEDIMENT_LOADS =
33 "SELECT " + 33 "SELECT " +
34 "sl.id AS sl_id, " + 34 "sl.id AS sl_id, " +
35 "sl.kind AS sl_kind, " +
35 "sl.description AS sl_description, " + 36 "sl.description AS sl_description, " +
36 "ti.start_time AS ti_start_time, " + 37 "ti.start_time AS ti_start_time, " +
37 "ti.stop_time AS ti_stoptime, " + 38 "ti.stop_time AS ti_stoptime, " +
38 "slv.value AS slv_value, " + 39 "slv.value AS slv_value, " +
39 "gf.name AS gf_name, " + 40 "gf.name AS gf_name, " +
43 "FROM sediment_load_values slv " + 44 "FROM sediment_load_values slv " +
44 "JOIN sediment_load sl ON slv.sediment_load_id = sl.id " + 45 "JOIN sediment_load sl ON slv.sediment_load_id = sl.id " +
45 "JOIN time_intervals ti ON sl.time_interval_id = ti.id " + 46 "JOIN time_intervals ti ON sl.time_interval_id = ti.id " +
46 "JOIN grain_fraction gf ON sl.grain_fraction_id = gf.id " + 47 "JOIN grain_fraction gf ON sl.grain_fraction_id = gf.id " +
47 "JOIN measurement_station ms ON slv.measurement_station_id = ms.id " + 48 "JOIN measurement_station ms ON slv.measurement_station_id = ms.id " +
48 "JOIN ranges rng ON ms.range_id = rng.id " + 49 "JOIN rivers r ON ms.river_id = r.id " +
49 "JOIN rivers r ON rng.river_id = r.id " +
50 "WHERE r.name = :river " + 50 "WHERE r.name = :river " +
51 "ORDER BY sl.id"; 51 "ORDER BY sl.id";
52 52
53 public static final SedimentLoadDataFactory INSTANCE = 53 public static final SedimentLoadDataFactory INSTANCE =
54 new SedimentLoadDataFactory(); 54 new SedimentLoadDataFactory();
100 100
101 Session session = SessionHolder.HOLDER.get(); 101 Session session = SessionHolder.HOLDER.get();
102 102
103 SQLQuery sqlQuery = session.createSQLQuery(SQL_LOAD_RIVER_SEDIMENT_LOADS) 103 SQLQuery sqlQuery = session.createSQLQuery(SQL_LOAD_RIVER_SEDIMENT_LOADS)
104 .addScalar("sl_id", StandardBasicTypes.INTEGER) 104 .addScalar("sl_id", StandardBasicTypes.INTEGER)
105 .addScalar("sl_kind", StandardBasicTypes.INTEGER)
105 .addScalar("sl_description", StandardBasicTypes.STRING) 106 .addScalar("sl_description", StandardBasicTypes.STRING)
106 .addScalar("ti_start_time", StandardBasicTypes.TIMESTAMP) 107 .addScalar("ti_start_time", StandardBasicTypes.TIMESTAMP)
107 .addScalar("ti_stop_time", StandardBasicTypes.TIMESTAMP) 108 .addScalar("ti_stop_time", StandardBasicTypes.TIMESTAMP)
108 .addScalar("slv_value", StandardBasicTypes.DOUBLE) 109 .addScalar("slv_value", StandardBasicTypes.DOUBLE)
109 .addScalar("gf_name", StandardBasicTypes.STRING) 110 .addScalar("gf_name", StandardBasicTypes.STRING)
121 122
122 for (Iterator iter = sqlQuery.iterate(); iter.hasNext();) { 123 for (Iterator iter = sqlQuery.iterate(); iter.hasNext();) {
123 Object [] row = (Object [])iter.next(); 124 Object [] row = (Object [])iter.next();
124 125
125 Integer sl_id = (Integer)row[0]; 126 Integer sl_id = (Integer)row[0];
126 String sl_description = (String)row[1]; 127 Integer sl_kind = (Integer)row[1];
127 Timestamp ti_start_time = (Timestamp)row[2]; 128 String sl_description = (String)row[2];
128 Timestamp ti_stop_time = (Timestamp)row[3]; 129 Timestamp ti_start_time = (Timestamp)row[3];
129 Double slv_value = (Double)row[4]; 130 Timestamp ti_stop_time = (Timestamp)row[4];
130 String gf_name = (String)row[5]; 131 Double slv_value = (Double)row[5];
131 Integer ms_id = (Integer)row[6]; 132 String gf_name = (String)row[6];
132 Double ms_station = (Double)row[7]; 133 Integer ms_id = (Integer)row[7];
133 String ms_type = (String)row[8]; 134 Double ms_station = (Double)row[8];
135 String ms_type = (String)row[9];
134 136
135 if (load == null || load.getId() != sl_id) { 137 if (load == null || load.getId() != sl_id) {
136 load = new SedimentLoadData.Load( 138 load = new SedimentLoadData.Load(
137 sl_id, sl_description, ti_start_time, ti_stop_time); 139 sl_id, sl_kind, sl_description,
140 ti_start_time, ti_stop_time);
138 141
139 // Grain fractions only change when a new sediment load starts. 142 // Grain fractions only change when a new sediment load starts.
140 grainFractionIndex = 143 grainFractionIndex =
141 SedimentLoadData.grainFractionIndex(gf_name); 144 SedimentLoadData.grainFractionIndex(gf_name);
142 145

http://dive4elements.wald.intevation.org