|
23 | 23 | import java.io.File; |
24 | 24 | import java.io.FilenameFilter; |
25 | 25 | import java.io.IOException; |
| 26 | +import java.util.ArrayList; |
26 | 27 | import java.util.List; |
27 | 28 | import java.util.Set; |
28 | 29 |
|
@@ -78,6 +79,40 @@ public void run(Logger log) |
78 | 79 | } |
79 | 80 | } |
80 | 81 |
|
| 82 | + //delete DBs linked to a genome that no longer exists |
| 83 | + sqlDB = new SQLFragment("SELECT max(d.rowId) as maxRowId, d.container, d.libraryId FROM " + BLASTSchema.NAME + "." + BLASTSchema.TABLE_DATABASES + " d GROUP BY d.libraryId, d.container HAVING count(*) > 1"); |
| 84 | + ss = new SqlSelector(BLASTSchema.getInstance().getSchema().getScope(), sqlDB); |
| 85 | + if (ss.exists()) |
| 86 | + { |
| 87 | + final List<String> objectIds = new ArrayList<>(); |
| 88 | + ss.forEach(rs -> { |
| 89 | + int libraryId = rs.getInt("libraryId"); |
| 90 | + int maxRowId = rs.getInt("maxRowId"); |
| 91 | + String container = rs.getString("container"); |
| 92 | + |
| 93 | + List<String> toDelete = new SqlSelector(BLASTSchema.getInstance().getSchema().getScope(), new SQLFragment("SELECT objectId FROM " + BLASTSchema.NAME + "." + BLASTSchema.TABLE_DATABASES + " WHERE libraryId = ? AND rowId != ? AND container = ?", libraryId, maxRowId, container)).getArrayList(String.class); |
| 94 | + objectIds.addAll(toDelete); |
| 95 | + }); |
| 96 | + |
| 97 | + try (DbScope.Transaction transaction = BLASTSchema.getInstance().getSchema().getScope().ensureTransaction()) |
| 98 | + { |
| 99 | + objectIds.forEach(objectId -> { |
| 100 | + log.info("deleting duplicate BLAST DB: " + objectId); |
| 101 | + |
| 102 | + Table.delete(BLASTSchema.getInstance().getSchema().getTable(BLASTSchema.TABLE_DATABASES), objectId); |
| 103 | + |
| 104 | + SqlExecutor ex = new SqlExecutor(BLASTSchema.getInstance().getSchema().getScope()); |
| 105 | + int deleted = ex.execute(new SQLFragment("DELETE FROM " + BLASTSchema.NAME + "." + BLASTSchema.TABLE_BLAST_JOBS + " WHERE databaseid = ? ", objectId)); |
| 106 | + if (deleted > 0) |
| 107 | + { |
| 108 | + log.info("also deleted " + deleted + " blast jobs associated with this database"); |
| 109 | + } |
| 110 | + }); |
| 111 | + |
| 112 | + transaction.commit(); |
| 113 | + } |
| 114 | + } |
| 115 | + |
81 | 116 | //delete BLAST jobs not flagged to persist |
82 | 117 | TableInfo blastJobs = BLASTSchema.getInstance().getSchema().getTable(BLASTSchema.TABLE_BLAST_JOBS); |
83 | 118 | TableSelector ts = new TableSelector(blastJobs); |
|
0 commit comments