Mercurial > dive4elements > framework
diff artifact-database/src/main/java/de/intevation/artifactdatabase/DatabaseCleaner.java @ 314:31ee2b3b5a57
forward list of deleted collections and artifacts from data cleaner to backend to backend listeners.
artifacts/trunk@2445 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 02 Aug 2011 11:11:59 +0000 |
parents | f33401ea2a6c |
children | 03e508e57b85 |
line wrap: on
line diff
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/DatabaseCleaner.java Mon Aug 01 15:43:44 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/DatabaseCleaner.java Tue Aug 02 11:11:59 2011 +0000 @@ -61,6 +61,9 @@ */ Artifact reviveArtifact(String factoryName, byte [] bytes); + void killedArtifacts(List<String> identifiers); + void killedCollections(List<String> identifiers); + } // interface ArtifactReviver public interface LockedIdsProvider { @@ -205,14 +208,30 @@ return SLEEP_DEFAULT; } - private static final class IdData { + private static class IdIdentifier { int id; + String identifier; + + private IdIdentifier(int id, String identifier) { + this.id = id; + this.identifier = identifier; + } + } // class IdIdentifier + + private static final class IdData + extends IdIdentifier + { byte [] data; String factoryName; - public IdData(int id, String factoryName, byte [] data) { - this.id = id; + public IdData( + int id, + String factoryName, + byte [] data, + String identifier + ) { + super(id, identifier); this.factoryName = factoryName; this.data = data; } @@ -236,9 +255,6 @@ PreparedStatement stmnt = null; ResultSet result = null; - int removedCollections = 0; - int removedArtifacts = 0; - DataSource dataSource = dbConnection.getDataSource(); Set<Integer> lockedIds = lockedIdsProvider != null @@ -249,6 +265,9 @@ ? "-666" // XXX: A bit hackish. : StringUtils.repeat('?', lockedIds.size(), ','); + List<String> deletedCollections = new ArrayList<String>(); + List<String> deletedArtifacts = new ArrayList<String>(); + try { connection = dataSource.getConnection(); connection.setAutoCommit(false); @@ -273,10 +292,12 @@ ++idx; } - ArrayList<Integer> cs = new ArrayList<Integer>(); + ArrayList<IdIdentifier> cs = new ArrayList<IdIdentifier>(); result = stmnt.executeQuery(); while (result.next()) { - cs.add(result.getInt(1)); + cs.add(new IdIdentifier( + result.getInt(1), + result.getString(2))); } result.close(); result = null; @@ -285,8 +306,8 @@ // delete collection items stmnt = connection.prepareStatement(SQL_DELETE_COLLECTION_ITEMS); - for (Integer id: cs) { - stmnt.setInt(1, id); + for (IdIdentifier id: cs) { + stmnt.setInt(1, id.id); stmnt.execute(); } @@ -295,15 +316,16 @@ // delete collections stmnt = connection.prepareStatement(SQL_DELETE_COLLECTION); - for (Integer id: cs) { - stmnt.setInt(1, id); + for (IdIdentifier id: cs) { + stmnt.setInt(1, id.id); stmnt.execute(); + deletedCollections.add(id.identifier); } stmnt.close(); stmnt = null; connection.commit(); - removedCollections = cs.size(); cs = null; + cs = null; // remove artifacts stmnt = connection.prepareStatement(SQL_DELETE_ARTIFACT); @@ -317,7 +339,8 @@ ids.add(new IdData( result.getInt(1), result.getString(2), - result.getBytes(3))); + result.getBytes(3), + result.getString(4))); } result.close(); result = null; @@ -344,9 +367,9 @@ catch (Exception e) { logger.error(e.getLocalizedMessage(), e); } + + deletedArtifacts.add(idData.identifier); } // for all fetched data - - removedArtifacts += ids.size(); } } catch (SQLException sqle) { @@ -371,8 +394,15 @@ } } - logger.info("collections removed: " + removedCollections); - logger.info("artifacts removed: " + removedArtifacts); + reviver.killedCollections(deletedCollections); + reviver.killedArtifacts(deletedArtifacts); + + if (logger.isDebugEnabled()) { + logger.debug( + "collections removed: " + deletedCollections.size()); + logger.debug( + "artifacts removed: " + deletedArtifacts.size()); + } } /**