Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAngel Avila2013-07-17 01:06:24 +0000
committerGerrit Code Review @ Eclipse.org2013-08-21 22:38:06 +0000
commit4d034397f398b93a7336c610b18d7695600acf8f (patch)
tree76d38a2d0a54d59d9398af144810156a46fb75ca /plugins/org.eclipse.osee.orcs.db/src
parent1f8f46e03a73c8378231abafeb6b1e6d917bd95b (diff)
downloadorg.eclipse.osee-4d034397f398b93a7336c610b18d7695600acf8f.tar.gz
org.eclipse.osee-4d034397f398b93a7336c610b18d7695600acf8f.tar.xz
org.eclipse.osee-4d034397f398b93a7336c610b18d7695600acf8f.zip
refinement[ats_7ZQS7]: Update 'PurgeAttributeTypeDatabaseTxCallable'
Diffstat (limited to 'plugins/org.eclipse.osee.orcs.db/src')
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/PurgeAttributeTypeDatabaseTxCallable.java82
1 files changed, 65 insertions, 17 deletions
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/PurgeAttributeTypeDatabaseTxCallable.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/PurgeAttributeTypeDatabaseTxCallable.java
index 2df86b42d55..403acc3d579 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/PurgeAttributeTypeDatabaseTxCallable.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/PurgeAttributeTypeDatabaseTxCallable.java
@@ -12,12 +12,15 @@ package org.eclipse.osee.orcs.db.internal.callable;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.LinkedList;
import java.util.List;
import org.eclipse.osee.framework.core.data.IAttributeType;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.services.IdentityService;
import org.eclipse.osee.framework.database.IOseeDatabaseService;
import org.eclipse.osee.framework.database.core.IOseeStatement;
+import org.eclipse.osee.framework.database.core.IdJoinQuery;
+import org.eclipse.osee.framework.database.core.JoinUtility;
import org.eclipse.osee.framework.database.core.OseeConnection;
import org.eclipse.osee.logger.Log;
import org.eclipse.osee.orcs.OrcsSession;
@@ -26,10 +29,20 @@ import org.eclipse.osee.orcs.OrcsSession;
* @author Angel Avila
*/
public final class PurgeAttributeTypeDatabaseTxCallable extends AbstractDatastoreTxCallable<Void> {
- private static final String RETRIEVE_GAMMAS_OF_ATTR_TYPE_TXS =
- "SELECT gamma_id FROM osee_attribute WHERE attr_type_id = ?";
+ private static final String RETRIEVE_GAMMAS_OF_ATTR_TYPE =
+ "select gamma_id from osee_attribute where attr_type_id = ?";
- private static final String DELETE_BY_GAMMAS = "DELETE FROM %s WHERE gamma_id = ?";
+ private static final String RETRIEVE_GAMMAS_OF_ATTR_MULT_TYPES =
+ "select gamma_id from osee_attribute attr, osee_join_id jid where attr.attr_type_id = jid.id and jid.query_id = ?";
+
+ private static final String RETRIEVE_GAMMAS_WITH_BRANCH_IDS =
+ "select txs.branch_id, txs.gamma_id from osee_attribute attr, osee_txs txs where attr.attr_type_id = ? and txs.gamma_id = attr.gamma_id";
+
+ private static final String RETRIEVE_GAMMAS_WITH_BRANCH_IDS_MULT_TYPES =
+ "select txs.branch_id, txs.gamma_id from osee_attribute attr, osee_txs txs, osee_join_id jid where attr.attr_type_id = jid.id and jid.query_id = ? and txs.gamma_id = attr.gamma_id";
+
+ private static final String DELETE_BY_GAMMAS_AND_BRANCH = "DELETE FROM %s WHERE gamma_id = ? AND branch_id = ?";
+ private static final String DELETE_BY_GAMMAS = "DELETE FROM osee_attribute WHERE gamma_id = ?";
private static final String DELETE_FROM_CONFLICT_TABLE_SOURCE_SIDE =
"DELETE FROM osee_conflict WHERE source_gamma_id = ?";
private static final String DELETE_FROM_CONFLICT_TABLE_DEST_SIDE =
@@ -46,33 +59,68 @@ public final class PurgeAttributeTypeDatabaseTxCallable extends AbstractDatastor
@Override
protected Void handleTxWork(OseeConnection connection) throws OseeCoreException {
- List<Integer[]> gammaIds = retrieveGammaIds(connection, typesToPurge);
- processDeletes(connection, gammaIds);
+ List<Integer[]> gammasAndBranchIds = retrieveBranchAndGammaIds(connection, typesToPurge);
+ List<Integer[]> gammas = retrieveGammaIds(connection, typesToPurge);
+ processDeletes(connection, gammasAndBranchIds, gammas);
return null;
}
private List<Integer[]> retrieveGammaIds(OseeConnection connection, Collection<? extends IAttributeType> types) throws OseeCoreException {
- List<Integer[]> gammas = new ArrayList<Integer[]>(50000);
+ List<Integer[]> gammas = new LinkedList<Integer[]>();
IOseeStatement chStmt = getDatabaseService().getStatement(connection);
+ IdJoinQuery joinQuery = JoinUtility.createIdJoinQuery();
try {
- for (IAttributeType type : types) {
- chStmt.runPreparedQuery(RETRIEVE_GAMMAS_OF_ATTR_TYPE_TXS, identityService.getLocalId(type));
- while (chStmt.next()) {
- gammas.add(new Integer[] {chStmt.getInt("gamma_id")});
+ if (types.size() == 1) {
+ chStmt.runPreparedQuery(RETRIEVE_GAMMAS_OF_ATTR_TYPE, identityService.getLocalId(types.iterator().next()));
+ } else {
+ for (IAttributeType type : types) {
+ joinQuery.add(identityService.getLocalId(type));
}
+ joinQuery.store(connection);
+ chStmt.runPreparedQuery(RETRIEVE_GAMMAS_OF_ATTR_MULT_TYPES, joinQuery.getQueryId());
+ }
+ while (chStmt.next()) {
+ gammas.add(new Integer[] {chStmt.getInt("gamma_id")});
}
} finally {
+ joinQuery.delete(connection);
chStmt.close();
}
-
return gammas;
}
- private void processDeletes(OseeConnection connection, List<Integer[]> gammas) throws OseeCoreException {
- getDatabaseService().runBatchUpdate(connection, String.format(DELETE_BY_GAMMAS, "osee_txs"), gammas);
- getDatabaseService().runBatchUpdate(connection, String.format(DELETE_BY_GAMMAS, "osee_txs_archived"), gammas);
- getDatabaseService().runBatchUpdate(connection, String.format(DELETE_BY_GAMMAS, "osee_attribute"), gammas);
- getDatabaseService().runBatchUpdate(connection, String.format(DELETE_FROM_CONFLICT_TABLE_SOURCE_SIDE), gammas);
- getDatabaseService().runBatchUpdate(connection, String.format(DELETE_FROM_CONFLICT_TABLE_DEST_SIDE), gammas);
+ private List<Integer[]> retrieveBranchAndGammaIds(OseeConnection connection, Collection<? extends IAttributeType> types) throws OseeCoreException {
+ List<Integer[]> gammasAndBranchIds = new LinkedList<Integer[]>();
+ IOseeStatement chStmt = getDatabaseService().getStatement(connection);
+ IdJoinQuery joinQuery = JoinUtility.createIdJoinQuery();
+ try {
+ if (types.size() == 1) {
+ chStmt.runPreparedQuery(RETRIEVE_GAMMAS_WITH_BRANCH_IDS,
+ identityService.getLocalId(types.iterator().next()));
+ } else {
+ for (IAttributeType type : types) {
+ joinQuery.add(identityService.getLocalId(type));
+ }
+ chStmt.runPreparedQuery(RETRIEVE_GAMMAS_WITH_BRANCH_IDS_MULT_TYPES, joinQuery.getQueryId());
+ }
+ while (chStmt.next()) {
+ gammasAndBranchIds.add(new Integer[] {chStmt.getInt("gamma_id"), chStmt.getInt("branch_id")});
+ }
+ } finally {
+ chStmt.close();
+ }
+
+ return gammasAndBranchIds;
+ }
+
+ private void processDeletes(OseeConnection connection, List<Integer[]> gammasAndBranchIds, List<Integer[]> gammas) throws OseeCoreException {
+ getDatabaseService().runBatchUpdate(connection, String.format(DELETE_BY_GAMMAS_AND_BRANCH, "osee_txs"),
+ gammasAndBranchIds);
+ getDatabaseService().runBatchUpdate(connection, String.format(DELETE_BY_GAMMAS_AND_BRANCH, "osee_txs_archived"),
+ gammasAndBranchIds);
+
+ getDatabaseService().runBatchUpdate(connection, DELETE_BY_GAMMAS, gammas);
+ getDatabaseService().runBatchUpdate(connection, DELETE_FROM_CONFLICT_TABLE_SOURCE_SIDE, gammas);
+ getDatabaseService().runBatchUpdate(connection, DELETE_FROM_CONFLICT_TABLE_DEST_SIDE, gammas);
}
} \ No newline at end of file

Back to the top