comparison artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java @ 175:16e6e661e6bf

Added code to delete collections. artifacts/trunk@1401 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 04 Mar 2011 17:11:40 +0000
parents 25d472a67a9f
children a0eff2227588
comparison
equal deleted inserted replaced
174:25d472a67a9f 175:16e6e661e6bf
143 public static final String SQL_COLLECTIONS_SELECT_ALL = 143 public static final String SQL_COLLECTIONS_SELECT_ALL =
144 SQL.get("collections.select.all"); 144 SQL.get("collections.select.all");
145 145
146 public static final String SQL_COLLECTIONS_CREATION_TIME = 146 public static final String SQL_COLLECTIONS_CREATION_TIME =
147 SQL.get("collection.creation.time"); 147 SQL.get("collection.creation.time");
148
149 public static final String SQL_COLLECTIONS_ID_BY_GID =
150 SQL.get("collection.creation.time");
151
152 public static final String SQL_DELETE_COLLECTION_ITEMS =
153 SQL.get("delete.collection.items");
154
155 public static final String SQL_DELETE_COLLECTION =
156 SQL.get("delete.collection");
148 157
149 /** The singleton.*/ 158 /** The singleton.*/
150 protected static Backend instance; 159 protected static Backend instance;
151 160
152 /** 161 /**
1042 ? collections.toArray(new ArtifactCollection[collections.size()]) 1051 ? collections.toArray(new ArtifactCollection[collections.size()])
1043 : null; 1052 : null;
1044 } 1053 }
1045 1054
1046 1055
1047 public boolean deleteCollection(String collectionId) { 1056 public boolean deleteCollection(final String collectionId) {
1048 // TODO: Implement me! 1057 if (!StringUtils.checkUUID(collectionId)) {
1049 return false; 1058 logger.debug("Invalid collection id: '" + collectionId + "'");
1059 return false;
1060 }
1061 SQLExecutor exec = new SQLExecutor() {
1062 public boolean doIt() throws SQLException {
1063 // fetch collection id
1064 prepareStatement(SQL_COLLECTIONS_ID_BY_GID);
1065 stmnt.setString(1, collectionId);
1066 result = stmnt.executeQuery();
1067 if (!result.next()) {
1068 logger.debug("No such collection: " + collectionId);
1069 return false;
1070 }
1071 int id = result.getInt(1);
1072 reset();
1073
1074 // outdate artifacts that are only in this collection
1075 prepareStatement(SQL_OUTDATE_ARTIFACTS_COLLECTION);
1076 stmnt.setInt(1, id);
1077 stmnt.setInt(2, id);
1078 stmnt.execute();
1079 reset();
1080
1081 // delete the collection items
1082 prepareStatement(SQL_DELETE_COLLECTION_ITEMS);
1083 stmnt.setInt(1, id);
1084 stmnt.execute();
1085 reset();
1086
1087 // delete the collection
1088 prepareStatement(SQL_DELETE_COLLECTION);
1089 stmnt.setInt(1, id);
1090 stmnt.execute();
1091 conn.commit();
1092 return true;
1093 }
1094 };
1095 return exec.runWrite();
1050 } 1096 }
1051 1097
1052 public Document getCollectionAttribute( 1098 public Document getCollectionAttribute(
1053 String collectionId, 1099 String collectionId,
1054 String artifactId 1100 String artifactId

http://dive4elements.wald.intevation.org