Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java @ 167:c9c27aca2f70
Added code to list collections.
artifacts/trunk@1392 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 03 Mar 2011 17:01:04 +0000 |
parents | 268c2972d4a7 |
children | ac0f8bd97277 |
comparison
equal
deleted
inserted
replaced
166:89db80380f7f | 167:c9c27aca2f70 |
---|---|
138 public static final String SQL_COLLECTIONS_NEXT_ID = | 138 public static final String SQL_COLLECTIONS_NEXT_ID = |
139 SQL.get("collections.id.nextval"); | 139 SQL.get("collections.id.nextval"); |
140 | 140 |
141 public static final String SQL_COLLECTIONS_INSERT = | 141 public static final String SQL_COLLECTIONS_INSERT = |
142 SQL.get("collections.insert"); | 142 SQL.get("collections.insert"); |
143 | |
144 public static final String SQL_COLLECTIONS_SELECT_USER = | |
145 SQL.get("collections.select.user"); | |
146 | |
147 public static final String SQL_COLLECTIONS_SELECT_ALL = | |
148 SQL.get("collections.select.all"); | |
143 | 149 |
144 /** The singleton.*/ | 150 /** The singleton.*/ |
145 protected static Backend instance; | 151 protected static Backend instance; |
146 | 152 |
147 /** | 153 /** |
1196 } | 1202 } |
1197 return null; | 1203 return null; |
1198 } | 1204 } |
1199 | 1205 |
1200 public ArtifactCollection [] listCollections( | 1206 public ArtifactCollection [] listCollections( |
1201 String userId, | 1207 String ownerIdentifier, |
1202 ArtifactCollectionFactory factory) | 1208 Document data, |
1203 { | 1209 ArtifactCollectionFactory collectionFactory, |
1204 // TODO: Implement me! | 1210 UserFactory userFactory, |
1211 Object context | |
1212 ) { | |
1213 if (ownerIdentifier != null | |
1214 && !StringUtils.checkUUID(ownerIdentifier)) { | |
1215 logger.debug("Invalid owner id: '" + ownerIdentifier + "'"); | |
1216 return null; | |
1217 } | |
1218 | |
1219 Connection conn = null; | |
1220 ResultSet result = null; | |
1221 PreparedStatement stmnt = null; | |
1222 | |
1223 DataSource dataSource = DBConnection.getDataSource(); | |
1224 try { | |
1225 ArrayList<ArtifactCollection> collections = | |
1226 new ArrayList<ArtifactCollection>(); | |
1227 conn = dataSource.getConnection(); | |
1228 | |
1229 if (ownerIdentifier != null) { | |
1230 stmnt = conn.prepareStatement(SQL_COLLECTIONS_SELECT_USER); | |
1231 stmnt.setString(1, ownerIdentifier); | |
1232 } | |
1233 else { | |
1234 stmnt = conn.prepareStatement(SQL_COLLECTIONS_SELECT_ALL); | |
1235 } | |
1236 | |
1237 result = stmnt.executeQuery(); | |
1238 | |
1239 while (result.next()) { | |
1240 String collectionIdentifier = result.getString(1); | |
1241 String collectionName = result.getString(2); | |
1242 long creationTime = result.getLong(3); | |
1243 String userIdentifier = result.getString(4); | |
1244 | |
1245 ArtifactCollection collection = | |
1246 collectionFactory.createCollection( | |
1247 collectionIdentifier, | |
1248 collectionName, | |
1249 data, | |
1250 context); | |
1251 | |
1252 if (userIdentifier != null) { | |
1253 collection.setUser(new LazyBackendUser( | |
1254 userIdentifier, userFactory, this, context)); | |
1255 } | |
1256 | |
1257 collections.add(collection); | |
1258 } | |
1259 | |
1260 return collections.toArray( | |
1261 new ArtifactCollection[collections.size()]); | |
1262 } | |
1263 catch (SQLException sqle) { | |
1264 logger.error(sqle.getLocalizedMessage(), sqle); | |
1265 } | |
1266 finally { | |
1267 if (result != null) { | |
1268 try { result.close(); } | |
1269 catch (SQLException sqle) {} | |
1270 } | |
1271 if (stmnt != null) { | |
1272 try { stmnt.close(); } | |
1273 catch (SQLException sqle) {} | |
1274 } | |
1275 if (conn != null) { | |
1276 try { conn.close(); } | |
1277 catch (SQLException sqle) {} | |
1278 } | |
1279 } | |
1205 return null; | 1280 return null; |
1206 } | 1281 } |
1207 | 1282 |
1208 public boolean deleteCollection(String collectionId) { | 1283 public boolean deleteCollection(String collectionId) { |
1209 // TODO: Implement me! | 1284 // TODO: Implement me! |