# HG changeset patch # User Felix Wolfsteller # Date 1386831433 -3600 # Node ID 7484132b2fbb1380f9f66eac4f683197dd7f7a0f # Parent 270946b97539dcaa225d5fa406891cff28c6a619 issue1577: Add W-Wrapping of wst-names in WKmsFactory if kind is one of a kind. diff -r 270946b97539 -r 7484132b2fbb artifacts/src/main/java/org/dive4elements/river/artifacts/StaticWKmsArtifact.java --- a/artifacts/src/main/java/org/dive4elements/river/artifacts/StaticWKmsArtifact.java Wed Dec 11 17:13:26 2013 +0100 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/StaticWKmsArtifact.java Thu Dec 12 07:57:13 2013 +0100 @@ -134,10 +134,14 @@ String wkmsName; if (col >= 0) { - wkmsName = WKmsFactory.getWKmsName(col, wst); + // The W-Wrapping could be done in here (like in + // StaticWQKmsArtifact), with benefit of i18nation, + // but slower execution (it wrappes based on kind + // which can be fetched in same sql query). + wkmsName = WKmsFactory.getWKmsNameWWrapped(col, wst); } else { - wkmsName = WKmsFactory.getWKmsName(wst); + wkmsName = WKmsFactory.getWKmsNameWWrapped(wst); } String name; diff -r 270946b97539 -r 7484132b2fbb artifacts/src/main/java/org/dive4elements/river/artifacts/model/WKmsFactory.java --- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/WKmsFactory.java Wed Dec 11 17:13:26 2013 +0100 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/WKmsFactory.java Thu Dec 12 07:57:13 2013 +0100 @@ -45,11 +45,22 @@ "FROM wst_columns "+ "WHERE wst_id = :wst_id AND position = :column_pos"; + /** Query to get name and kind for wst_id and column_pos. */ + public static final String SQL_SELECT_NAME_KIND = + "SELECT wst_columns.name, wsts.kind " + + "FROM wst_columns JOIN wsts on wst_id = wsts.id "+ + "WHERE wst_id = :wst_id AND position = :column_pos"; + /** Query to get name (description) for wst_id. */ public static final String SQL_SELECT_WST_NAME = "SELECT description from wsts "+ "WHERE id = :wst_id"; + /** Query to get name (description) and kind for wst_id. */ + public static final String SQL_SELECT_WST_NAME_KIND = + "SELECT description, kind from wsts "+ + "WHERE id = :wst_id"; + private WKmsFactory() { } @@ -86,6 +97,59 @@ return values; } + /** Get name for a WKms wrapped in W, if suitable. */ + public static String getWKmsNameWWrapped(int wst_id) { + log.debug("WKmsFactory.getWKmsNameWWrapped wst_id/" + wst_id); + + String name = null; + Session session = SessionHolder.HOLDER.get(); + + SQLQuery nameQuery = session.createSQLQuery(SQL_SELECT_WST_NAME_KIND) + .addScalar("description", StandardBasicTypes.STRING) + .addScalar("kind", StandardBasicTypes.INTEGER); + nameQuery.setInteger("wst_id", wst_id); + + List names = nameQuery.list(); + + if (names.size() >= 1) { + Object[] row = names.get(0); + name = (String) row[0]; + Integer kind = (Integer) row[1]; + if (kind == 0 || kind == 2 || kind == 3) + name = "W(" + name + ")"; + } + + return name; + } + + + /** Get name for a WKms wrapped in W, if suitable. */ + public static String getWKmsNameWWrapped(int column, int wst_id) { + log.debug("WKmsFactory.getWKmsNameWWrapped c/" + column + ", wst_id/" + wst_id); + + String name = null; + Session session = SessionHolder.HOLDER.get(); + + SQLQuery nameQuery = session.createSQLQuery(SQL_SELECT_NAME_KIND) + .addScalar("name", StandardBasicTypes.STRING) + .addScalar("kind", StandardBasicTypes.INTEGER); + nameQuery.setInteger("wst_id", wst_id); + nameQuery.setInteger("column_pos", column); + + List names = nameQuery.list(); + + if (names.size() >= 1) { + Object[] row = names.get(0); + name = (String) row[0]; + Integer kind = (Integer) row[1]; + if (kind == 0 || kind == 2 || kind == 3) + name = "W(" + name + ")"; + } + + return name; + } + + /** Get name for a WKms. */ public static String getWKmsName(int wst_id) { log.debug("WKmsFactory.getWKmsName wst_id/" + wst_id);