Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WKmsFactory.java @ 1726:e3b9164a85fe
Fetch name of static WKms.
flys-artifacts/trunk@3008 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Tue, 18 Oct 2011 14:03:43 +0000 |
parents | fb4fb1c67c35 |
children | 2e5ebdeb8af9 |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WKmsFactory.java Tue Oct 18 13:28:39 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WKmsFactory.java Tue Oct 18 14:03:43 2011 +0000 @@ -27,23 +27,16 @@ { private static Logger log = Logger.getLogger(WKmsFactory.class); - /** - * Value for wsts 'kind' typically used for "additional - * longitudinal sections. - */ - public static final int KIND_ZUS = 1; - - /** - * Value for wsts 'kind' typically used for flood protection measures - * (e.g. dikes). - */ - public static final int KIND_PROTECTION = 5; - /** Query to get km and ws for wst_id and column_pos. */ public static final String SQL_SELECT_WS = "SELECT km, w FROM wst_w_values " + "WHERE wst_id = :wst_id AND column_pos = :column_pos"; + public static final String SQL_SELECT_NAME = + "SELECT name " + + "FROM wst_columns "+ + "WHERE wst_id = :wst_id AND position = :column_pos"; + private WKmsFactory() { } @@ -52,7 +45,7 @@ /** * Get WKms for given column and wst_id, caring about the cache. */ - public static WKms getWKms(int kind, int column, int wst_id) { + public static WKms getWKms(int column, int wst_id) { log.debug("WKmsFactory.getWKms"); Cache cache = CacheFactory.getCache(StaticWKmsCacheKey.CACHE_NAME); @@ -70,7 +63,7 @@ cacheKey = null; } - WKms values = getWKmsUncached(kind, column, wst_id); + WKms values = getWKmsUncached(column, wst_id); if (values != null && cacheKey != null) { log.debug("Store static wst values in cache."); @@ -83,11 +76,28 @@ /** * Get WKms from db. + * @param column the position columns value + * @param wst_id database id of the wst + * @return according WKms. */ - public static WKms getWKmsUncached(int kind, int column, int wst_id) { + public static WKms getWKmsUncached(int column, int wst_id) { log.debug("WKmsFactory.getWKmsUncached c/" + column + ", wst_id/" + wst_id); Session session = SessionHolder.HOLDER.get(); + String name = "todo"; + + SQLQuery nameQuery = session.createSQLQuery(SQL_SELECT_NAME) + .addScalar("name", StandardBasicTypes.STRING); + nameQuery.setInteger("wst_id", wst_id); + nameQuery.setInteger("column_pos", column); + + List<String> names = nameQuery.list(); + if (names.size() >= 1) { + name = names.get(0); + } + + WKmsImpl wkms = new WKmsImpl(name); + SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_WS) .addScalar("km", StandardBasicTypes.DOUBLE) .addScalar("w", StandardBasicTypes.DOUBLE); @@ -96,10 +106,6 @@ List<Object []> results = sqlQuery.list(); - // TODO Fetch name in a separate query. - String name = "todo"; - - WKmsImpl wkms = new WKmsImpl(name); double kms [] = new double[results.size()]; double ws [] = new double[results.size()];