comparison artifact-database/src/main/java/de/intevation/artifactdatabase/DatabaseCleaner.java @ 231:1ea35226a6de

Database cleaner: Ignoring locked artifacts is now done on database level. artifacts/trunk@1635 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 31 Mar 2011 15:56:50 +0000
parents fbd57d2eeaef
children 202b6ae2fcad
comparison
equal deleted inserted replaced
230:fbd57d2eeaef 231:1ea35226a6de
219 ResultSet result = null; 219 ResultSet result = null;
220 220
221 int removedArtifacts = 0; 221 int removedArtifacts = 0;
222 222
223 DataSource dataSource = DBConnection.getDataSource(); 223 DataSource dataSource = DBConnection.getDataSource();
224
225 Set<Integer> lockedIds = lockedIdsProvider != null
226 ? lockedIdsProvider.getLockedIds()
227 : EMPTY_IDS;
228
229 String questionMarks = StringUtils.repeat('?', lockedIds.size(), ',');
230
224 try { 231 try {
225 connection = dataSource.getConnection(); 232 connection = dataSource.getConnection();
226 connection.setAutoCommit(false); 233 connection.setAutoCommit(false);
227 fetchIds = connection.prepareStatement(SQL_OUTDATED); 234
235 fetchIds = connection.prepareStatement(
236 SQL_OUTDATED.replace("$LOCKED_IDS$", questionMarks));
237
238 int idx = 1;
239 for (Integer id: lockedIds) {
240 fetchIds.setInt(idx++, id);
241 }
242
228 deleteId = connection.prepareStatement(SQL_DELETE); 243 deleteId = connection.prepareStatement(SQL_DELETE);
229 244
230 // some dbms like derby do not support LIMIT 245 // some dbms like derby do not support LIMIT
231 // in SQL statements. 246 // in SQL statements.
232 fetchIds.setMaxRows(MAX_ROWS); 247 fetchIds.setMaxRows(MAX_ROWS);
233 248
234 for (;;) { 249 for (;;) {
235 List<IdData> ids = new ArrayList<IdData>(); 250 List<IdData> ids = new ArrayList<IdData>();
236 251
237 Set<Integer> filter = lockedIdsProvider != null
238 ? lockedIdsProvider.getLockedIds()
239 : EMPTY_IDS;
240
241 result = fetchIds.executeQuery(); 252 result = fetchIds.executeQuery();
242 253
243 while (result.next()) { 254 while (result.next()) {
244 int id = result.getInt(1); 255 ids.add(new IdData(
245 if (!filter.contains(id)) { 256 result.getInt(1),
246 ids.add(new IdData( 257 result.getString(2),
247 id, 258 result.getBytes(3)));
248 result.getString(2),
249 result.getBytes(3)));
250 }
251 } 259 }
252 260
253 result.close(); result = null; 261 result.close(); result = null;
254 262
255 if (ids.isEmpty()) { 263 if (ids.isEmpty()) {

http://dive4elements.wald.intevation.org