Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjmisinco2014-08-25 20:00:48 +0000
committerRoberto E. Escobar2014-10-01 21:03:14 +0000
commit4a2589ece3b57889a7df14294cd467fa822e7e7e (patch)
treeea4ed4c78b5f305d9270c504a799e5feab74d20e
parent1d03e610cd94d09acbde46b3b4e0de0b86005b73 (diff)
downloadorg.eclipse.osee-4a2589ece3b57889a7df14294cd467fa822e7e7e.tar.gz
org.eclipse.osee-4a2589ece3b57889a7df14294cd467fa822e7e7e.tar.xz
org.eclipse.osee-4a2589ece3b57889a7df14294cd467fa822e7e7e.zip
refactor[ats_ATS46139]: Remove BranchCache from PurgeBranchCallabe
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/BranchDataStore.java3
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/OrcsBranchImpl.java4
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/branch/PurgeBranchCallable.java62
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/branch/BranchModule.java5
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/PurgeBranchDatabaseCallable.java61
5 files changed, 58 insertions, 77 deletions
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/BranchDataStore.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/BranchDataStore.java
index e2ac5026349..e01178bdf23 100644
--- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/BranchDataStore.java
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/BranchDataStore.java
@@ -24,6 +24,7 @@ import org.eclipse.osee.orcs.OrcsSession;
import org.eclipse.osee.orcs.OrcsTypes;
import org.eclipse.osee.orcs.data.ArchiveOperation;
import org.eclipse.osee.orcs.data.ArtifactReadable;
+import org.eclipse.osee.orcs.data.BranchReadable;
import org.eclipse.osee.orcs.data.CreateBranchData;
/**
@@ -35,7 +36,7 @@ public interface BranchDataStore {
Callable<Branch> createBranchCopyTx(OrcsSession session, CreateBranchData branchData);
- Callable<Branch> purgeBranch(OrcsSession session, Branch branch);
+ Callable<Void> purgeBranch(OrcsSession session, BranchReadable branch);
Callable<TransactionRecord> commitBranch(OrcsSession session, ArtifactReadable committer, Branch source, Branch destination);
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/OrcsBranchImpl.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/OrcsBranchImpl.java
index 208be46c649..eccf5a865a3 100644
--- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/OrcsBranchImpl.java
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/OrcsBranchImpl.java
@@ -51,6 +51,7 @@ public class OrcsBranchImpl implements OrcsBranch {
private final BranchDataStore branchStore;
private final BranchDataFactory branchDataFactory;
private final OrcsTypes orcsTypes;
+ private final QueryFactory queryFactory;
private final BranchCache branchCache;
private final TransactionCache txCache;
@@ -63,6 +64,7 @@ public class OrcsBranchImpl implements OrcsBranch {
this.orcsTypes = orcsTypes;
this.branchCache = branchCache;
branchDataFactory = new BranchDataFactory(branchCache);
+ this.queryFactory = queryFactory;
}
@Override
@@ -82,7 +84,7 @@ public class OrcsBranchImpl implements OrcsBranch {
@Override
public Callable<List<IOseeBranch>> purgeBranch(IOseeBranch branch, boolean recurse) {
- return new PurgeBranchCallable(logger, session, branchStore, branchCache, branch, recurse);
+ return new PurgeBranchCallable(logger, session, branchStore, branch, recurse, queryFactory);
}
@Override
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/branch/PurgeBranchCallable.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/branch/PurgeBranchCallable.java
index d07d2318a9a..7ea25e0cff9 100644
--- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/branch/PurgeBranchCallable.java
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/branch/PurgeBranchCallable.java
@@ -10,70 +10,66 @@
*******************************************************************************/
package org.eclipse.osee.orcs.core.internal.branch;
-import java.util.Collection;
-import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Callable;
import org.eclipse.osee.framework.core.data.IOseeBranch;
-import org.eclipse.osee.framework.core.model.Branch;
-import org.eclipse.osee.framework.core.model.cache.BranchCache;
-import org.eclipse.osee.framework.core.model.cache.BranchFilter;
+import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException;
+import org.eclipse.osee.framework.jdk.core.type.ResultSet;
import org.eclipse.osee.framework.jdk.core.util.Conditions;
import org.eclipse.osee.logger.Log;
import org.eclipse.osee.orcs.OrcsSession;
import org.eclipse.osee.orcs.core.ds.BranchDataStore;
-import org.eclipse.osee.orcs.core.internal.branch.provider.BranchProvider;
-import org.eclipse.osee.orcs.core.internal.branch.provider.MultiBranchProvider;
-import org.eclipse.osee.orcs.core.internal.branch.provider.SingleBranchProvider;
+import org.eclipse.osee.orcs.data.BranchReadable;
+import org.eclipse.osee.orcs.search.BranchQuery;
+import org.eclipse.osee.orcs.search.QueryFactory;
/**
* @author Roberto E. Escobar
*/
public class PurgeBranchCallable extends AbstractBranchCallable<List<IOseeBranch>> {
- private final BranchCache branchCache;
private final IOseeBranch branchToken;
private final boolean isRecursive;
+ private final QueryFactory queryFactory;
- public PurgeBranchCallable(Log logger, OrcsSession session, BranchDataStore branchStore, BranchCache branchCache, IOseeBranch branchToken, boolean isRecursive) {
+ public PurgeBranchCallable(Log logger, OrcsSession session, BranchDataStore branchStore, IOseeBranch branchToken, boolean isRecursive, QueryFactory queryFactory) {
super(logger, session, branchStore);
- this.branchCache = branchCache;
this.branchToken = branchToken;
this.isRecursive = isRecursive;
- }
-
- private BranchProvider createProvider(Branch branch, boolean isRecursive) {
- BranchProvider provider;
- if (isRecursive) {
- provider = new MultiBranchProvider(true, Collections.singleton(branch), new BranchFilter());
- } else {
- provider = new SingleBranchProvider(branch);
- }
- return provider;
+ this.queryFactory = queryFactory;
}
@Override
protected List<IOseeBranch> innerCall() throws Exception {
- Conditions.checkNotNull(branchCache, "branchCache");
Conditions.checkNotNull(branchToken, "branchToPurge");
- Branch branch = branchCache.get(branchToken);
-
- Conditions.checkNotNull(branch, "branchToPurge");
-
- BranchProvider provider = createProvider(branch, isRecursive);
+ BranchQuery branchQuery = queryFactory.branchQuery();
+ branchQuery.andIds(branchToken);
+ if (isRecursive) {
+ branchQuery.andIsChildOf(branchToken);
+ }
- Collection<Branch> branches = provider.getBranches();
- Conditions.checkNotNull(branches, "branchesToPurge");
+ ResultSet<BranchReadable> branches = branchQuery.getResults();
List<IOseeBranch> purged = new LinkedList<IOseeBranch>();
- List<Branch> orderedBranches = BranchUtil.orderByParent(branches);
- for (Branch aBranch : orderedBranches) {
+ List<BranchReadable> orderedBranches = BranchUtil.orderByParentReadable(queryFactory, branches);
+ for (BranchReadable aBranch : orderedBranches) {
checkForCancelled();
- Callable<Branch> callable = getBranchStore().purgeBranch(getSession(), aBranch);
- purged.add(callAndCheckForCancel(callable));
+ checkForChildBranches(aBranch);
+ Callable<Void> callable = getBranchStore().purgeBranch(getSession(), aBranch);
+ callAndCheckForCancel(callable);
+ purged.add(aBranch);
}
return purged;
}
+
+ private void checkForChildBranches(BranchReadable aBranch) {
+ BranchQuery branchQuery = queryFactory.branchQuery();
+ branchQuery.andIsChildOf(aBranch);
+ if (branchQuery.getCount() > 0) {
+ throw new OseeArgumentException("Unable to purge a branch containing children: branchUuid[%s] branchType[%s]",
+ aBranch.getUuid(), aBranch.getBranchType());
+ }
+ }
}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/branch/BranchModule.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/branch/BranchModule.java
index cd3e8ea8c3c..3a5d0293b42 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/branch/BranchModule.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/branch/BranchModule.java
@@ -33,6 +33,7 @@ import org.eclipse.osee.orcs.core.ds.BranchDataStore;
import org.eclipse.osee.orcs.core.ds.DataLoaderFactory;
import org.eclipse.osee.orcs.data.ArchiveOperation;
import org.eclipse.osee.orcs.data.ArtifactReadable;
+import org.eclipse.osee.orcs.data.BranchReadable;
import org.eclipse.osee.orcs.data.CreateBranchData;
import org.eclipse.osee.orcs.db.internal.IdentityLocator;
import org.eclipse.osee.orcs.db.internal.callable.AbstractDatastoreTxCallable;
@@ -102,8 +103,8 @@ public class BranchModule {
}
@Override
- public Callable<Branch> purgeBranch(OrcsSession session, Branch branch) {
- return new PurgeBranchDatabaseCallable(logger, session, dbService, cachingService.getBranchCache(), branch);
+ public Callable<Void> purgeBranch(OrcsSession session, BranchReadable toDelete) {
+ return new PurgeBranchDatabaseCallable(logger, session, dbService, toDelete);
}
@Override
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/PurgeBranchDatabaseCallable.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/PurgeBranchDatabaseCallable.java
index 6be7810028c..2e823393df9 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/PurgeBranchDatabaseCallable.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/PurgeBranchDatabaseCallable.java
@@ -11,16 +11,12 @@
package org.eclipse.osee.orcs.db.internal.callable;
-import org.eclipse.osee.framework.core.enums.BranchState;
-import org.eclipse.osee.framework.core.enums.StorageState;
-import org.eclipse.osee.framework.core.model.Branch;
-import org.eclipse.osee.framework.core.model.cache.BranchCache;
import org.eclipse.osee.framework.database.IOseeDatabaseService;
import org.eclipse.osee.framework.database.core.OseeConnection;
-import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.logger.Log;
import org.eclipse.osee.orcs.OrcsSession;
+import org.eclipse.osee.orcs.data.BranchReadable;
/**
* @author Megumi Telles
@@ -28,7 +24,7 @@ import org.eclipse.osee.orcs.OrcsSession;
* @author Robert A. Fisher
* @author Ryan D. Brooks
*/
-public class PurgeBranchDatabaseCallable extends AbstractDatastoreTxCallable<Branch> {
+public class PurgeBranchDatabaseCallable extends AbstractDatastoreTxCallable<Void> {
private static final String DELETE_FROM_BRANCH_TABLE = "DELETE FROM osee_branch WHERE branch_id = ?";
private static final String DELETE_FROM_MERGE =
"DELETE FROM osee_merge WHERE merge_branch_id = ? AND source_branch_id = ?";
@@ -37,46 +33,31 @@ public class PurgeBranchDatabaseCallable extends AbstractDatastoreTxCallable<Bra
private final String DELETE_ARTIFACT_ACL_FROM_BRANCH = "DELETE FROM OSEE_ARTIFACT_ACL WHERE branch_id =?";
private final String DELETE_BRANCH_ACL_FROM_BRANCH = "DELETE FROM OSEE_BRANCH_ACL WHERE branch_id =?";
- private final Branch branch;
- private final String sourceTableName;
- private final BranchCache branchCache;
+ private final BranchReadable toDelete;
- public PurgeBranchDatabaseCallable(Log logger, OrcsSession session, IOseeDatabaseService databaseService, BranchCache branchCache, Branch branch) {
- super(logger, session, databaseService, String.format("Purge Branch: [(%s)-%s]", branch.getUuid(),
- branch.getShortName()));
- this.branch = branch;
- this.sourceTableName = branch.getArchiveState().isArchived() ? "osee_txs_archived" : "osee_txs";
- this.branchCache = branchCache;
+ public PurgeBranchDatabaseCallable(Log logger, OrcsSession session, IOseeDatabaseService databaseService, BranchReadable toDelete) {
+ super(logger, session, databaseService, String.format("Purge Branch: [(%s)-%s]", toDelete.getUuid(),
+ toDelete.getName()));
+ this.toDelete = toDelete;
}
@Override
- protected Branch handleTxWork(OseeConnection connection) throws OseeCoreException {
- if (branch.getStorageState() != StorageState.PURGED) {
- if (!branch.getAllChildBranches(false).isEmpty()) {
- throw new OseeArgumentException(
- "Unable to purge a branch containing children: branchUuid[%s] branchType[%s]", branch.getUuid(),
- branch.getBranchType());
- }
+ protected Void handleTxWork(OseeConnection connection) throws OseeCoreException {
+ String sourceTableName = toDelete.getArchiveState().isArchived() ? "osee_txs_archived" : "osee_txs";
+ long branchUuid = toDelete.getUuid();
+ String sql = String.format("DELETE FROM %s WHERE branch_id = ?", sourceTableName);
+ purgeFromTable(connection, sql, 0.20, branchUuid);
- long branchUuid = branch.getUuid();
- String sql = String.format("DELETE FROM %s WHERE branch_id = ?", sourceTableName);
- purgeFromTable(connection, sql, 0.20, branchUuid);
-
- purgeFromTable(connection, DELETE_FROM_TX_DETAILS, 0.09, branchUuid);
- purgeFromTable(connection, DELETE_FROM_CONFLICT, 0.01, branchUuid);
- if (branch.hasParentBranch()) {
- purgeFromTable(connection, DELETE_FROM_MERGE, 0.01, branchUuid, branch.getParentBranch().getUuid());
- }
- purgeFromTable(connection, DELETE_FROM_BRANCH_TABLE, 0.01, branchUuid);
-
- purgeAccessControlTables(branchUuid);
-
- branch.setStorageState(StorageState.PURGED);
- branchCache.storeItems(branch);
- branch.setBranchState(BranchState.PURGED);
- branch.internalRemovePurgedBranchFromParent();
+ purgeFromTable(connection, DELETE_FROM_TX_DETAILS, 0.09, branchUuid);
+ purgeFromTable(connection, DELETE_FROM_CONFLICT, 0.01, branchUuid);
+ Long parentUuid = toDelete.getParentBranch();
+ if (parentUuid != null) {
+ purgeFromTable(connection, DELETE_FROM_MERGE, 0.01, branchUuid, parentUuid);
}
- return branch;
+ purgeFromTable(connection, DELETE_FROM_BRANCH_TABLE, 0.01, branchUuid);
+
+ purgeAccessControlTables(branchUuid);
+ return null;
}
private void purgeAccessControlTables(long branchUuid) throws OseeCoreException {

Back to the top