Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java @ 253:a2df2b48d2aa
Enabled the artifact database to handle requests specific to collection attributes and collection item attributes.
artifacts/trunk@1746 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 26 Apr 2011 07:43:40 +0000 |
parents | 6de74b0b878e |
children | 22a90706d32d |
comparison
equal
deleted
inserted
replaced
252:6de74b0b878e | 253:a2df2b48d2aa |
---|---|
165 public static final String SQL_COLLECTION_ITEMS_ID_NEXTVAL = | 165 public static final String SQL_COLLECTION_ITEMS_ID_NEXTVAL = |
166 SQL.get("collection.items.id.nextval"); | 166 SQL.get("collection.items.id.nextval"); |
167 | 167 |
168 public static final String SQL_COLLECTION_ITEMS_INSERT = | 168 public static final String SQL_COLLECTION_ITEMS_INSERT = |
169 SQL.get("collection.items.insert"); | 169 SQL.get("collection.items.insert"); |
170 | |
171 public static final String SQL_COLLECTION_GET_ATTRIBUTE = | |
172 SQL.get("collection.get.attribute"); | |
173 | |
174 public static final String SQL_COLLECTION_SET_ATTRIBUTE = | |
175 SQL.get("collection.set.attribute"); | |
170 | 176 |
171 public static final String SQL_COLLECTION_ITEM_GET_ATTRIBUTE = | 177 public static final String SQL_COLLECTION_ITEM_GET_ATTRIBUTE = |
172 SQL.get("collection.item.get.attribute"); | 178 SQL.get("collection.item.get.attribute"); |
173 | 179 |
174 public static final String SQL_COLLECTION_ITEM_SET_ATTRIBUTE = | 180 public static final String SQL_COLLECTION_ITEM_SET_ATTRIBUTE = |
1200 } | 1206 } |
1201 }; | 1207 }; |
1202 return exec.runWrite(); | 1208 return exec.runWrite(); |
1203 } | 1209 } |
1204 | 1210 |
1211 public Document getCollectionAttribute(final String collectionId) { | |
1212 if (!isValidIdentifier(collectionId)) { | |
1213 logger.debug("collection id is not valid: " + collectionId); | |
1214 } | |
1215 | |
1216 final byte[][] data = new byte[1][1]; | |
1217 | |
1218 SQLExecutor exec = new SQLExecutor() { | |
1219 public boolean doIt() throws SQLException { | |
1220 prepareStatement(SQL_COLLECTION_GET_ATTRIBUTE); | |
1221 stmnt.setString(1, collectionId); | |
1222 result = stmnt.executeQuery(); | |
1223 if (!result.next()) { | |
1224 logger.debug("No such collection."); | |
1225 return false; | |
1226 } | |
1227 | |
1228 data[0] = result.getBytes(1); | |
1229 return true; | |
1230 } | |
1231 }; | |
1232 | |
1233 return exec.runRead() | |
1234 ? XMLUtils.fromByteArray(data[0], true) | |
1235 : null; | |
1236 } | |
1237 | |
1238 public boolean setCollectionAttribute( | |
1239 final String collectionId, | |
1240 Document attribute | |
1241 ) { | |
1242 if (!isValidIdentifier(collectionId)) { | |
1243 logger.debug("collection id is not valid: " + collectionId); | |
1244 return false; | |
1245 } | |
1246 | |
1247 final byte [] data = XMLUtils.toByteArray(attribute, true); | |
1248 | |
1249 return new SQLExecutor() { | |
1250 public boolean doIt() throws SQLException { | |
1251 | |
1252 // set the column in collection items | |
1253 prepareStatement(SQL_COLLECTION_SET_ATTRIBUTE); | |
1254 if (data == null) { | |
1255 stmnt.setNull(1, Types.BINARY); | |
1256 } | |
1257 else { | |
1258 stmnt.setBytes(1, data); | |
1259 } | |
1260 stmnt.setString(2, collectionId); | |
1261 stmnt.execute(); | |
1262 reset(); | |
1263 | |
1264 // touch the collection | |
1265 prepareStatement(SQL_COLLECTIONS_TOUCH_BY_GID); | |
1266 stmnt.setString(1, collectionId); | |
1267 stmnt.execute(); | |
1268 | |
1269 conn.commit(); | |
1270 return true; | |
1271 } | |
1272 }.runWrite(); | |
1273 } | |
1274 | |
1205 public Document getCollectionItemAttribute( | 1275 public Document getCollectionItemAttribute( |
1206 final String collectionId, | 1276 final String collectionId, |
1207 final String artifactId | 1277 final String artifactId |
1208 ) { | 1278 ) { |
1209 if (!isValidIdentifier(collectionId)) { | 1279 if (!isValidIdentifier(collectionId)) { |