# HG changeset patch # User Sascha L. Teichmann # Date 1333464091 0 # Node ID ed550e325248fdd97161803ab7b0633e8f4fb1bc # Parent 938e2f6c0c9a1ab3ff6b8ada1440a375311fdf3a Little optimization when fetching q ranges for single columns of wsts. flys-artifacts/trunk@4191 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 938e2f6c0c9a -r ed550e325248 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java --- 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 qRanges, int start, int stop) { + this(qRanges, WITH_COLUMN, start, stop); + } + + public QRangeTree( + List 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, diff -r 938e2f6c0c9a -r ed550e325248 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTableFactory.java --- 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); }