comparison artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java @ 180:38fbbeffe8fe

Added code to remove an artifact from a collection artifacts/trunk@1406 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 06 Mar 2011 11:49:00 +0000
parents 644fd11ddd9f
children 7eebe707a034
comparison
equal deleted inserted replaced
179:644fd11ddd9f 180:38fbbeffe8fe
169 169
170 public static final String SQL_COLLECTION_ITEM_SET_ATTRIBUTE = 170 public static final String SQL_COLLECTION_ITEM_SET_ATTRIBUTE =
171 SQL.get("collection.item.set.attribute"); 171 SQL.get("collection.item.set.attribute");
172 172
173 public static final String SQL_COLLECTIONS_TOUCH_BY_GID = 173 public static final String SQL_COLLECTIONS_TOUCH_BY_GID =
174 SQL.get("collections.touch.by,gid"); 174 SQL.get("collections.touch.by.gid");
175
176 public static final String SQL_COLLECTION_ITEM_ID_CID_AID =
177 SQL.get("collection.item.id.cid.aid");
178
179 public static final String SQL_COLLECTION_ITEM_OUTDATE_ARTIFACT =
180 SQL.get("collection.item.outdate.artifact");
181
182 public static final String SQL_COLLECTION_ITEM_DELETE =
183 SQL.get("collection.item.delete");
184
185 public static final String SQL_COLLECTIONS_TOUCH_BY_ID =
186 SQL.get("collections.touch.by.id");
175 187
176 /** The singleton.*/ 188 /** The singleton.*/
177 protected static Backend instance; 189 protected static Backend instance;
178 190
179 /** 191 /**
1276 }; 1288 };
1277 return exec.runWrite(); 1289 return exec.runWrite();
1278 } 1290 }
1279 1291
1280 public boolean removeCollectionArtifact( 1292 public boolean removeCollectionArtifact(
1281 String collectionId, 1293 final String collectionId,
1282 String artifactId 1294 final String artifactId
1283 ) { 1295 ) {
1284 // TODO: Implement me! 1296 if (!isValidIdentifier(collectionId)) {
1285 return false; 1297 logger.debug("Invalid collection id: '" + collectionId + "'");
1298 return false;
1299 }
1300 return new SQLExecutor() {
1301 public boolean doIt() throws SQLException {
1302
1303 // fetch id, collection id and artitfact id
1304 prepareStatement(SQL_COLLECTION_ITEM_ID_CID_AID);
1305 stmnt.setString(1, collectionId);
1306 stmnt.setString(2, artifactId);
1307 result = stmnt.executeQuery();
1308 if (!result.next()) {
1309 logger.debug("No such collection item");
1310 return false;
1311 }
1312 int id = result.getInt(1);
1313 int cid = result.getInt(2);
1314 int aid = result.getInt(3);
1315 reset();
1316
1317 // outdate artifact iff it is only in this collection
1318 prepareStatement(SQL_COLLECTION_ITEM_OUTDATE_ARTIFACT);
1319 stmnt.setInt(1, aid);
1320 stmnt.setInt(2, cid);
1321 stmnt.execute();
1322 reset();
1323
1324 // delete collection item
1325 prepareStatement(SQL_COLLECTION_ITEM_DELETE);
1326 stmnt.setInt(1, id);
1327 stmnt.execute();
1328 reset();
1329
1330 // touch collection
1331 prepareStatement(SQL_COLLECTIONS_TOUCH_BY_ID);
1332 stmnt.setInt(1, cid);
1333 stmnt.execute();
1334
1335 conn.commit();
1336 return true;
1337 }
1338 }.runWrite();
1286 } 1339 }
1287 1340
1288 public ArtifactCollection [] listCollectionArtifacts(String collectionId) { 1341 public ArtifactCollection [] listCollectionArtifacts(String collectionId) {
1289 // TODO: Implement me! 1342 // TODO: Implement me!
1290 return null; 1343 return null;

http://dive4elements.wald.intevation.org