changeset 1839:c3b44da22a3a

Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms. flys-artifacts/trunk@3175 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Mon, 07 Nov 2011 12:37:41 +0000
parents 853cd2120d69
children 54f550ba8e6a
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTableFactory.java
diffstat 2 files changed, 52 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Mon Nov 07 10:48:13 2011 +0000
+++ b/flys-artifacts/ChangeLog	Mon Nov 07 12:37:41 2011 +0000
@@ -1,3 +1,10 @@
+2011-11-07  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/WstValueTableFactory.java
+	  (loadRows, loadColumns, loadQRanges): Refactored in preparation to
+	  ability to create WstValueTables for given wst_id and
+	  column_pos (interpolation for static data).
+
 2011-11-07  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/states/LocationDistanceSelect.java,
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTableFactory.java	Mon Nov 07 10:48:13 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTableFactory.java	Mon Nov 07 12:37:41 2011 +0000
@@ -21,6 +21,10 @@
 
 import org.hibernate.type.StandardBasicTypes;
 
+/**
+ * Creates WstValueTable s from database.
+ * WstValueTable s are used to interpolate given w/q/km values.
+ */
 public class WstValueTableFactory
 {
     private static Logger log = Logger.getLogger(WstValueTableFactory.class);
@@ -51,6 +55,7 @@
         return getTable(river, DEFAULT_KIND);
     }
 
+
     public static WstValueTable getTable(River river, int kind) {
 
         Cache cache = CacheFactory.getCache(WstValueTableCacheKey.CACHE_NAME);
@@ -113,20 +118,21 @@
 
         List<Wst> wsts = query.list();
 
+        // TODO Multiple wsts can match, why return just the first one?
         return wsts.isEmpty() ? null : wsts.get(0);
     }
 
     protected static List<WstValueTable.Row> loadRows(
         Session session,
-        Wst     wst,
+        int     wst_id,
         int     numColumns
-    ) {
+    ){
         SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_WS)
             .addScalar("km",         StandardBasicTypes.DOUBLE)
             .addScalar("w",          StandardBasicTypes.DOUBLE)
             .addScalar("column_pos", StandardBasicTypes.INTEGER);
 
-        sqlQuery.setInteger("wst_id", wst.getId());
+        sqlQuery.setInteger("wst_id", wst_id);
 
         List<Object []> results = sqlQuery.list();
 
@@ -150,17 +156,30 @@
 
         rows.trimToSize();
         return rows;
+    
     }
 
+    protected static List<WstValueTable.Row> loadRows(
+        Session session,
+        Wst     wst,
+        int     numColumns
+    ) {
+        return loadRows(session, wst.getId(), numColumns);
+    }
+
+
+    /**
+     * Get columns from wst-id.
+     */
     protected static WstValueTable.Column [] loadColumns(
         Session session,
-        Wst     wst
+        int wst_id
     ) {
         SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_NAMES_POS)
             .addScalar("position",   StandardBasicTypes.INTEGER)
             .addScalar("name",       StandardBasicTypes.STRING);
 
-        sqlQuery.setInteger("wst_id", wst.getId());
+        sqlQuery.setInteger("wst_id", wst_id);
 
         List<Object []> columnNames = sqlQuery.list();
 
@@ -174,10 +193,20 @@
         return columns;
     }
 
+    /**
+     * Get columns from Wst.
+     */
+    protected static WstValueTable.Column [] loadColumns(
+        Session session,
+        Wst     wst
+    ) {
+        return loadColumns(session, wst.getId());
+    }
+
     protected static void loadQRanges(
         Session                 session,
         WstValueTable.Column [] columns,
-        Wst                     wst
+        int                     wst_id
     ) {
         SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_QS)
             .addScalar("column_pos", StandardBasicTypes.INTEGER)
@@ -185,7 +214,7 @@
             .addScalar("a",          StandardBasicTypes.DOUBLE)
             .addScalar("b",          StandardBasicTypes.DOUBLE);
 
-        sqlQuery.setInteger("wst_id", wst.getId());
+        sqlQuery.setInteger("wst_id", wst_id);
 
         List<Object []> qRanges = sqlQuery.list();
 
@@ -241,6 +270,15 @@
             }
         }
         */
+    
+    }
+
+    protected static void loadQRanges(
+        Session                 session,
+        WstValueTable.Column [] columns,
+        Wst                     wst
+    ) {
+        loadQRanges(session, columns, wst.getId());
     }
 
 }

http://dive4elements.wald.intevation.org