diff options
author | Ryan D. Brooks | 2011-05-26 18:37:52 +0000 |
---|---|---|
committer | Ryan D. Brooks | 2011-05-26 18:37:52 +0000 |
commit | dac9415b438cafc1500e05b2b00ad64b43483839 (patch) | |
tree | 33d17b609507971e14f3a5e96290909a239b326e | |
parent | 10805f9b035092acded4197fbf3a136d89c15f29 (diff) | |
download | org.eclipse.osee-dac9415b438cafc1500e05b2b00ad64b43483839.tar.gz org.eclipse.osee-dac9415b438cafc1500e05b2b00ad64b43483839.tar.xz org.eclipse.osee-dac9415b438cafc1500e05b2b00ad64b43483839.zip |
feature: Add removal of references to nonexistent gammas to PurgeUnusedBackingDataAndTransactions
-rw-r--r-- | plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/operation/PurgeUnusedBackingDataAndTransactions.java | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/operation/PurgeUnusedBackingDataAndTransactions.java b/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/operation/PurgeUnusedBackingDataAndTransactions.java index afa8f74ccda..98d8edff8e1 100644 --- a/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/operation/PurgeUnusedBackingDataAndTransactions.java +++ b/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/operation/PurgeUnusedBackingDataAndTransactions.java @@ -21,7 +21,7 @@ import org.eclipse.osee.framework.database.core.IOseeStatement; import org.eclipse.osee.framework.database.internal.Activator; /** - * Purge artifact, attribute, and relation versions that are not addressed and purge empty transactions + * Purge artifact, attribute, and relation versions that are not addressed or nonexistent and purge empty transactions * * @author Ryan D. Brooks */ @@ -30,18 +30,20 @@ public class PurgeUnusedBackingDataAndTransactions extends AbstractOperation { "select gamma_id from %s t1 where not exists (select 1 from osee_txs txs1 where t1.gamma_id = txs1.gamma_id) and not exists (select 1 from osee_txs_archived txs3 where t1.gamma_id = txs3.gamma_id)"; private static final String EMPTY_TRANSACTIONS = "select transaction_id from osee_tx_details txd where tx_type = 0 and not exists (select 1 from osee_txs txs1 where txd.transaction_id = txs1.transaction_id) and not exists (select 1 from osee_txs_archived txs3 where txd.transaction_id = txs3.transaction_id)"; + + private static final String NONEXISTENT_GAMMAS = + "SELECT gamma_id FROM osee_txs txs WHERE NOT EXISTS " + + "(SELECT 1 FROM osee_attribute att WHERE txs.gamma_id = att.gamma_id) AND NOT EXISTS " + + "(SELECT 1 FROM osee_artifact art WHERE txs.gamma_id = art.gamma_id) AND NOT EXISTS " + + "(SELECT 1 FROM osee_relation_link rel WHERE txs.gamma_id = rel.gamma_id)"; private static final String DELETE_GAMMAS = "DELETE FROM %s WHERE gamma_id = ?"; private static final String DELETE_EMPTY_TRANSACTIONS = "DELETE FROM osee_tx_details WHERE transaction_id = ?"; - private IProgressMonitor monitor; - public PurgeUnusedBackingDataAndTransactions(OperationLogger logger) { super("Data with no TXS Addressing and empty transactions", Activator.PLUGIN_ID, logger); } private void processNotAddressedGammas(String tableName) throws OseeCoreException { - checkForCancelledStatus(monitor); - List<Object[]> notAddressedGammas = new LinkedList<Object[]>(); IOseeStatement chStmt = ConnectionHandler.getStatement(); String sql = String.format(NOT_ADDRESSESED_GAMMAS, tableName); @@ -58,13 +60,26 @@ public class PurgeUnusedBackingDataAndTransactions extends AbstractOperation { sql = String.format(DELETE_GAMMAS, tableName); ConnectionHandler.runBatchUpdate(sql, notAddressedGammas); + } + + private void processAddressedButNonexistentGammas() throws OseeCoreException { + List<Object[]> nonexistentGammas = new LinkedList<Object[]>(); + IOseeStatement chStmt = ConnectionHandler.getStatement(); + + try { + chStmt.runPreparedQuery(NONEXISTENT_GAMMAS); + while (chStmt.next()) { + nonexistentGammas.add(new Object[] {chStmt.getInt("gamma_id")}); + log(String.valueOf(chStmt.getInt("gamma_id"))); + } + } finally { + chStmt.close(); + } - monitor.worked(calculateWork(0.10)); + ConnectionHandler.runBatchUpdate(String.format(DELETE_GAMMAS, "osee_txs"), nonexistentGammas); } private void processEmptyTransactions() throws OseeCoreException { - checkForCancelledStatus(monitor); - List<Object[]> emptyTransactions = new LinkedList<Object[]>(); IOseeStatement chStmt = ConnectionHandler.getStatement(); @@ -79,19 +94,14 @@ public class PurgeUnusedBackingDataAndTransactions extends AbstractOperation { } ConnectionHandler.runBatchUpdate(DELETE_EMPTY_TRANSACTIONS, emptyTransactions); - - monitor.worked(calculateWork(0.10)); } @Override protected void doWork(IProgressMonitor monitor) throws OseeCoreException { - this.monitor = monitor; - processNotAddressedGammas("osee_attribute"); processNotAddressedGammas("osee_artifact"); processNotAddressedGammas("osee_relation_link"); + processAddressedButNonexistentGammas(); processEmptyTransactions(); - - monitor.worked(calculateWork(0.20)); } }
\ No newline at end of file |