comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/WKmsFactory.java @ 7686:7484132b2fbb

issue1577: Add W-Wrapping of wst-names in WKmsFactory if kind is one of a kind.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 12 Dec 2013 07:57:13 +0100
parents af13ceeba52a
children 5484818087de
comparison
equal deleted inserted replaced
7685:270946b97539 7686:7484132b2fbb
43 public static final String SQL_SELECT_NAME = 43 public static final String SQL_SELECT_NAME =
44 "SELECT name " + 44 "SELECT name " +
45 "FROM wst_columns "+ 45 "FROM wst_columns "+
46 "WHERE wst_id = :wst_id AND position = :column_pos"; 46 "WHERE wst_id = :wst_id AND position = :column_pos";
47 47
48 /** Query to get name and kind for wst_id and column_pos. */
49 public static final String SQL_SELECT_NAME_KIND =
50 "SELECT wst_columns.name, wsts.kind " +
51 "FROM wst_columns JOIN wsts on wst_id = wsts.id "+
52 "WHERE wst_id = :wst_id AND position = :column_pos";
53
48 /** Query to get name (description) for wst_id. */ 54 /** Query to get name (description) for wst_id. */
49 public static final String SQL_SELECT_WST_NAME = 55 public static final String SQL_SELECT_WST_NAME =
50 "SELECT description from wsts "+ 56 "SELECT description from wsts "+
57 "WHERE id = :wst_id";
58
59 /** Query to get name (description) and kind for wst_id. */
60 public static final String SQL_SELECT_WST_NAME_KIND =
61 "SELECT description, kind from wsts "+
51 "WHERE id = :wst_id"; 62 "WHERE id = :wst_id";
52 63
53 64
54 private WKmsFactory() { 65 private WKmsFactory() {
55 } 66 }
84 cache.put(element); 95 cache.put(element);
85 } 96 }
86 return values; 97 return values;
87 } 98 }
88 99
100 /** Get name for a WKms wrapped in W, if suitable. */
101 public static String getWKmsNameWWrapped(int wst_id) {
102 log.debug("WKmsFactory.getWKmsNameWWrapped wst_id/" + wst_id);
103
104 String name = null;
105 Session session = SessionHolder.HOLDER.get();
106
107 SQLQuery nameQuery = session.createSQLQuery(SQL_SELECT_WST_NAME_KIND)
108 .addScalar("description", StandardBasicTypes.STRING)
109 .addScalar("kind", StandardBasicTypes.INTEGER);
110 nameQuery.setInteger("wst_id", wst_id);
111
112 List<Object[]> names = nameQuery.list();
113
114 if (names.size() >= 1) {
115 Object[] row = names.get(0);
116 name = (String) row[0];
117 Integer kind = (Integer) row[1];
118 if (kind == 0 || kind == 2 || kind == 3)
119 name = "W(" + name + ")";
120 }
121
122 return name;
123 }
124
125
126 /** Get name for a WKms wrapped in W, if suitable. */
127 public static String getWKmsNameWWrapped(int column, int wst_id) {
128 log.debug("WKmsFactory.getWKmsNameWWrapped c/" + column + ", wst_id/" + wst_id);
129
130 String name = null;
131 Session session = SessionHolder.HOLDER.get();
132
133 SQLQuery nameQuery = session.createSQLQuery(SQL_SELECT_NAME_KIND)
134 .addScalar("name", StandardBasicTypes.STRING)
135 .addScalar("kind", StandardBasicTypes.INTEGER);
136 nameQuery.setInteger("wst_id", wst_id);
137 nameQuery.setInteger("column_pos", column);
138
139 List<Object[]> names = nameQuery.list();
140
141 if (names.size() >= 1) {
142 Object[] row = names.get(0);
143 name = (String) row[0];
144 Integer kind = (Integer) row[1];
145 if (kind == 0 || kind == 2 || kind == 3)
146 name = "W(" + name + ")";
147 }
148
149 return name;
150 }
151
152
89 /** Get name for a WKms. */ 153 /** Get name for a WKms. */
90 public static String getWKmsName(int wst_id) { 154 public static String getWKmsName(int wst_id) {
91 log.debug("WKmsFactory.getWKmsName wst_id/" + wst_id); 155 log.debug("WKmsFactory.getWKmsName wst_id/" + wst_id);
92 156
93 String name = null; 157 String name = null;

http://dive4elements.wald.intevation.org