Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjmisinco2014-08-21 20:25:47 +0000
committerRoberto E. Escobar2014-10-01 21:02:52 +0000
commit0c80ae5898949202d590f22630fb31a7a3ce8a1e (patch)
tree309cfbba3efd2fc385586a3e02d46d6c7b9932f9
parente17105041464a12d0554930750cab5d7622aeb59 (diff)
downloadorg.eclipse.osee-0c80ae5898949202d590f22630fb31a7a3ce8a1e.tar.gz
org.eclipse.osee-0c80ae5898949202d590f22630fb31a7a3ce8a1e.tar.xz
org.eclipse.osee-0c80ae5898949202d590f22630fb31a7a3ce8a1e.zip
refactor[ats_ATS46139]: Add DB branch and tx accessors to client
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/OSGI-INF/osee.client.caching.service.xml1
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/ClientCachingServiceProxy.java17
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/ClientBranchAccessor.java115
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/ClientTransactionAccessor.java95
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/DatabaseBranchAccessor.java208
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/DatabaseTransactionRecordAccessor.java176
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/MoveBranchDatabaseCallable.java45
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/StoreBranchDatabaseCallable.java166
8 files changed, 607 insertions, 216 deletions
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/OSGI-INF/osee.client.caching.service.xml b/plugins/org.eclipse.osee.framework.skynet.core/OSGI-INF/osee.client.caching.service.xml
index f3583772dc2..6ed0fc12605 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core/OSGI-INF/osee.client.caching.service.xml
+++ b/plugins/org.eclipse.osee.framework.skynet.core/OSGI-INF/osee.client.caching.service.xml
@@ -6,4 +6,5 @@
<provide interface="org.eclipse.osee.framework.core.services.TempCachingService"/>
</service>
<reference bind="setModelFactory" cardinality="1..1" interface="org.eclipse.osee.framework.core.services.IOseeModelFactoryService" name="IOseeModelFactoryService" policy="static"/>
+ <reference bind="setDatabaseService" cardinality="1..1" interface="org.eclipse.osee.framework.database.IOseeDatabaseService" name="IOseeDatabaseService" policy="static"/>
</scr:component>
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/ClientCachingServiceProxy.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/ClientCachingServiceProxy.java
index c7e945e2ac2..9b5865d9b6b 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/ClientCachingServiceProxy.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/ClientCachingServiceProxy.java
@@ -23,13 +23,14 @@ import org.eclipse.osee.framework.core.model.cache.RelationTypeCache;
import org.eclipse.osee.framework.core.model.cache.TransactionCache;
import org.eclipse.osee.framework.core.services.IOseeCachingService;
import org.eclipse.osee.framework.core.services.IOseeModelFactoryService;
+import org.eclipse.osee.framework.database.IOseeDatabaseService;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.skynet.core.internal.accessors.ClientArtifactTypeAccessor;
import org.eclipse.osee.framework.skynet.core.internal.accessors.ClientAttributeTypeAccessor;
-import org.eclipse.osee.framework.skynet.core.internal.accessors.ClientBranchAccessor;
import org.eclipse.osee.framework.skynet.core.internal.accessors.ClientOseeEnumTypeAccessor;
import org.eclipse.osee.framework.skynet.core.internal.accessors.ClientRelationTypeAccessor;
-import org.eclipse.osee.framework.skynet.core.internal.accessors.ClientTransactionAccessor;
+import org.eclipse.osee.framework.skynet.core.internal.accessors.DatabaseBranchAccessor;
+import org.eclipse.osee.framework.skynet.core.internal.accessors.DatabaseTransactionRecordAccessor;
/**
* @author Roberto E. Escobar
@@ -37,6 +38,7 @@ import org.eclipse.osee.framework.skynet.core.internal.accessors.ClientTransacti
public class ClientCachingServiceProxy implements IOseeCachingService {
private IOseeModelFactoryService modelFactory;
+ private IOseeDatabaseService dbService;
private IOseeCachingService proxiedService;
@@ -44,6 +46,10 @@ public class ClientCachingServiceProxy implements IOseeCachingService {
this.modelFactory = modelFactory;
}
+ public void setDatabaseService(IOseeDatabaseService dbService) {
+ this.dbService = dbService;
+ }
+
public void start() {
proxiedService = createService(modelFactory);
}
@@ -110,14 +116,13 @@ public class ClientCachingServiceProxy implements IOseeCachingService {
private IOseeCachingService createService(IOseeModelFactoryService factory) {
TransactionCache transactionCache = new TransactionCache();
- ClientBranchAccessor clientBranchAccessor =
- new ClientBranchAccessor(factory.getBranchFactory(), transactionCache);
+ DatabaseBranchAccessor clientBranchAccessor =
+ new DatabaseBranchAccessor(dbService, transactionCache, factory.getBranchFactory());
BranchCache branchCache = new BranchCache(clientBranchAccessor, transactionCache);
- clientBranchAccessor.setBranchCache(branchCache);
TransactionRecordFactory txFactory = factory.getTransactionFactory();
- transactionCache.setAccessor(new ClientTransactionAccessor(txFactory, branchCache));
+ transactionCache.setAccessor(new DatabaseTransactionRecordAccessor(dbService, branchCache, txFactory));
OseeEnumTypeCache oseeEnumTypeCache =
new OseeEnumTypeCache(new ClientOseeEnumTypeAccessor(factory.getOseeEnumTypeFactory()));
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/ClientBranchAccessor.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/ClientBranchAccessor.java
deleted file mode 100644
index fd212f3cdfa..00000000000
--- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/ClientBranchAccessor.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2007 Boeing.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Boeing - initial API and implementation
- *******************************************************************************/
-package org.eclipse.osee.framework.skynet.core.internal.accessors;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.logging.Level;
-import org.eclipse.osee.framework.core.data.OseeServerContext;
-import org.eclipse.osee.framework.core.enums.CacheOperation;
-import org.eclipse.osee.framework.core.enums.CoreTranslatorId;
-import org.eclipse.osee.framework.core.message.BranchCacheStoreRequest;
-import org.eclipse.osee.framework.core.message.BranchCacheUpdateResponse;
-import org.eclipse.osee.framework.core.message.BranchCacheUpdateUtil;
-import org.eclipse.osee.framework.core.model.AbstractOseeType;
-import org.eclipse.osee.framework.core.model.Branch;
-import org.eclipse.osee.framework.core.model.BranchFactory;
-import org.eclipse.osee.framework.core.model.cache.BranchCache;
-import org.eclipse.osee.framework.core.model.cache.IOseeCache;
-import org.eclipse.osee.framework.core.model.cache.TransactionCache;
-import org.eclipse.osee.framework.core.util.HttpProcessor.AcquireResult;
-import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
-import org.eclipse.osee.framework.logging.OseeLog;
-import org.eclipse.osee.framework.skynet.core.artifact.HttpClientMessage;
-import org.eclipse.osee.framework.skynet.core.event.OseeEventManager;
-import org.eclipse.osee.framework.skynet.core.event.model.BranchEvent;
-import org.eclipse.osee.framework.skynet.core.event.model.BranchEventType;
-import org.eclipse.osee.framework.skynet.core.internal.Activator;
-
-/**
- * @author Roberto E. Escobar
- */
-public class ClientBranchAccessor extends AbstractClientDataAccessor<Long, Branch> {
-
- private final TransactionCache transactionCache;
- private BranchCache branchCache;
- private final BranchFactory branchFactory;
-
- public ClientBranchAccessor(BranchFactory branchFactory, TransactionCache transactionCache) {
- this.branchFactory = branchFactory;
- this.transactionCache = transactionCache;
- }
-
- public void setBranchCache(BranchCache branchCache) {
- this.branchCache = branchCache;
- }
-
- private BranchFactory getFactory() {
- return branchFactory;
- }
-
- @Override
- public void load(IOseeCache<Long, Branch> cache) throws OseeCoreException {
- transactionCache.ensurePopulated();
- super.load(cache);
- }
-
- @Override
- protected Collection<Branch> updateCache(IOseeCache<Long, Branch> cache) throws OseeCoreException {
- BranchCacheUpdateResponse response = requestUpdateMessage(cache, CoreTranslatorId.BRANCH_CACHE_UPDATE_RESPONSE);
- return new BranchCacheUpdateUtil(getFactory(), branchCache).updateCache(response);
- }
-
- @Override
- public void store(Collection<Branch> types) throws OseeCoreException {
- store(branchCache, types);
- }
-
- public void store(IOseeCache<Long, Branch> cache, Collection<Branch> branches) throws OseeCoreException {
-
- Map<String, String> parameters = new HashMap<String, String>();
- parameters.put("function", CacheOperation.STORE.name());
-
- BranchCacheStoreRequest request = BranchCacheStoreRequest.fromCache(branches);
- AcquireResult updateResponse =
- HttpClientMessage.send(OseeServerContext.CACHE_CONTEXT, parameters,
- CoreTranslatorId.BRANCH_CACHE_STORE_REQUEST, request, null);
-
- if (updateResponse.wasSuccessful()) {
- sendChangeEvents(branches);
- for (Branch branch : branches) {
- branch.clearDirty();
- }
- }
- }
-
- private void sendChangeEvents(Collection<Branch> branches) {
- for (Branch branch : branches) {
- if (branch.getBranchState().isDeleted()) {
- try {
- OseeEventManager.kickBranchEvent(this, new BranchEvent(BranchEventType.Deleted, branch.getUuid()));
- } catch (Exception ex) {
- OseeLog.log(Activator.class, Level.SEVERE, ex);
- }
- }
-
- try {
- if (branch.isFieldDirty(AbstractOseeType.NAME_FIELD_KEY)) {
- OseeEventManager.kickBranchEvent(this, new BranchEvent(BranchEventType.Renamed, branch.getUuid()));
- }
- } catch (Exception ex) {
- OseeLog.log(Activator.class, Level.SEVERE, ex);
- }
- }
- }
-
-}
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/ClientTransactionAccessor.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/ClientTransactionAccessor.java
deleted file mode 100644
index b3871822ad6..00000000000
--- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/ClientTransactionAccessor.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Boeing.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Boeing - initial API and implementation
- *******************************************************************************/
-package org.eclipse.osee.framework.skynet.core.internal.accessors;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import org.eclipse.osee.framework.core.data.IOseeBranch;
-import org.eclipse.osee.framework.core.data.OseeServerContext;
-import org.eclipse.osee.framework.core.enums.CacheOperation;
-import org.eclipse.osee.framework.core.enums.CoreTranslatorId;
-import org.eclipse.osee.framework.core.enums.TransactionVersion;
-import org.eclipse.osee.framework.core.message.CacheUpdateRequest;
-import org.eclipse.osee.framework.core.message.TransactionCacheUpdateResponse;
-import org.eclipse.osee.framework.core.model.Branch;
-import org.eclipse.osee.framework.core.model.TransactionRecord;
-import org.eclipse.osee.framework.core.model.TransactionRecordFactory;
-import org.eclipse.osee.framework.core.model.cache.BranchCache;
-import org.eclipse.osee.framework.core.model.cache.ITransactionDataAccessor;
-import org.eclipse.osee.framework.core.model.cache.TransactionCache;
-import org.eclipse.osee.framework.database.core.ConnectionHandler;
-import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
-import org.eclipse.osee.framework.skynet.core.artifact.HttpClientMessage;
-
-/**
- * @author Roberto E. Escobar
- */
-public class ClientTransactionAccessor implements ITransactionDataAccessor {
-
- private static final String GET_PRIOR_TRANSACTION =
- "select transaction_id FROM osee_tx_details where branch_id = ? and transaction_id < ? order by transaction_id desc";
- private static final String TX_GET_MAX_AS_LARGEST_TX =
- "SELECT max(transaction_id) as largest_transaction_id FROM osee_tx_details WHERE branch_id = ?";
- private final TransactionRecordFactory txFactory;
- private final BranchCache branchCache;
-
- public ClientTransactionAccessor(TransactionRecordFactory txFactory, BranchCache branchCache) {
- super();
- this.txFactory = txFactory;
- this.branchCache = branchCache;
- }
-
- @Override
- public void loadTransactionRecord(TransactionCache cache, Collection<Integer> transactionIds) throws OseeCoreException {
- CacheUpdateRequest request = new CacheUpdateRequest(cache.getCacheId(), transactionIds);
- requestUpdateMessage(cache, request);
-
- }
-
- @Override
- public TransactionRecord loadTransactionRecord(TransactionCache cache, IOseeBranch branch, TransactionVersion transactionType) {
- return null;
- }
-
- @Override
- public void load(TransactionCache transactionCache) throws OseeCoreException {
- requestUpdateMessage(transactionCache, new CacheUpdateRequest(transactionCache.getCacheId()));
- }
-
- protected void requestUpdateMessage(TransactionCache cache, CacheUpdateRequest updateRequest) throws OseeCoreException {
- Map<String, String> parameters = new HashMap<String, String>();
- parameters.put("function", CacheOperation.UPDATE.name());
-
- TransactionCacheUpdateResponse response =
- HttpClientMessage.send(OseeServerContext.CACHE_CONTEXT, parameters,
- CoreTranslatorId.OSEE_CACHE_UPDATE_REQUEST, updateRequest, CoreTranslatorId.TX_CACHE_UPDATE_RESPONSE);
- for (TransactionRecord row : response.getTxRows()) {
- TransactionRecord record =
- txFactory.createOrUpdate(cache, row.getId(), row.getBranchId(), row.getComment(), row.getTimeStamp(),
- row.getAuthor(), row.getCommit(), row.getTxType(), branchCache);
- record.clearDirty();
- }
- }
-
- @Override
- public TransactionRecord getOrLoadPriorTransaction(TransactionCache cache, int transactionNumber, long branchUuid) throws OseeCoreException {
- int priorTransactionId =
- ConnectionHandler.runPreparedQueryFetchInt(transactionNumber, GET_PRIOR_TRANSACTION, branchUuid,
- transactionNumber);
- return cache.getOrLoad(priorTransactionId);
- }
-
- @Override
- public TransactionRecord getHeadTransaction(TransactionCache cache, Branch branch) throws OseeCoreException {
- return cache.getOrLoad(ConnectionHandler.runPreparedQueryFetchInt(-1, TX_GET_MAX_AS_LARGEST_TX, branch.getUuid()));
- }
-}
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/DatabaseBranchAccessor.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/DatabaseBranchAccessor.java
new file mode 100644
index 00000000000..b2b6ea418a9
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/DatabaseBranchAccessor.java
@@ -0,0 +1,208 @@
+package org.eclipse.osee.framework.skynet.core.internal.accessors;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.logging.Level;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.osee.framework.core.enums.BranchArchivedState;
+import org.eclipse.osee.framework.core.enums.BranchState;
+import org.eclipse.osee.framework.core.enums.BranchType;
+import org.eclipse.osee.framework.core.enums.StorageState;
+import org.eclipse.osee.framework.core.exception.BranchDoesNotExist;
+import org.eclipse.osee.framework.core.exception.OseeExceptions;
+import org.eclipse.osee.framework.core.model.AbstractOseeType;
+import org.eclipse.osee.framework.core.model.Branch;
+import org.eclipse.osee.framework.core.model.BranchFactory;
+import org.eclipse.osee.framework.core.model.MergeBranch;
+import org.eclipse.osee.framework.core.model.TransactionRecord;
+import org.eclipse.osee.framework.core.model.cache.BranchCache;
+import org.eclipse.osee.framework.core.model.cache.IOseeCache;
+import org.eclipse.osee.framework.core.model.cache.IOseeDataAccessor;
+import org.eclipse.osee.framework.core.model.cache.TransactionCache;
+import org.eclipse.osee.framework.database.IOseeDatabaseService;
+import org.eclipse.osee.framework.database.core.IOseeStatement;
+import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.type.OseeStateException;
+import org.eclipse.osee.framework.logging.OseeLog;
+import org.eclipse.osee.framework.skynet.core.event.OseeEventManager;
+import org.eclipse.osee.framework.skynet.core.event.model.BranchEvent;
+import org.eclipse.osee.framework.skynet.core.event.model.BranchEventType;
+import org.eclipse.osee.framework.skynet.core.internal.Activator;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class DatabaseBranchAccessor implements IOseeDataAccessor<Long, Branch> {
+ private static final int NULL_PARENT_BRANCH_ID = -1;
+
+ private static final String SELECT_BRANCHES = "SELECT * FROM osee_branch";
+ private static final String SELECT_MERGE_BRANCHES = "SELECT * FROM osee_merge";
+
+ private final IOseeDatabaseService dbService;
+
+ private final TransactionCache txCache;
+ private final BranchFactory branchFactory;
+
+ public DatabaseBranchAccessor(IOseeDatabaseService dbService, TransactionCache txCache, BranchFactory branchFactory) {
+ this.dbService = dbService;
+ this.txCache = txCache;
+ this.branchFactory = branchFactory;
+ }
+
+ private IOseeDatabaseService getDatabaseService() {
+ return dbService;
+ }
+
+ @Override
+ public void load(IOseeCache<Long, Branch> cache) throws OseeCoreException {
+ Map<Branch, Long> childToParent = new HashMap<Branch, Long>();
+ Map<Branch, Integer> branchToBaseTx = new HashMap<Branch, Integer>();
+ Map<Branch, Integer> branchToSourceTx = new HashMap<Branch, Integer>();
+ Map<Branch, Integer> associatedArtifact = new HashMap<Branch, Integer>();
+
+ BranchCache brCache = (BranchCache) cache;
+ loadBranches(brCache, childToParent, branchToBaseTx, branchToSourceTx, associatedArtifact);
+ loadBranchHierarchy(brCache, childToParent);
+ loadMergeBranches(brCache);
+ loadAssociatedArtifacts(brCache, associatedArtifact);
+ loadBranchRelatedTransactions(brCache, branchToBaseTx, branchToSourceTx);
+
+ for (Branch branch : cache.getAll()) {
+ branch.clearDirty();
+ }
+ }
+
+ private void loadBranches(BranchCache cache, Map<Branch, Long> childToParent, Map<Branch, Integer> branchToBaseTx, Map<Branch, Integer> branchToSourceTx, Map<Branch, Integer> associatedArtifact) throws OseeCoreException {
+ IOseeStatement chStmt = getDatabaseService().getStatement();
+ try {
+ chStmt.runPreparedQuery(2000, SELECT_BRANCHES);
+ while (chStmt.next()) {
+ try {
+ String branchName = chStmt.getString("branch_name");
+ BranchState branchState = BranchState.getBranchState(chStmt.getInt("branch_state"));
+ BranchType branchType = BranchType.valueOf(chStmt.getInt("branch_type"));
+ boolean isArchived = BranchArchivedState.valueOf(chStmt.getInt("archived")).isArchived();
+ long branchUuid = chStmt.getLong("branch_id");
+ int inheritAccessControl = chStmt.getInt("inherit_access_control");
+ Branch branch =
+ branchFactory.createOrUpdate(cache, branchUuid, branchName, branchType, branchState, isArchived,
+ StorageState.LOADED, inheritAccessControl == 1);
+
+ Long parentBranchId = chStmt.getLong("parent_branch_id");
+ if (parentBranchId != NULL_PARENT_BRANCH_ID) {
+ childToParent.put(branch, parentBranchId);
+ }
+ branchToSourceTx.put(branch, chStmt.getInt("parent_transaction_id"));
+ branchToBaseTx.put(branch, chStmt.getInt("baseline_transaction_id"));
+ associatedArtifact.put(branch, chStmt.getInt("associated_art_id"));
+ } catch (OseeCoreException ex) {
+ OseeLog.log(Activator.class, Level.SEVERE, "Error loading branches", ex);
+ }
+ }
+ } finally {
+ chStmt.close();
+ }
+ }
+
+ private void loadAssociatedArtifacts(BranchCache cache, Map<Branch, Integer> associatedArtifact) throws OseeCoreException {
+ for (Entry<Branch, Integer> entry : associatedArtifact.entrySet()) {
+ Branch branch = entry.getKey();
+ branch.setAssociatedArtifactId(entry.getValue());
+ }
+ }
+
+ private void loadBranchRelatedTransactions(BranchCache cache, Map<Branch, Integer> branchToBaseTx, Map<Branch, Integer> branchToSourceTx) throws OseeCoreException {
+ Set<Integer> transactionIds = new HashSet<Integer>();
+ transactionIds.addAll(branchToSourceTx.values());
+ transactionIds.addAll(branchToBaseTx.values());
+ txCache.loadTransactions(transactionIds);
+
+ for (Entry<Branch, Integer> entry : branchToBaseTx.entrySet()) {
+ Branch branch = entry.getKey();
+ if (branch.getBaseTransaction() == null) {
+ TransactionRecord baseTx = txCache.getById(entry.getValue());
+ branch.setBaseTransaction(baseTx);
+ }
+ }
+
+ for (Entry<Branch, Integer> entry : branchToSourceTx.entrySet()) {
+ Branch branch = entry.getKey();
+ if (branch.getSourceTransaction() == null) {
+ TransactionRecord srcTx = txCache.getById(entry.getValue());
+ branch.setSourceTransaction(srcTx);
+ }
+ }
+ }
+
+ private void loadBranchHierarchy(BranchCache branchCache, Map<Branch, Long> childToParent) throws OseeCoreException {
+ for (Entry<Branch, Long> entry : childToParent.entrySet()) {
+ Branch childBranch = entry.getKey();
+ Branch parentBranch = branchCache.getByUuid(entry.getValue());
+ if (parentBranch == null) {
+ throw new BranchDoesNotExist("Parent Branch uuid:[%s] does not exist for child branch [%s]",
+ entry.getValue(), entry.getKey());
+ }
+ childBranch.setParentBranch(parentBranch);
+ }
+ }
+
+ private void loadMergeBranches(BranchCache branchCache) throws OseeCoreException {
+ IOseeStatement chStmt = getDatabaseService().getStatement();
+ try {
+ chStmt.runPreparedQuery(1000, SELECT_MERGE_BRANCHES);
+ while (chStmt.next()) {
+ Branch sourceBranch = branchCache.getByUuid(chStmt.getLong("source_branch_id"));
+ Branch destBranch = branchCache.getByUuid(chStmt.getLong("dest_branch_id"));
+
+ MergeBranch mergeBranch = (MergeBranch) branchCache.getByUuid(chStmt.getLong("merge_branch_id"));
+ mergeBranch.setSourceBranch(sourceBranch);
+ mergeBranch.setDestinationBranch(destBranch);
+ }
+ } finally {
+ chStmt.close();
+ }
+
+ }
+
+ @Override
+ public void store(Collection<Branch> branches) throws OseeCoreException {
+ StoreBranchDatabaseCallable task = new StoreBranchDatabaseCallable(dbService, branches);
+ try {
+ IStatus status = task.handleTxWork();
+ if (status.isOK()) {
+ sendChangeEvents(branches);
+ for (Branch branch : branches) {
+ branch.clearDirty();
+ }
+ } else {
+ throw new OseeStateException("Error storing branches");
+ }
+ } catch (Exception ex) {
+ OseeExceptions.wrapAndThrow(ex);
+ }
+ }
+
+ private void sendChangeEvents(Collection<Branch> branches) {
+ for (Branch branch : branches) {
+ if (branch.getBranchState().isDeleted()) {
+ try {
+ OseeEventManager.kickBranchEvent(this, new BranchEvent(BranchEventType.Deleted, branch.getUuid()));
+ } catch (Exception ex) {
+ OseeLog.log(Activator.class, Level.SEVERE, ex);
+ }
+ }
+
+ try {
+ if (branch.isFieldDirty(AbstractOseeType.NAME_FIELD_KEY)) {
+ OseeEventManager.kickBranchEvent(this, new BranchEvent(BranchEventType.Renamed, branch.getUuid()));
+ }
+ } catch (Exception ex) {
+ OseeLog.log(Activator.class, Level.SEVERE, ex);
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/DatabaseTransactionRecordAccessor.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/DatabaseTransactionRecordAccessor.java
new file mode 100644
index 00000000000..d70921212c5
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/DatabaseTransactionRecordAccessor.java
@@ -0,0 +1,176 @@
+package org.eclipse.osee.framework.skynet.core.internal.accessors;
+
+import java.util.Collection;
+import java.util.Date;
+import org.eclipse.osee.framework.core.client.ClientSessionManager;
+import org.eclipse.osee.framework.core.data.IOseeBranch;
+import org.eclipse.osee.framework.core.enums.TransactionDetailsType;
+import org.eclipse.osee.framework.core.enums.TransactionVersion;
+import org.eclipse.osee.framework.core.model.Branch;
+import org.eclipse.osee.framework.core.model.TransactionRecord;
+import org.eclipse.osee.framework.core.model.TransactionRecordFactory;
+import org.eclipse.osee.framework.core.model.cache.BranchCache;
+import org.eclipse.osee.framework.core.model.cache.ITransactionDataAccessor;
+import org.eclipse.osee.framework.core.model.cache.TransactionCache;
+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.OseeSql;
+import org.eclipse.osee.framework.jdk.core.type.MutableInteger;
+import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.type.OseeStateException;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class DatabaseTransactionRecordAccessor implements ITransactionDataAccessor {
+
+ private static final String SELECT_BASE_TRANSACTION =
+ "select * from osee_tx_details where branch_id = ? and tx_type = ?";
+
+ private static final String SELECT_BY_TRANSACTION = "select * from osee_tx_details WHERE transaction_id = ?";
+
+ private static final String SELECT_HEAD_TRANSACTION =
+ "select * from osee_tx_details where transaction_id = (select max(transaction_id) from osee_tx_details where branch_id = ?) and branch_id = ?";
+
+ private static final String SELECT_TRANSACTIONS_BY_QUERY_ID =
+ "select * from osee_join_id oji, osee_tx_details txd where oji.query_id = ? and txd.transaction_id = oji.id";
+
+ private static final String SELECT_NON_EXISTING_TRANSACTIONS_BY_QUERY_ID =
+ "select oji.id from osee_join_id oji where oji.query_id = ? and not exists (select 1 from osee_tx_details txd where txd.transaction_id = oji.id)";
+
+ private static final String GET_PRIOR_TRANSACTION =
+ "select max(transaction_id) FROM osee_tx_details where branch_id = ? and transaction_id < ?";
+
+ private final IOseeDatabaseService oseeDatabaseService;
+ private final BranchCache branchCache;
+ private final TransactionRecordFactory factory;
+
+ public DatabaseTransactionRecordAccessor(IOseeDatabaseService oseeDatabaseService, BranchCache branchCache, TransactionRecordFactory factory) {
+ this.oseeDatabaseService = oseeDatabaseService;
+ this.branchCache = branchCache;
+ this.factory = factory;
+ }
+
+ private synchronized void ensureDependantCachePopulated() throws OseeCoreException {
+ branchCache.ensurePopulated();
+ }
+
+ @Override
+ public void loadTransactionRecord(TransactionCache cache, Collection<Integer> transactionIds) throws OseeCoreException {
+ if (transactionIds.isEmpty()) {
+ return;
+ }
+ ensureDependantCachePopulated();
+ if (transactionIds.size() > 1) {
+ IdJoinQuery joinQuery = JoinUtility.createIdJoinQuery();
+ try {
+ for (Integer txNumber : transactionIds) {
+ joinQuery.add(txNumber);
+ }
+ joinQuery.store();
+
+ loadTransactions(cache, transactionIds.size(), SELECT_TRANSACTIONS_BY_QUERY_ID, joinQuery.getQueryId());
+
+ } finally {
+ joinQuery.delete();
+ }
+ } else {
+ loadTransaction(cache, SELECT_BY_TRANSACTION, transactionIds.iterator().next());
+ }
+ }
+
+ @Override
+ public TransactionRecord loadTransactionRecord(TransactionCache cache, IOseeBranch branch, TransactionVersion transactionType) throws OseeCoreException {
+ ensureDependantCachePopulated();
+ TransactionRecord toReturn = null;
+ switch (transactionType) {
+ case BASE:
+ toReturn =
+ loadTransaction(cache, SELECT_BASE_TRANSACTION, branch.getUuid(), TransactionDetailsType.Baselined);
+ break;
+ case HEAD:
+ toReturn = loadTransaction(cache, SELECT_HEAD_TRANSACTION, branch.getUuid(), branch.getUuid());
+ break;
+ default:
+ throw new OseeStateException("Transaction Type [%s] is not supported", transactionType);
+ }
+ return toReturn;
+ }
+
+ private void loadTransactions(TransactionCache cache, int expectedCount, String query, int queryId) throws OseeCoreException {
+ MutableInteger numberLoaded = new MutableInteger(-1);
+ loadFromTransaction(cache, expectedCount, numberLoaded, query, queryId);
+
+ if (numberLoaded.getValue() != expectedCount) {
+ IOseeStatement chStmt = oseeDatabaseService.getStatement();
+ try {
+ chStmt.runPreparedQuery(expectedCount, SELECT_NON_EXISTING_TRANSACTIONS_BY_QUERY_ID, queryId);
+ while (chStmt.next()) {
+ int transactionNumber = chStmt.getInt("id");
+ factory.getOrCreate(cache, transactionNumber, null);
+ }
+ } finally {
+ chStmt.close();
+ }
+ }
+ }
+
+ private TransactionRecord loadTransaction(TransactionCache cache, String query, Object... parameters) throws OseeCoreException {
+ return loadFromTransaction(cache, 1, new MutableInteger(0), query, parameters);
+ }
+
+ private TransactionRecord loadFromTransaction(TransactionCache cache, int expectedCount, MutableInteger numberLoaded, String query, Object... parameters) throws OseeCoreException {
+ IOseeStatement chStmt = oseeDatabaseService.getStatement();
+ TransactionRecord record = null;
+ int count = 0;
+ try {
+ chStmt.runPreparedQuery(expectedCount, query, parameters);
+ while (chStmt.next()) {
+ count++;
+ long branchUuid = chStmt.getLong("branch_id");
+ int transactionNumber = chStmt.getInt("transaction_id");
+ String comment = chStmt.getString("osee_comment");
+ Date timestamp = chStmt.getTimestamp("time");
+ int authorArtId = chStmt.getInt("author");
+ int commitArtId = chStmt.getInt("commit_art_id");
+ TransactionDetailsType txType = TransactionDetailsType.toEnum(chStmt.getInt("tx_type"));
+
+ record =
+ prepareTransactionRecord(cache, transactionNumber, branchUuid, comment, timestamp, authorArtId,
+ commitArtId, txType);
+ }
+ numberLoaded.setValue(count);
+ } finally {
+ chStmt.close();
+ }
+ return record;
+ }
+
+ private TransactionRecord prepareTransactionRecord(TransactionCache cache, int transactionNumber, long branchUuid, String comment, Date timestamp, int authorArtId, int commitArtId, TransactionDetailsType txType) throws OseeCoreException {
+ TransactionRecord record =
+ factory.createOrUpdate(cache, transactionNumber, branchUuid, comment, timestamp, authorArtId, commitArtId,
+ txType, branchCache);
+ record.clearDirty();
+ return record;
+ }
+
+ @Override
+ public void load(TransactionCache transactionCache) throws OseeCoreException {
+ // Not implemented
+ }
+
+ @Override
+ public TransactionRecord getOrLoadPriorTransaction(TransactionCache cache, int transactionNumber, long branchUuid) throws OseeCoreException {
+ int priorTransactionId =
+ oseeDatabaseService.runPreparedQueryFetchObject(-1, GET_PRIOR_TRANSACTION, branchUuid, transactionNumber);
+ return cache.getOrLoad(priorTransactionId);
+ }
+
+ @Override
+ public TransactionRecord getHeadTransaction(TransactionCache cache, Branch branch) throws OseeCoreException {
+ return cache.getOrLoad(oseeDatabaseService.runPreparedQueryFetchObject(-1,
+ ClientSessionManager.getSql(OseeSql.TX_GET_MAX_AS_LARGEST_TX), branch.getUuid()));
+ }
+}
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/MoveBranchDatabaseCallable.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/MoveBranchDatabaseCallable.java
new file mode 100644
index 00000000000..d2aff7f1cb5
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/MoveBranchDatabaseCallable.java
@@ -0,0 +1,45 @@
+package org.eclipse.osee.framework.skynet.core.internal.accessors;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.osee.framework.core.model.Branch;
+import org.eclipse.osee.framework.database.IOseeDatabaseService;
+import org.eclipse.osee.framework.database.core.OseeConnection;
+import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
+
+/**
+ * @author Ryan D. Brooks
+ */
+public class MoveBranchDatabaseCallable {
+
+ private static final String INSERT_ADDRESSING =
+ "insert into %s (transaction_id, gamma_id, tx_current, mod_type, branch_id) select transaction_id, gamma_id, tx_current, mod_type, branch_id from %s where branch_id = ?";
+
+ public static final String DELETE_ADDRESSING = "delete from %s where branch_id = ?";
+ private final boolean archive;
+ private final Branch branch;
+ private final IOseeDatabaseService dbService;
+
+ public MoveBranchDatabaseCallable(IOseeDatabaseService databaseService, boolean archive, Branch branch) {
+ this.dbService = databaseService;
+ this.archive = archive;
+ this.branch = branch;
+ }
+
+ protected IStatus handleTxWork() throws OseeCoreException {
+ OseeConnection connection = dbService.getConnection();
+ try {
+ String sourceTableName = archive ? "osee_txs" : "osee_txs_archived";
+ String destinationTableName = archive ? "osee_txs_archived" : "osee_txs";
+
+ String sql = String.format(INSERT_ADDRESSING, destinationTableName, sourceTableName);
+ dbService.runPreparedUpdate(connection, sql, branch.getUuid());
+
+ sql = String.format(DELETE_ADDRESSING, sourceTableName);
+ dbService.runPreparedUpdate(connection, sql, branch.getUuid());
+ } finally {
+ connection.close();
+ }
+ return Status.OK_STATUS;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/StoreBranchDatabaseCallable.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/StoreBranchDatabaseCallable.java
new file mode 100644
index 00000000000..19559af95e8
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/StoreBranchDatabaseCallable.java
@@ -0,0 +1,166 @@
+package org.eclipse.osee.framework.skynet.core.internal.accessors;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.osee.framework.core.exception.OseeExceptions;
+import org.eclipse.osee.framework.core.model.AbstractOseeType;
+import org.eclipse.osee.framework.core.model.Branch;
+import org.eclipse.osee.framework.core.model.BranchField;
+import org.eclipse.osee.framework.core.model.TransactionRecord;
+import org.eclipse.osee.framework.database.IOseeDatabaseService;
+import org.eclipse.osee.framework.database.core.OseeConnection;
+import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.util.GUID;
+
+/**
+ * @author Ryan D. Brooks
+ */
+public class StoreBranchDatabaseCallable {
+ protected static final int NULL_PARENT_BRANCH_ID = -1;
+
+ private static final String INSERT_BRANCH_WITH_GUID =
+ "INSERT INTO osee_branch (branch_id, branch_guid, branch_name, parent_branch_id, parent_transaction_id, archived, associated_art_id, branch_type, branch_state, baseline_transaction_id, inherit_access_control) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
+
+ private static final String INSERT_BRANCH =
+ "INSERT INTO osee_branch (branch_id, branch_name, parent_branch_id, parent_transaction_id, archived, associated_art_id, branch_type, branch_state, baseline_transaction_id, inherit_access_control) VALUES (?,?,?,?,?,?,?,?,?,?)";
+
+ private static final String UPDATE_BRANCH =
+ "UPDATE osee_branch SET branch_name = ?, parent_branch_id = ?, parent_transaction_id = ?, archived = ?, associated_art_id = ?, branch_type = ?, branch_state = ?, baseline_transaction_id = ?, inherit_access_control = ? WHERE branch_id = ?";
+
+ private static final String DELETE_BRANCH = "DELETE FROM osee_branch WHERE branch_id = ?";
+
+ private final Collection<Branch> branches;
+ private final IOseeDatabaseService dbService;
+
+ public StoreBranchDatabaseCallable(IOseeDatabaseService dbService, Collection<Branch> branches) {
+ this.branches = branches;
+ this.dbService = dbService;
+ }
+
+ public IStatus handleTxWork() throws OseeCoreException {
+ OseeConnection connection = dbService.getConnection();
+ try {
+ List<Object[]> insertData = new ArrayList<Object[]>();
+ List<Object[]> updateData = new ArrayList<Object[]>();
+ List<Object[]> deleteData = new ArrayList<Object[]>();
+
+ boolean insertBranchGuid = false;
+
+ for (Branch branch : branches) {
+ if (isDataDirty(branch)) {
+ switch (branch.getStorageState()) {
+ case CREATED:
+ insertBranchGuid = isBranchGuidNeeded(connection);
+ insertData.add(toInsertValues(branch, insertBranchGuid));
+ break;
+ case MODIFIED:
+ updateData.add(toUpdateValues(branch));
+ break;
+ case PURGED:
+ deleteData.add(toDeleteValues(branch));
+ break;
+ default:
+ break;
+ }
+ }
+ if (branch.isFieldDirty(BranchField.BRANCH_ARCHIVED_STATE_FIELD_KEY)) {
+ MoveBranchDatabaseCallable task =
+ new MoveBranchDatabaseCallable(dbService, branch.getArchiveState().isArchived(), branch);
+ try {
+ task.handleTxWork();
+ } catch (Exception ex) {
+ OseeExceptions.wrapAndThrow(ex);
+ }
+ }
+ }
+ String insertBranch = insertBranchGuid ? INSERT_BRANCH_WITH_GUID : INSERT_BRANCH;
+ dbService.runBatchUpdate(connection, insertBranch, insertData);
+ dbService.runBatchUpdate(connection, UPDATE_BRANCH, updateData);
+ dbService.runBatchUpdate(connection, DELETE_BRANCH, deleteData);
+ } finally {
+ connection.close();
+ }
+
+ return Status.OK_STATUS;
+ }
+
+ private boolean isBranchGuidNeeded(OseeConnection connection) {
+ return dbService.runPreparedQueryFetchObject(connection, false,
+ "select osee_value from osee_info where osee_key = ?", "osee.insert.branch.guid.on.create");
+ }
+
+ private Object[] toInsertValues(Branch branch, boolean insertBranchGuid) throws OseeCoreException {
+ Branch parentBranch = branch.getParentBranch();
+ TransactionRecord baseTxRecord = branch.getBaseTransaction();
+ long parentBranchId = parentBranch != null ? parentBranch.getUuid() : NULL_PARENT_BRANCH_ID;
+ int baselineTransaction = baseTxRecord != null ? baseTxRecord.getId() : NULL_PARENT_BRANCH_ID;
+ int inheritAccessControl = branch.isInheritAccessControl() ? 1 : 0;
+
+ if (insertBranchGuid) {
+ return new Object[] {
+ branch.getUuid(),
+ GUID.create(),
+ branch.getName(),
+ parentBranchId,
+ branch.getSourceTransaction().getId(),
+ branch.getArchiveState().getValue(),
+ branch.getAssociatedArtifactId(),
+ branch.getBranchType().getValue(),
+ branch.getBranchState().getValue(),
+ baselineTransaction,
+ inheritAccessControl};
+ } else {
+ return new Object[] {
+ branch.getUuid(),
+ branch.getName(),
+ parentBranchId,
+ branch.getSourceTransaction().getId(),
+ branch.getArchiveState().getValue(),
+ branch.getAssociatedArtifactId(),
+ branch.getBranchType().getValue(),
+ branch.getBranchState().getValue(),
+ baselineTransaction,
+ inheritAccessControl};
+ }
+ }
+
+ private Object[] toUpdateValues(Branch branch) throws OseeCoreException {
+ Branch parentBranch = branch.getParentBranch();
+ TransactionRecord baseTxRecord = branch.getBaseTransaction();
+ long parentBranchId = parentBranch != null ? parentBranch.getUuid() : NULL_PARENT_BRANCH_ID;
+ int baselineTransaction = baseTxRecord != null ? baseTxRecord.getId() : NULL_PARENT_BRANCH_ID;
+ int inheritAccessControl = branch.isInheritAccessControl() ? 1 : 0;
+
+ return new Object[] {
+ branch.getName(),
+ parentBranchId,
+ branch.getSourceTransaction().getId(),
+ branch.getArchiveState().getValue(),
+ branch.getAssociatedArtifactId(),
+ branch.getBranchType().getValue(),
+ branch.getBranchState().getValue(),
+ baselineTransaction,
+ inheritAccessControl,
+ branch.getUuid()};
+ }
+
+ private Object[] toDeleteValues(Branch branch) {
+ return new Object[] {branch.getUuid()};
+ }
+
+ private boolean isDataDirty(Branch type) throws OseeCoreException {
+ return type.areFieldsDirty(//
+ AbstractOseeType.NAME_FIELD_KEY, //
+ AbstractOseeType.UNIQUE_ID_FIELD_KEY, //
+ BranchField.BRANCH_ARCHIVED_STATE_FIELD_KEY, //
+ BranchField.BRANCH_STATE_FIELD_KEY, //
+ BranchField.BRANCH_TYPE_FIELD_KEY, //
+ BranchField.BRANCH_ASSOCIATED_ARTIFACT_ID_FIELD_KEY, //
+ BranchField.BRANCH_BASE_TRANSACTION, //
+ BranchField.BRANCH_INHERIT_ACCESS_CONTROL);
+ }
+
+}

Back to the top