Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/StoreBranchDatabaseCallable.java')
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/StoreBranchDatabaseCallable.java195
1 files changed, 0 insertions, 195 deletions
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/StoreBranchDatabaseCallable.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/StoreBranchDatabaseCallable.java
deleted file mode 100644
index 0cbc019e969..00000000000
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/StoreBranchDatabaseCallable.java
+++ /dev/null
@@ -1,195 +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.orcs.db.internal.callable;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.concurrent.Callable;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.osee.event.EventService;
-import org.eclipse.osee.executor.admin.ExecutorAdmin;
-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;
-import org.eclipse.osee.logger.Log;
-import org.eclipse.osee.orcs.OrcsSession;
-
-/**
- * @author Ryan D. Brooks
- */
-public class StoreBranchDatabaseCallable extends AbstractDatastoreTxCallable<IStatus> {
- 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 ExecutorAdmin executorAdmin;
- private final EventService eventService;
-
- public StoreBranchDatabaseCallable(Log logger, OrcsSession session, IOseeDatabaseService dbService, ExecutorAdmin executorAdmin, EventService eventService, Collection<Branch> branches) {
- super(logger, session, dbService, "Branch Archive Operation");
- this.executorAdmin = executorAdmin;
- this.eventService = eventService;
- this.branches = branches;
- }
-
- private EventService getEventService() {
- return eventService;
- }
-
- private ExecutorAdmin getExecutorAdmin() {
- return executorAdmin;
- }
-
- @Override
- public IStatus handleTxWork(OseeConnection connection) throws OseeCoreException {
- 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)) {
- Callable<?> task =
- new MoveBranchDatabaseCallable(getLogger(), getSession(), getDatabaseService(), getEventService(),
- branch.getArchiveState().isArchived(), branch);
- try {
- getExecutorAdmin().schedule(task);
- } catch (Exception ex) {
- OseeExceptions.wrapAndThrow(ex);
- }
- }
- }
- String insertBranch = insertBranchGuid ? INSERT_BRANCH_WITH_GUID : INSERT_BRANCH;
- getDatabaseService().runBatchUpdate(connection, insertBranch, insertData);
- getDatabaseService().runBatchUpdate(connection, UPDATE_BRANCH, updateData);
- getDatabaseService().runBatchUpdate(connection, DELETE_BRANCH, deleteData);
-
- return Status.OK_STATUS;
- }
-
- private boolean isBranchGuidNeeded(OseeConnection connection) {
- return getDatabaseService().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;
-
- getLogger().debug(
- "Branch Name: [%s], Parent Branch Uuid: [%s], src trans: [%s], arch state: [%s], assoc art: [%s], branch type: [%s], branch state: [%s], baseline trans: [%s], branch uuid: [%s]",
- branch.getName(), parentBranchId, branch.getSourceTransaction().getId(), branch.getArchiveState().getValue(),
- branch.getAssociatedArtifactId(), branch.getBranchType().getValue(), branch.getBranchState().getValue(),
- baselineTransaction, branch.getUuid());
-
- 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