changeset 2609:ed550e325248

Little optimization when fetching q ranges for single columns of wsts. flys-artifacts/trunk@4191 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 03 Apr 2012 14:41:31 +0000
parents 938e2f6c0c9a
children 3c907758f0ab
files flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTableFactory.java
diffstat 2 files changed, 41 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java	Tue Apr 03 13:46:16 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java	Tue Apr 03 14:41:31 2012 +0000
@@ -105,8 +105,40 @@
     public QRangeTree() {
     }
 
+    public static final class AccessQAB {
+        private int startIndex;
+
+        public AccessQAB(int startIndex) {
+            this.startIndex = startIndex;
+        }
+
+        public Double getQ(Object [] row) {
+            return (Double)row[startIndex];
+        }
+
+        public Double getA(Object [] row) {
+            return (Double)row[startIndex+1];
+        }
+
+        public Double getB(Object [] row) {
+            return (Double)row[startIndex+2];
+        }
+    }
+
+    public static final AccessQAB WITH_COLUMN    = new AccessQAB(1);
+    public static final AccessQAB WITHOUT_COLUMN = new AccessQAB(0);
+
     /** wstQRanges need to be sorted by range.a */
     public QRangeTree(List<Object []> qRanges, int start, int stop) {
+        this(qRanges, WITH_COLUMN, start, stop);
+    }
+
+    public QRangeTree(
+        List<Object []> qRanges,
+        AccessQAB       accessQAB, 
+        int             start,
+        int             stop
+    ) {
 
         if (stop <= start) {
             return;
@@ -115,9 +147,9 @@
         Node [] nodes = new Node[stop-start];
         for (int i = 0; i < nodes.length; ++i) {
             Object [] qRange = qRanges.get(start + i);
-            Double q = (Double)qRange[1];
-            Double a = (Double)qRange[2];
-            Double b = (Double)qRange[3];
+            Double q = accessQAB.getQ(qRange);
+            Double a = accessQAB.getA(qRange);
+            Double b = accessQAB.getB(qRange);
 
             nodes[i] = new Node(
                 a != null ? a.doubleValue() : -Double.MAX_VALUE,
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTableFactory.java	Tue Apr 03 13:46:16 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTableFactory.java	Tue Apr 03 14:41:31 2012 +0000
@@ -53,7 +53,7 @@
 
     /** Statement to query qranges of a single column. */
     public static final String SQL_SELECT_QS_AT_COL =
-        "SELECT column_pos, q, a, b FROM wst_q_values " +
+        "SELECT q, a, b FROM wst_q_values " +
         "WHERE wst_id = :wst_id AND column_pos = :column_pos";
 
     // (sorted by km)
@@ -369,10 +369,9 @@
         int                     column_pos
     ) {
         SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_QS_AT_COL)
-            .addScalar("column_pos", StandardBasicTypes.INTEGER) // keep to maintain order.
-            .addScalar("q",          StandardBasicTypes.DOUBLE)
-            .addScalar("a",          StandardBasicTypes.DOUBLE)
-            .addScalar("b",          StandardBasicTypes.DOUBLE);
+            .addScalar("q", StandardBasicTypes.DOUBLE)
+            .addScalar("a", StandardBasicTypes.DOUBLE)
+            .addScalar("b", StandardBasicTypes.DOUBLE);
 
         sqlQuery.setInteger("wst_id",     wst_id);
         sqlQuery.setInteger("column_pos", column_pos);
@@ -381,7 +380,8 @@
 
         int qSize = qRanges.size();
 
-        QRangeTree qRangeTree = new QRangeTree(qRanges, 0, qSize);
+        QRangeTree qRangeTree = new QRangeTree(
+            qRanges, QRangeTree.WITHOUT_COLUMN, 0, qSize);
         columns[0].setQRangeTree(qRangeTree);
     }
 

http://dive4elements.wald.intevation.org