changeset 4007:d4d272e56d3a

S(Q) Fixed AIOOBE
author Sascha L. Teichmann <teichmann@intevation.de>
date Mon, 01 Oct 2012 23:05:21 +0200
parents d4e39cc5c10c
children fea3d9210948
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/MeasurementFactory.java
diffstat 2 files changed, 78 insertions(+), 100 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Mon Oct 01 18:39:48 2012 +0200
+++ b/flys-artifacts/ChangeLog	Mon Oct 01 23:05:21 2012 +0200
@@ -1,3 +1,8 @@
+2012-10-01	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/sq/MeasurementFactory.java:
+	  Wrote fractions SQL more compact. Fixed AIOOBE.
+
 2012-10-01	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/sq/Measurement.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/MeasurementFactory.java	Mon Oct 01 18:39:48 2012 +0200
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/MeasurementFactory.java	Mon Oct 01 23:05:21 2012 +0200
@@ -28,59 +28,38 @@
     private static final Logger log =
         Logger.getLogger(MeasurementFactory.class);
 
-    public static final String SQL_MEASSURE =
-        "SELECT m.datum        AS DATUM," +
-               "g.GLOTRECHTEID AS GLOTRECHTEID," +
-               "gp.LFDNR       AS LFDNR," +
-               "g.UFERABST     AS UFERABST," +
-               "g.UFERABLINKS  AS UFERABLINKS," +
-               "m.TSCHWEB      AS TSCHWEB," +
-               "m.TSAND        AS TSAND," +
-               "gp.GTRIEB      AS GTRIEB," +
-               "m.TGESCHIEBE   AS TGESCHIEBE," +
-               "sie.SIEB01     AS SIEB01," +
-               "sie.SIEB02     AS SIEB02," +
-               "sie.SIEB03     AS SIEB03," +
-               "sie.SIEB04     AS SIEB04," +
-               "sie.SIEB05     AS SIEB05," +
-               "sie.SIEB06     AS SIEB06," +
-               "sie.SIEB07     AS SIEB07," +
-               "sie.SIEB08     AS SIEB08," +
-               "sie.SIEB09     AS SIEB09," +
-               "sie.SIEB10     AS SIEB10," +
-               "sie.SIEB11     AS SIEB11," +
-               "sie.SIEB12     AS SIEB12," +
-               "sie.SIEB13     AS SIEB13," +
-               "sie.SIEB14     AS SIEB14," +
-               "sie.SIEB15     AS SIEB15," +
-               "sie.SIEB16     AS SIEB16," +
-               "sie.SIEB17     AS SIEB17," +
-               "sie.SIEB18     AS SIEB18," +
-               "sie.SIEB19     AS SIEB19," +
-               "sie.SIEB20     AS SIEB20," +
-               "sie.SIEB21     AS SIEB21," +
-               "gs.RSIEB01     AS RSIEB01," +
-               "gs.RSIEB02     AS RSIEB02," +
-               "gs.RSIEB03     AS RSIEB03," +
-               "gs.RSIEB04     AS RSIEB04," +
-               "gs.RSIEB05     AS RSIEB05," +
-               "gs.RSIEB06     AS RSIEB06," +
-               "gs.RSIEB07     AS RSIEB07," +
-               "gs.RSIEB08     AS RSIEB08," +
-               "gs.RSIEB09     AS RSIEB09," +
-               "gs.RSIEB10     AS RSIEB10," +
-               "gs.RSIEB11     AS RSIEB11," +
-               "gs.RSIEB12     AS RSIEB12," +
-               "gs.RSIEB13     AS RSIEB13," +
-               "gs.RSIEB14     AS RSIEB14," +
-               "gs.RSIEB15     AS RSIEB15," +
-               "gs.RSIEB16     AS RSIEB16," +
-               "gs.RSIEB17     AS RSIEB17," +
-               "gs.RSIEB18     AS RSIEB18," +
-               "gs.RSIEB19     AS RSIEB19," +
-               "gs.RSIEB20     AS RSIEB20," +
-               "gs.RSIEB21     AS RSIEB21," +
-               "gs.REST        AS REST " +
+    public static final String SQL_FACTIONS =
+        "SELECT m.datum    AS DATUM," +
+            "g.GLOTRECHTEID AS GLOTRECHTEID," +
+            "gp.LFDNR       AS LFDNR," +
+            "g.UFERABST     AS UFERABST," +
+            "g.UFERABLINKS  AS UFERABLINKS," +
+            "m.TSCHWEB      AS TSCHWEB," +
+            "m.TSAND        AS TSAND," +
+            "gp.GTRIEB      AS GTRIEB," +
+            "m.TGESCHIEBE   AS TGESCHIEBE," +
+            "sie.SIEB01 AS SIEB01, sie.SIEB02 AS SIEB02," +
+            "sie.SIEB03 AS SIEB03, sie.SIEB04 AS SIEB04," +
+            "sie.SIEB05 AS SIEB05, sie.SIEB06 AS SIEB06," +
+            "sie.SIEB07 AS SIEB07, sie.SIEB08 AS SIEB08," +
+            "sie.SIEB09 AS SIEB09, sie.SIEB10 AS SIEB10," +
+            "sie.SIEB11 AS SIEB11, sie.SIEB12 AS SIEB12," +
+            "sie.SIEB13 AS SIEB13, sie.SIEB14 AS SIEB14," +
+            "sie.SIEB15 AS SIEB15, sie.SIEB16 AS SIEB16," +
+            "sie.SIEB17 AS SIEB17, sie.SIEB18 AS SIEB18," +
+            "sie.SIEB19 AS SIEB19, sie.SIEB20 AS SIEB20," +
+            "sie.SIEB21 AS SIEB21," +
+            "gs.RSIEB01 AS RSIEB01, gs.RSIEB02 AS RSIEB02," +
+            "gs.RSIEB03 AS RSIEB03, gs.RSIEB04 AS RSIEB04," +
+            "gs.RSIEB05 AS RSIEB05, gs.RSIEB06 AS RSIEB06," +
+            "gs.RSIEB07 AS RSIEB07, gs.RSIEB08 AS RSIEB08," +
+            "gs.RSIEB09 AS RSIEB09, gs.RSIEB10 AS RSIEB10," +
+            "gs.RSIEB11 AS RSIEB11, gs.RSIEB12 AS RSIEB12," +
+            "gs.RSIEB13 AS RSIEB13, gs.RSIEB14 AS RSIEB14," +
+            "gs.RSIEB15 AS RSIEB15, gs.RSIEB16 AS RSIEB16," +
+            "gs.RSIEB17 AS RSIEB17, gs.RSIEB18 AS RSIEB18," +
+            "gs.RSIEB19 AS RSIEB19, gs.RSIEB20 AS RSIEB20," +
+            "gs.RSIEB21 AS RSIEB21, gs.REST    AS REST " +
         "FROM MESSUNG m " +
             "JOIN STATION    s ON m.STATIONID    = s.STATIONID " +
             "JOIN glotrechte g ON m.MESSUNGID    = g.MESSUNGID " +
