[Dive4elements-commits] [PATCH 03 of 10] WQKmsFactory: Add name getting function if only column id is known
Wald Commits
scm-commit at wald.intevation.org
Tue Apr 16 16:17:20 CEST 2013
# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1366108730 -7200
# Node ID 17eba7d251b22498784ec282d7d8a447da87f5c2
# Parent 0cab1c884e72114e47512e9b085a51a9a53513fc
WQKmsFactory: Add name getting function if only column id is known.
diff -r 0cab1c884e72 -r 17eba7d251b2 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQKmsFactory.java
--- 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 :
More information about the Dive4elements-commits
mailing list