changeset 5726:17eba7d251b2

WQKmsFactory: Add name getting function if only column id is known.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 16 Apr 2013 12:38:50 +0200 (2013-04-16)
parents 0cab1c884e72
children 26dcd924befc
files flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQKmsFactory.java
diffstat 1 files changed, 55 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQKmsFactory.java	Tue Apr 16 12:36:43 2013 +0200
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQKmsFactory.java	Tue Apr 16 12:38:50 2013 +0200
@@ -29,6 +29,10 @@
         "SELECT position, w, q FROM wst_value_table " +
         "WHERE wst_id = :wst_id AND column_pos = :column_pos";
 
+    /** Get wst_id and position from wst_columns. */
+    public static final String SQL_SELECT_COLUMN =
+        "SELECT wst_id, position FROM wst_columns WHERE id = :column_id";
+
     /** Query to get name for wst_id and column_pos. */
     public static final String SQL_SELECT_NAME =
         "SELECT name " +
@@ -106,5 +110,56 @@
 
         return wqkms;
     }
+
+
+    /**
+     * Get WQKms from db.
+     * @param columnID the columns database id value
+     * @param wst_id database id of the wst
+     * @return respective WQKms.
+     */
+    public static int[] getColumn(int columnID) {
+
+        if (log.isDebugEnabled()) {
+            log.debug("WQKmsFactory.getColumn, columnID "
+                + columnID);
+        }
+
+        Session session = SessionHolder.HOLDER.get();
+
+        SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_COLUMN)
+            .addScalar("wst_id",  StandardBasicTypes.INTEGER)
+            .addScalar("position", StandardBasicTypes.INTEGER);
+        sqlQuery.setInteger("column_id", columnID);
+
+        List<Object []> results = sqlQuery.list();
+
+        for (int i = 0, N = results.size(); i < N; i++) {
+            Object[] row = results.get(i);
+            return new int[] {(Integer)row[0], (Integer)row[1]};
+        }
+
+        return null;
+    }
+
+
+    /** Get name for a WKms. */
+    public static String getWQKmsName(int columnID) {
+        log.debug("WQKmsFactory.getWQKmsName c/" + columnID);
+
+        String name = null;
+        Session session = SessionHolder.HOLDER.get();
+
+        SQLQuery nameQuery = session.createSQLQuery(SQL_SELECT_NAME)
+            .addScalar("name", StandardBasicTypes.STRING);
+        nameQuery.setInteger("column_id", columnID);
+
+        List<String> names = nameQuery.list();
+        if (names.size() >= 1) {
+            name = names.get(0);
+        }
+
+        return name;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org