@@ -107,56 +86,50 @@
                 "COALESCE(gs.RSIEB21, 0) + COALESCE(gs.REST, 0)) > 0 " +
         "ORDER BY m.DATUM, g.UFERABST, g.GLOTRECHTEID, gp.LFDNR";
 
-    public static final class MeasurementResultTransformer
-    extends                   BasicTransformerAdapter
-    {
-        public static MeasurementResultTransformer INSTANCE =
-            new MeasurementResultTransformer();
-
-        public MeasurementResultTransformer() {
-        }
-
-        private static final int index(String s) {
-            return Integer.parseInt(s.substring(s.length()-2))-1;
-        }
-
-        @Override
-        public Object transformTuple(Object [] tuple, String [] aliases) {
-            Map<String, Object> map = new HashMap<String, Object>();
+    private static final int index(String s) {
+        return Integer.parseInt(s.substring(s.length()-2))-1;
+    }
 
-            Sieve [] sieves = new Sieve[20];
-
-            List<Sieve> validSieves = new ArrayList<Sieve>(20);
+    public static final BasicTransformerAdapter FRACTIONS_TRANSFORMER =
+        new BasicTransformerAdapter() {
 
-            for (int i = 0; i < tuple.length; ++i) {
-                Object value = tuple[i];
-                if (value == null) {
-                    continue;
-                }
-                String alias = aliases[i];
-                if (alias.startsWith("SIEB")) {
-                    Sieve s = new Sieve((Double)value, 0d);
-                    sieves[index(alias)] = s;
-                }
-                else if (alias.startsWith("RSIEB")) {
-                    Sieve s = sieves[index(alias)];
-                    if (s != null) {
-                        s.setLoad((Double)value);
+            @Override
+            public Object transformTuple(Object [] tuple, String [] aliases) {
+                Map<String, Object> map = new HashMap<String, Object>();
+
+                Sieve [] sieves = new Sieve[21];
+
+                List<Sieve> validSieves = new ArrayList<Sieve>(21);
+
+                for (int i = 0; i < tuple.length; ++i) {
+                    Object value = tuple[i];
+                    if (value == null) {
+                        continue;
+                    }
+                    String alias = aliases[i];
+                    if (alias.startsWith("SIEB")) {
+                        Sieve s = new Sieve((Double)value, 0d);
+                        sieves[index(alias)] = s;
+                    }
+                    else if (alias.startsWith("RSIEB")) {
+                        Sieve s = sieves[index(alias)];
+                        if (s != null) {
+                            s.setLoad((Double)value);
+                            validSieves.add(s);
+                        }
+                    }
+                    else if (alias.equals("REST")) {
+                        Sieve s = new Sieve(0d, (Double)value);
                         validSieves.add(s);
                     }
-                }
-                else if (alias.equals("REST")) {
-                    Sieve s = new Sieve(0d, (Double)value);
-                    validSieves.add(s);
+                    else {
+                        map.put(alias, value);
+                    }
                 }
-                else {
-                    map.put(alias, value);
-                }
+
+                return new Measurement(map, validSieves);
             }
-
-            return new Measurement(map, validSieves);
-        }
-    } // class BasicTransformerAdapter
+        };
 
     private MeasurementFactory() {
     }
@@ -170,10 +143,10 @@
         boolean debug = log.isDebugEnabled();
 
         if (debug) {
-            log.debug(SQL_MEASSURE);
+            log.debug(SQL_FACTIONS);
         }
 
-        SQLQuery query = session.createSQLQuery(SQL_MEASSURE)
+        SQLQuery query = session.createSQLQuery(SQL_FACTIONS)
             .addScalar("Q_BPEGEL",     StandardBasicTypes.DOUBLE)
             .addScalar("DATUM",        StandardBasicTypes.DATE)
             .addScalar("GLOTRECHTEID", StandardBasicTypes.INTEGER)
@@ -233,7 +206,7 @@
         query.setDate("from", dateRange.getFrom());
         query.setDate("to", dateRange.getTo());
 
-        query.setResultTransformer(MeasurementResultTransformer.INSTANCE);
+        query.setResultTransformer(FRACTIONS_TRANSFORMER);
 
         @SuppressWarnings("unchecked")
         List<Measurement> measuments = (List<Measurement>)query.list();

http://dive4elements.wald.intevation.org