comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQKmsFactory.java @ 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
parents 58bdf95df5e4
children 26dcd924befc
comparison
equal deleted inserted replaced
5725:0cab1c884e72 5726:17eba7d251b2
26 26
27 /** Query to get km and wqs for wst_id and column_pos. */ 27 /** Query to get km and wqs for wst_id and column_pos. */
28 public static final String SQL_SELECT_WQS = 28 public static final String SQL_SELECT_WQS =
29 "SELECT position, w, q FROM wst_value_table " + 29 "SELECT position, w, q FROM wst_value_table " +
30 "WHERE wst_id = :wst_id AND column_pos = :column_pos"; 30 "WHERE wst_id = :wst_id AND column_pos = :column_pos";
31
32 /** Get wst_id and position from wst_columns. */
33 public static final String SQL_SELECT_COLUMN =
34 "SELECT wst_id, position FROM wst_columns WHERE id = :column_id";
31 35
32 /** Query to get name for wst_id and column_pos. */ 36 /** Query to get name for wst_id and column_pos. */
33 public static final String SQL_SELECT_NAME = 37 public static final String SQL_SELECT_NAME =
34 "SELECT name " + 38 "SELECT name " +
35 "FROM wst_columns "+ 39 "FROM wst_columns "+
104 wqkms.add((Double) row[1], (Double) row[2], (Double) row[0]); 108 wqkms.add((Double) row[1], (Double) row[2], (Double) row[0]);
105 } 109 }
106 110
107 return wqkms; 111 return wqkms;
108 } 112 }
113
114
115 /**
116 * Get WQKms from db.
117 * @param columnID the columns database id value
118 * @param wst_id database id of the wst
119 * @return respective WQKms.
120 */
121 public static int[] getColumn(int columnID) {
122
123 if (log.isDebugEnabled()) {
124 log.debug("WQKmsFactory.getColumn, columnID "
125 + columnID);
126 }
127
128 Session session = SessionHolder.HOLDER.get();
129
130 SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_COLUMN)
131 .addScalar("wst_id", StandardBasicTypes.INTEGER)
132 .addScalar("position", StandardBasicTypes.INTEGER);
133 sqlQuery.setInteger("column_id", columnID);
134
135 List<Object []> results = sqlQuery.list();
136
137 for (int i = 0, N = results.size(); i < N; i++) {
138 Object[] row = results.get(i);
139 return new int[] {(Integer)row[0], (Integer)row[1]};
140 }
141
142 return null;
143 }
144
145
146 /** Get name for a WKms. */
147 public static String getWQKmsName(int columnID) {
148 log.debug("WQKmsFactory.getWQKmsName c/" + columnID);
149
150 String name = null;
151 Session session = SessionHolder.HOLDER.get();
152
153 SQLQuery nameQuery = session.createSQLQuery(SQL_SELECT_NAME)
154 .addScalar("name", StandardBasicTypes.STRING);
155 nameQuery.setInteger("column_id", columnID);
156
157 List<String> names = nameQuery.list();
158 if (names.size() >= 1) {
159 name = names.get(0);
160 }
161
162 return name;
163 }
109 } 164 }
110 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 165 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org