comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/WKmsFactory.java @ 7703:5484818087de

(issue1577, issue1494) Wrap wst name depending on Q > 0
author Andre Heinecke <aheinecke@intevation.de>
date Tue, 17 Dec 2013 17:21:37 +0100
parents 7484132b2fbb
children a97b2926de5e
comparison
equal deleted inserted replaced
7702:c6f89989de84 7703:5484818087de
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. */ 48 /** Query to get name and kind for wst_id and column_pos. */
49 public static final String SQL_SELECT_NAME_KIND = 49 public static final String SQL_SELECT_Q_NAME =
50 "SELECT wst_columns.name, wsts.kind " + 50 "SELECT wqr.q, wc.name " +
51 "FROM wst_columns JOIN wsts on wst_id = wsts.id "+ 51 "FROM wst_column_q_ranges wcqr " +
52 "WHERE wst_id = :wst_id AND position = :column_pos"; 52 "JOIN wst_q_ranges wqr ON wcqr.wst_q_range_id = wqr.id " +
53 "JOIN wst_columns wc ON wcqr.wst_column_id = wc.id " +
54 "JOIN wsts ON wc.wst_id = wsts.id " +
55 "WHERE wc.wst_id = :wst_id AND wc.position = :column_pos";
56 /*
57 Test statement:
58 SELECT wqr.q, wc.name
59 FROM wst_column_q_ranges wcqr
60 JOIN wst_q_ranges wqr ON wcqr.wst_q_range_id = wqr.id
61 JOIN wst_columns wc ON wcqr.wst_column_id = wc.id
62 JOIN wsts ON wc.wst_id = wsts.id
63 WHERE wc.wst_id = 1817 AND wc.position = 29;
64 */
65
66
53 67
54 /** Query to get name (description) for wst_id. */ 68 /** Query to get name (description) for wst_id. */
55 public static final String SQL_SELECT_WST_NAME = 69 public static final String SQL_SELECT_WST_NAME =
56 "SELECT description from wsts "+ 70 "SELECT description from wsts "+
57 "WHERE id = :wst_id"; 71 "WHERE id = :wst_id";
58 72
59 /** Query to get name (description) and kind for wst_id. */ 73 /** Query to get name (description) and kind for wst_id. */
60 public static final String SQL_SELECT_WST_NAME_KIND = 74 public static final String SQL_SELECT_WST_Q_NAME =
61 "SELECT description, kind from wsts "+ 75 "SELECT wqr.q, wc.name " +
62 "WHERE id = :wst_id"; 76 "FROM wst_column_q_ranges wcqr " +
63 77 "JOIN wst_q_ranges wqr ON wcqr.wst_q_range_id = wqr.id " +
78 "JOIN wst_columns wc ON wcqr.wst_column_id = wc.id " +
79 "JOIN wsts ON wc.wst_id = wsts.id " +
80 "WHERE wc.wst_id = :wst_id";
64 81
65 private WKmsFactory() { 82 private WKmsFactory() {
66 } 83 }
67 84
68 85
97 return values; 114 return values;
98 } 115 }
99 116
100 /** Get name for a WKms wrapped in W, if suitable. */ 117 /** Get name for a WKms wrapped in W, if suitable. */
101 public static String getWKmsNameWWrapped(int wst_id) { 118 public static String getWKmsNameWWrapped(int wst_id) {
102 log.debug("WKmsFactory.getWKmsNameWWrapped wst_id/" + wst_id); 119 return getWKmsNameWWrapped(-1, 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 } 120 }
124 121
125 122
126 /** Get name for a WKms wrapped in W, if suitable. */ 123 /** Get name for a WKms wrapped in W, if suitable. */
127 public static String getWKmsNameWWrapped(int column, int wst_id) { 124 public static String getWKmsNameWWrapped(int column, int wst_id) {
128 log.debug("WKmsFactory.getWKmsNameWWrapped c/" + column + ", wst_id/" + wst_id); 125 log.debug("WKmsFactory.getWKmsNameWWrapped c/" + column + ", wst_id/" + wst_id);
129 126
130 String name = null; 127 String name = null;
131 Session session = SessionHolder.HOLDER.get(); 128 Session session = SessionHolder.HOLDER.get();
132 129
133 SQLQuery nameQuery = session.createSQLQuery(SQL_SELECT_NAME_KIND) 130 SQLQuery nameQuery;
134 .addScalar("name", StandardBasicTypes.STRING) 131 if (column != -1) {
135 .addScalar("kind", StandardBasicTypes.INTEGER); 132 nameQuery = session.createSQLQuery(SQL_SELECT_Q_NAME);
133 nameQuery.setInteger("column_pos", column);
134 } else {
135 nameQuery = session.createSQLQuery(SQL_SELECT_WST_Q_NAME);
136 }
137
138 nameQuery.addScalar("q", StandardBasicTypes.DOUBLE)
139 .addScalar("name", StandardBasicTypes.STRING);
136 nameQuery.setInteger("wst_id", wst_id); 140 nameQuery.setInteger("wst_id", wst_id);
137 nameQuery.setInteger("column_pos", column);
138 141
139 List<Object[]> names = nameQuery.list(); 142 List<Object[]> names = nameQuery.list();
140 143
141 if (names.size() >= 1) { 144 if (names.size() >= 1) {
142 Object[] row = names.get(0); 145 Object[] row = names.get(0);
143 name = (String) row[0]; 146 Double q = (Double) row[0];
144 Integer kind = (Integer) row[1]; 147 name = (String) row[1];
145 if (kind == 0 || kind == 2 || kind == 3) 148 if (q >= 0) {
146 name = "W(" + name + ")"; 149 name = "W(" + name + ")";
147 } 150 }
151 } else {
152 // This should handle the case of Q = NULL
153 if (column != -1) {
154 name = getWKmsName(column, wst_id);
155 } else {
156 name = getWKmsName(wst_id);
157 }
158 }
159
160 log.debug("WKmsFactory.getWKmsNameWWrapped c/" + column +
161 ", wst_id/" + wst_id + " = name/ " + name);
148 162
149 return name; 163 return name;
150 } 164 }
151 165
152 166

http://dive4elements.wald.intevation.org