diff options
author | Shawn F. Cook | 2011-08-02 20:05:40 +0000 |
---|---|---|
committer | Ryan D. Brooks | 2011-08-02 20:05:40 +0000 |
commit | dad30d551e147defe4d124ec94b7c6aa704b08cf (patch) | |
tree | df00bdb845c0acdda98346d6650f1b25c749ad25 /plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework | |
parent | a75fa5b6a515a19ae050b72a1d53ce1abc8b40c8 (diff) | |
download | org.eclipse.osee-dad30d551e147defe4d124ec94b7c6aa704b08cf.tar.gz org.eclipse.osee-dad30d551e147defe4d124ec94b7c6aa704b08cf.tar.xz org.eclipse.osee-dad30d551e147defe4d124ec94b7c6aa704b08cf.zip |
refinement[bgz_350331]: Migrate PurgeTransactionBlam to server side command line
Diffstat (limited to 'plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework')
10 files changed, 71 insertions, 350 deletions
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/BranchManager.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/BranchManager.java index 7a289432ee0..621207676e5 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/BranchManager.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/BranchManager.java @@ -65,6 +65,7 @@ import org.eclipse.osee.framework.skynet.core.httpRequests.UpdateBranchStateHttp import org.eclipse.osee.framework.skynet.core.httpRequests.UpdateBranchTypeHttpRequestOperation; import org.eclipse.osee.framework.skynet.core.internal.Activator; import org.eclipse.osee.framework.skynet.core.transaction.TransactionManager; +import org.eclipse.osee.framework.skynet.core.utility.PurgeTransactionOperationWithListener; /** * Provides access to all branches as well as support for creating branches of all types @@ -319,8 +320,9 @@ public class BranchManager { * Permanently removes transactions and any of their backing data that is not referenced by any other transactions. */ public static Job purgeTransactions(IJobChangeListener jobChangeListener, boolean force, final int... transactionIdNumbers) { - IOperation op = - new PurgeTransactionOperation(Activator.getInstance().getOseeDatabaseService(), force, transactionIdNumbers); + final IOperation op = + PurgeTransactionOperationWithListener.getPurgeTransactionOperation(force, transactionIdNumbers); + return Operations.executeAsJob(op, true, Job.LONG, jobChangeListener); } diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/PurgeTransactionOperation.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/PurgeTransactionOperation.java deleted file mode 100644 index 8a48e2022d3..00000000000 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/PurgeTransactionOperation.java +++ /dev/null @@ -1,286 +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.artifact; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.logging.Level; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.osee.framework.core.enums.ModificationType; -import org.eclipse.osee.framework.core.enums.TxChange; -import org.eclipse.osee.framework.core.exception.OseeArgumentException; -import org.eclipse.osee.framework.core.exception.OseeCoreException; -import org.eclipse.osee.framework.core.exception.TransactionDoesNotExist; -import org.eclipse.osee.framework.core.model.TransactionRecord; -import org.eclipse.osee.framework.core.util.Conditions; -import org.eclipse.osee.framework.database.IOseeDatabaseService; -import org.eclipse.osee.framework.database.core.AbstractDbTxOperation; -import org.eclipse.osee.framework.database.core.ConnectionHandler; -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.framework.database.core.TransactionJoinQuery; -import org.eclipse.osee.framework.logging.OseeLog; -import org.eclipse.osee.framework.skynet.core.event.OseeEventManager; -import org.eclipse.osee.framework.skynet.core.event.PurgeTransactionEventUtil; -import org.eclipse.osee.framework.skynet.core.event.model.TransactionEvent; -import org.eclipse.osee.framework.skynet.core.internal.Activator; -import org.eclipse.osee.framework.skynet.core.transaction.TransactionManager; - -/** - * @author Ryan D. Brooks - */ -public class PurgeTransactionOperation extends AbstractDbTxOperation { - - private static final String UPDATE_TXS_DETAILS_COMMENT = - "UPDATE osee_tx_details SET osee_comment = replace(osee_comment, ?, ?) WHERE osee_comment like ?"; - - private static final String SELECT_GAMMAS_FROM_TRANSACTION = - "SELECT DISTINCT txs1.gamma_id FROM osee_txs txs1, osee_join_transaction txj1 WHERE txs1.transaction_id = txj1.transaction_id AND txj1.query_id = ? AND NOT EXISTS (SELECT 'x' FROM osee_txs txs2 WHERE txs1.gamma_id = txs2.gamma_id AND txs1.transaction_id <> txs2.transaction_id)"; - - private final static String DELETE_TXS = "delete from osee_txs where transaction_id = ?"; - private static final String DELETE_TX_DETAILS = "delete from osee_tx_details where transaction_id = ?"; - - private final static String DELETE_ARTIFACT_VERSIONS = "delete from osee_artifact items where items.gamma_id = ?"; - private final static String DELETE_ATTRIBUTES = "delete from osee_attribute items where items.gamma_id = ?"; - private final static String DELETE_RELATIONS = "delete from osee_relation_link items where items.gamma_id = ?"; - - private final static String TRANSACATION_GAMMA_IN_USE = - "SELECT txs2.transaction_id FROM osee_txs txs1, osee_txs txs2, osee_join_transaction jn where txs1.transaction_id = jn.transaction_id AND txs1.gamma_id = txs2.gamma_id and txs2.transaction_id != txs1.transaction_id AND jn.query_id = ?"; - - private final static String SELECT_AFFECTED_ITEMS = - "SELECT %s as item_id, txs.branch_id from osee_join_transaction ojt, osee_txs txs, %s item where ojt.query_id = ? AND ojt.transaction_id = txs.transaction_id AND txs.gamma_id = item.gamma_id"; - - private final static String FIND_NEW_TX_CURRENTS = - "SELECT oj.id as item_id, txs.mod_type, txs.gamma_id, txs.transaction_id from osee_join_id oj, %s item, osee_txs txs where oj.query_id = ? and oj.id = item.%s and item.gamma_id = txs.gamma_id and txs.branch_id = ? order by oj.id desc, txs.transaction_id desc"; - - private static final String UPDATE_TX_CURRENT = - "update osee_txs set tx_current = ? where transaction_id = ? and gamma_id = ?"; - - private final int[] txIdsToDelete; - private final boolean force; - private boolean success; - private TransactionEvent transactionEvent; - - public PurgeTransactionOperation(IOseeDatabaseService databaseService, boolean force, int... txIdsToDelete) { - super(databaseService, String.format("Delete transactions: %s", Arrays.toString(txIdsToDelete)), - Activator.PLUGIN_ID); - this.txIdsToDelete = txIdsToDelete; - this.force = force; - this.success = false; - } - - @Override - protected void doTxWork(IProgressMonitor monitor, OseeConnection connection) throws OseeCoreException { - Conditions.checkNotNull(txIdsToDelete, "transaction ids to delete"); - Conditions.checkExpressionFailOnTrue(txIdsToDelete.length <= 0, "transaction ids to delete cannot be empty"); - - Arrays.sort(txIdsToDelete); - - TransactionJoinQuery txsToDeleteQuery = JoinUtility.createTransactionJoinQuery(); - - Map<TransactionRecord, TransactionRecord> deleteToPreviousTx = - findPriorTransactions(monitor, txsToDeleteQuery, 0.20); - - transactionEvent = PurgeTransactionEventUtil.createPurgeTransactionEvent(deleteToPreviousTx.keySet()); - - txsToDeleteQuery.store(connection); - - int txQueryId = txsToDeleteQuery.getQueryId(); - - try { - checkForModifiedBaselines(connection, force, txQueryId); - - Map<Integer, IdJoinQuery> arts = findAffectedItems(connection, "art_id", "osee_artifact", txQueryId); - Map<Integer, IdJoinQuery> attrs = findAffectedItems(connection, "attr_id", "osee_attribute", txQueryId); - Map<Integer, IdJoinQuery> rels = findAffectedItems(connection, "rel_link_id", "osee_relation_link", txQueryId); - monitor.worked(calculateWork(0.20)); - - setChildBranchBaselineTxs(connection, monitor, deleteToPreviousTx, 0.20); - deleteItemEntriesForTransactions(connection, monitor, txQueryId, 0.20); - - monitor.subTask("Remove Tx Rows"); - List<Object[]> txsToDelete = new ArrayList<Object[]>(); - for (int txId : txIdsToDelete) { - txsToDelete.add(new Object[] {txId}); - } - ConnectionHandler.runBatchUpdate(connection, DELETE_TX_DETAILS, txsToDelete); - ConnectionHandler.runBatchUpdate(connection, DELETE_TXS, txsToDelete); - - monitor.subTask("Updating Previous Tx to Current"); - List<Object[]> txsUpdate = new ArrayList<Object[]>(); - computeNewTxCurrents(connection, txsUpdate, "art_id", "osee_artifact", arts); - computeNewTxCurrents(connection, txsUpdate, "attr_id", "osee_attribute", attrs); - computeNewTxCurrents(connection, txsUpdate, "rel_link_id", "osee_relation_link", rels); - - ConnectionHandler.runBatchUpdate(connection, UPDATE_TX_CURRENT, txsUpdate); - monitor.worked(calculateWork(0.20)); - success = true; - } finally { - clearJoin(connection, txsToDeleteQuery); - } - } - - @Override - protected void handleTxFinally(IProgressMonitor monitor) throws OseeCoreException { - if (success) { - OseeEventManager.kickTransactionEvent(this, transactionEvent); - } - } - - private void computeNewTxCurrents(OseeConnection connection, Collection<Object[]> txsUpdate, String itemId, String tableName, Map<Integer, IdJoinQuery> affected) throws OseeCoreException { - String query = String.format(FIND_NEW_TX_CURRENTS, tableName, itemId); - - for (Entry<Integer, IdJoinQuery> entry : affected.entrySet()) { - Integer branchId = entry.getKey(); - IdJoinQuery joinQuery = entry.getValue(); - - IOseeStatement statement = ConnectionHandler.getStatement(connection); - try { - statement.runPreparedQuery(query, joinQuery.getQueryId(), branchId); - int previousItem = -1; - while (statement.next()) { - int currentItem = statement.getInt("item_id"); - - if (previousItem != currentItem) { - ModificationType modType = ModificationType.getMod(statement.getInt("mod_type")); - TxChange txCurrent = TxChange.getCurrent(modType); - txsUpdate.add(new Object[] { - txCurrent.getValue(), - statement.getInt("transaction_id"), - statement.getLong("gamma_id")}); - previousItem = currentItem; - } - } - } finally { - statement.close(); - } - joinQuery.delete(connection); - } - } - - private void clearJoin(OseeConnection connection, TransactionJoinQuery txsToDeleteQuery) { - try { - if (connection != null && !connection.isClosed()) { - txsToDeleteQuery.delete(connection); - } - } catch (OseeCoreException ex) { - OseeLog.log(Activator.class, Level.SEVERE, ex.toString(), ex); - } - } - - private Map<Integer, IdJoinQuery> findAffectedItems(OseeConnection connection, String itemId, String itemTable, int txQueryId) throws OseeCoreException { - Map<Integer, IdJoinQuery> items = new HashMap<Integer, IdJoinQuery>(); - - String query = String.format(SELECT_AFFECTED_ITEMS, itemId, itemTable); - IOseeStatement statement = ConnectionHandler.getStatement(connection); - try { - statement.runPreparedQuery(query, txQueryId); - while (statement.next()) { - Integer branchId = statement.getInt("branch_id"); - IdJoinQuery joinId = items.get(branchId); - if (joinId == null) { - joinId = JoinUtility.createIdJoinQuery(); - items.put(branchId, joinId); - } - Integer id = statement.getInt("item_id"); - joinId.add(id); - } - } finally { - statement.close(); - } - - for (IdJoinQuery join : items.values()) { - join.store(); - } - return items; - } - - private Map<TransactionRecord, TransactionRecord> findPriorTransactions(IProgressMonitor monitor, TransactionJoinQuery txsToDeleteQuery, double workPercentage) throws OseeCoreException { - Map<TransactionRecord, TransactionRecord> deleteToPreviousTx = - new HashMap<TransactionRecord, TransactionRecord>(); - double workStep = workPercentage / txIdsToDelete.length; - for (int index = 0; index < txIdsToDelete.length; index++) { - monitor.subTask(String.format("Fetching Previous Tx Info: [%d of %d]", index + 1, txIdsToDelete.length)); - int fromTx = txIdsToDelete[index]; - TransactionRecord fromTransaction = TransactionManager.getTransactionId(fromTx); - TransactionRecord previousTransaction; - try { - previousTransaction = TransactionManager.getPriorTransaction(fromTransaction); - } catch (TransactionDoesNotExist ex) { - throw new OseeArgumentException( - "You are trying to delete Transaction [%d] which is a baseline transaction. If your intent is to delete the Branch use the delete Branch Operation. \n\nNO TRANSACTIONS WERE DELETED.", - fromTx); - } - deleteToPreviousTx.put(fromTransaction, previousTransaction); - - // Store transaction id(s) to delete - no need for gammas - txsToDeleteQuery.add(-1L, fromTx); - monitor.worked(calculateWork(workStep)); - } - return deleteToPreviousTx; - } - - private void deleteItemEntriesForTransactions(OseeConnection connection, IProgressMonitor monitor, int txsToDeleteQueryId, double workPercentage) throws OseeCoreException { - monitor.subTask("Deleting Tx Items"); - List<Object[]> data = new ArrayList<Object[]>(); - IOseeStatement chStmt = ConnectionHandler.getStatement(connection); - try { - chStmt.runPreparedQuery(SELECT_GAMMAS_FROM_TRANSACTION, txsToDeleteQueryId); - while (chStmt.next()) { - data.add(new Object[] {chStmt.getLong("gamma_id")}); - } - } finally { - chStmt.close(); - } - ConnectionHandler.runBatchUpdate(connection, DELETE_ARTIFACT_VERSIONS, data); - ConnectionHandler.runBatchUpdate(connection, DELETE_ATTRIBUTES, data); - ConnectionHandler.runBatchUpdate(connection, DELETE_RELATIONS, data); - monitor.worked(calculateWork(workPercentage)); - } - - private void setChildBranchBaselineTxs(OseeConnection connection, IProgressMonitor monitor, Map<TransactionRecord, TransactionRecord> deleteToPreviousTx, double workPercentage) throws OseeCoreException { - List<Object[]> data = new ArrayList<Object[]>(); - monitor.subTask("Update Baseline Txs for Child Branches"); - for (Entry<TransactionRecord, TransactionRecord> entry : deleteToPreviousTx.entrySet()) { - TransactionRecord previousTransaction = entry.getValue(); - if (previousTransaction != null) { - int toDeleteTransaction = entry.getKey().getId(); - - data.add(new Object[] { - String.valueOf(toDeleteTransaction), - String.valueOf(previousTransaction.getId()), - "%" + toDeleteTransaction}); - } - } - if (!data.isEmpty()) { - ConnectionHandler.runBatchUpdate(connection, UPDATE_TXS_DETAILS_COMMENT, data); - } - monitor.worked(calculateWork(workPercentage)); - } - - private void checkForModifiedBaselines(OseeConnection connection, boolean force, int queryId) throws OseeCoreException { - int transaction_id = - ConnectionHandler.runPreparedQueryFetchInt(connection, 0, TRANSACATION_GAMMA_IN_USE, queryId); - if (transaction_id > 0 && !force) { - throw new OseeCoreException( - "The Transaction %d holds a Gamma that is in use in other transactions. In order to delete this Transaction you will need to select the force check box.\n\nNO TRANSACTIONS WERE DELETED.", - transaction_id); - } - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/event/FrameworkEventUtil.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/event/FrameworkEventUtil.java index 6e97e88965a..5c64fa01535 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/event/FrameworkEventUtil.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/event/FrameworkEventUtil.java @@ -153,7 +153,7 @@ public class FrameworkEventUtil { RemoteTransactionEvent1 event = new RemoteTransactionEvent1(); event.setNetworkSender(getRemoteNetworkSender(transEvent.getNetworkSender())); event.setEventTypeGuid(transEvent.getEventType().getGuid()); - for (TransactionChange change : transEvent.getTransactions()) { + for (TransactionChange change : transEvent.getTransactionChanges()) { RemoteTransactionChange1 remChange = new RemoteTransactionChange1(); remChange.setBranchGuid(change.getBranchGuid()); remChange.setTransactionId(change.getTransactionId()); @@ -178,7 +178,7 @@ public class FrameworkEventUtil { for (RemoteBasicGuidArtifact1 remGuidArt : remChange.getArtifacts()) { eventArts.add(getBasicGuidArtifact(remGuidArt)); } - event.getTransactions().add(change); + event.addTransactionChange(change); } return event; } diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/event/PurgeTransactionEventUtil.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/event/PurgeTransactionEventUtil.java index a95753248b9..d2f064f7573 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/event/PurgeTransactionEventUtil.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/event/PurgeTransactionEventUtil.java @@ -10,29 +10,21 @@ *******************************************************************************/ package org.eclipse.osee.framework.skynet.core.event; -import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; -import java.util.List; import java.util.Set; import java.util.logging.Level; import org.eclipse.osee.framework.core.exception.OseeCoreException; -import org.eclipse.osee.framework.core.model.Branch; import org.eclipse.osee.framework.core.model.TransactionRecord; import org.eclipse.osee.framework.core.model.event.DefaultBasicGuidArtifact; -import org.eclipse.osee.framework.core.operation.IOperation; -import org.eclipse.osee.framework.core.operation.Operations; import org.eclipse.osee.framework.logging.OseeLog; import org.eclipse.osee.framework.skynet.core.artifact.Artifact; import org.eclipse.osee.framework.skynet.core.artifact.ArtifactCache; -import org.eclipse.osee.framework.skynet.core.artifact.BranchManager; import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery; -import org.eclipse.osee.framework.skynet.core.change.Change; import org.eclipse.osee.framework.skynet.core.event.model.TransactionChange; import org.eclipse.osee.framework.skynet.core.event.model.TransactionEvent; import org.eclipse.osee.framework.skynet.core.event.model.TransactionEventType; import org.eclipse.osee.framework.skynet.core.internal.Activator; -import org.eclipse.osee.framework.skynet.core.revision.ChangeManager; import org.eclipse.osee.framework.skynet.core.transaction.TransactionManager; /** @@ -47,30 +39,7 @@ public final class PurgeTransactionEventUtil { public static TransactionEvent createPurgeTransactionEvent(Collection<TransactionRecord> purgedTransactions) { TransactionEvent transactionEvent = new TransactionEvent(); transactionEvent.setEventType(TransactionEventType.Purged); - List<TransactionChange> txChanges = transactionEvent.getTransactions(); - for (TransactionRecord txRecord : purgedTransactions) { - try { - Branch branch = BranchManager.getBranch(txRecord.getBranchId()); - - TransactionChange transChange = new TransactionChange(); - transChange.setTransactionId(txRecord.getId()); - transChange.setBranchGuid(branch.getGuid()); - - Collection<Change> changes = new ArrayList<Change>(); - IOperation operation = ChangeManager.comparedToPreviousTx(txRecord, changes); - Operations.executeWorkAndCheckStatus(operation); - - Collection<DefaultBasicGuidArtifact> eventArts = transChange.getArtifacts(); - for (Change change : changes) { - Artifact art = change.getChangeArtifact(); - eventArts.add(art.getBasicGuidArtifact()); - } - txChanges.add(transChange); - } catch (Exception ex) { - OseeLog.log(Activator.class, Level.SEVERE, ex); - } - } return transactionEvent; } @@ -78,7 +47,7 @@ public final class PurgeTransactionEventUtil { if (transEvent.getEventType() == TransactionEventType.Purged) { Set<Artifact> artifactsInCache = new HashSet<Artifact>(); - for (TransactionChange transChange : transEvent.getTransactions()) { + for (TransactionChange transChange : transEvent.getTransactionChanges()) { try { TransactionManager.deCache(transChange.getTransactionId()); } catch (OseeCoreException ex1) { diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/event/model/TransactionEvent.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/event/model/TransactionEvent.java index 007dfbbec27..ff89defb633 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/event/model/TransactionEvent.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/event/model/TransactionEvent.java @@ -36,8 +36,12 @@ public class TransactionEvent extends FrameworkEvent { * <p> * Objects of the following type(s) are allowed in the list {@link DefaultBasicGuidArtifact } */ - public List<TransactionChange> getTransactions() { - return this.transactions; + public List<TransactionChange> getTransactionChanges() { + return transactions; + } + + public void addTransactionChange(TransactionChange txChange) { + transactions.add(txChange); } /** 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 index c86fa049e54..ce0159f5275 100644 --- 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 @@ -26,6 +26,7 @@ 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.skynet.core.artifact.HttpClientMessage; /** @@ -33,6 +34,9 @@ import org.eclipse.osee.framework.skynet.core.artifact.HttpClientMessage; */ 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 final TransactionRecordFactory txFactory; private final BranchCache branchCache; @@ -80,4 +84,10 @@ public class ClientTransactionAccessor implements ITransactionDataAccessor { } } + @Override + public TransactionRecord getOrLoadPriorTransaction(TransactionCache cache, int transactionNumber, int branchId) throws OseeCoreException { + int priorTransactionId = + ConnectionHandler.runPreparedQueryFetchInt(-1, GET_PRIOR_TRANSACTION, branchId, transactionNumber); + return cache.getOrLoad(priorTransactionId); + } } diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/acquirer/ArtifactChangeAcquirer.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/acquirer/ArtifactChangeAcquirer.java index 040fcdb9d81..0f925cf70fc 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/acquirer/ArtifactChangeAcquirer.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/acquirer/ArtifactChangeAcquirer.java @@ -22,6 +22,7 @@ import org.eclipse.osee.framework.core.model.Branch; import org.eclipse.osee.framework.core.model.TransactionDelta; import org.eclipse.osee.framework.core.model.TransactionRecord; import org.eclipse.osee.framework.database.core.ConnectionHandler; +import org.eclipse.osee.framework.database.core.DatabaseTransactions; import org.eclipse.osee.framework.database.core.IOseeStatement; import org.eclipse.osee.framework.database.core.OseeSql; import org.eclipse.osee.framework.skynet.core.artifact.Artifact; diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/acquirer/AttributeChangeAcquirer.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/acquirer/AttributeChangeAcquirer.java index 90f82d2b37b..7e069c46af4 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/acquirer/AttributeChangeAcquirer.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/acquirer/AttributeChangeAcquirer.java @@ -29,6 +29,7 @@ import org.eclipse.osee.framework.core.model.TransactionDelta; import org.eclipse.osee.framework.core.model.TransactionRecord; import org.eclipse.osee.framework.core.model.type.AttributeType; import org.eclipse.osee.framework.database.core.ConnectionHandler; +import org.eclipse.osee.framework.database.core.DatabaseTransactions; import org.eclipse.osee.framework.database.core.IOseeStatement; import org.eclipse.osee.framework.database.core.OseeSql; import org.eclipse.osee.framework.database.core.SQL3DataType; diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionManager.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionManager.java index 409e37a081a..f62b5713d21 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionManager.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/transaction/TransactionManager.java @@ -51,9 +51,6 @@ public final class TransactionManager { private static final String SELECT_TRANSACTIONS = "SELECT * FROM osee_tx_details WHERE branch_id = ? ORDER BY transaction_id DESC"; - private static final String GET_PRIOR_TRANSACTION = - "SELECT MAX(transaction_id) AS prior_id FROM osee_tx_details WHERE branch_id = ? AND transaction_id < ?"; - private static final String SELECT_COMMIT_TRANSACTIONS = "SELECT transaction_id FROM osee_tx_details WHERE commit_art_id = ?"; @@ -193,29 +190,6 @@ public final class TransactionManager { transactionRecord.getBranchId(), transactionRecord.getTxType().getId()); } - /** - * @return The prior transactionId, or null if there is no prior. - */ - public static TransactionRecord getPriorTransaction(TransactionRecord transactionId) throws OseeCoreException { - TransactionRecord priorTransactionId = null; - IOseeStatement chStmt = ConnectionHandler.getStatement(); - - try { - chStmt.runPreparedQuery(GET_PRIOR_TRANSACTION, transactionId.getBranchId(), transactionId.getId()); - - if (chStmt.next()) { - int priorId = chStmt.getInt("prior_id"); - if (chStmt.wasNull()) { - throw new TransactionDoesNotExist("the prior transation id was null"); - } - priorTransactionId = getTransactionId(priorId); - } - } finally { - chStmt.close(); - } - return priorTransactionId; - } - public static TransactionRecord getTransactionAtDate(IOseeBranch branch, Date maxDateExclusive) throws OseeCoreException { Conditions.checkNotNull(branch, "branch"); Conditions.checkNotNull(maxDateExclusive, "max date exclusive"); @@ -289,4 +263,9 @@ public final class TransactionManager { } return transactionRecord; } + + public static TransactionRecord getPriorTransaction(TransactionRecord transactionId) throws OseeCoreException { + TransactionCache txCache = getTransactionCache(); + return txCache.getPriorTransaction(transactionId); + } }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/utility/PurgeTransactionOperationWithListener.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/utility/PurgeTransactionOperationWithListener.java new file mode 100644 index 00000000000..82958e5b93f --- /dev/null +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/utility/PurgeTransactionOperationWithListener.java @@ -0,0 +1,41 @@ +/* + * Created on Jun 15, 2011 + * + * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE + */ +package org.eclipse.osee.framework.skynet.core.utility; + +import java.util.Collection; +import java.util.logging.Level; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.model.TransactionRecord; +import org.eclipse.osee.framework.core.operation.IOperation; +import org.eclipse.osee.framework.database.operation.PurgeTransactionOperation; +import org.eclipse.osee.framework.database.operation.PurgeTransactionOperation.PurgeTransactionListener; +import org.eclipse.osee.framework.logging.OseeLog; +import org.eclipse.osee.framework.skynet.core.event.OseeEventManager; +import org.eclipse.osee.framework.skynet.core.event.PurgeTransactionEventUtil; +import org.eclipse.osee.framework.skynet.core.event.model.TransactionEvent; +import org.eclipse.osee.framework.skynet.core.internal.Activator; + +public class PurgeTransactionOperationWithListener { + public static IOperation getPurgeTransactionOperation(boolean force, final int... transactionIdNumbers) { + final PurgeTransactionOperation op = + new PurgeTransactionOperation(Activator.getInstance().getOseeDatabaseService(), force, transactionIdNumbers); + + PurgeTransactionListener listener = new PurgeTransactionListener() { + + @Override + public void onPurgeTransactionSuccess(Collection<TransactionRecord> transactions) { + TransactionEvent transactionEvent = PurgeTransactionEventUtil.createPurgeTransactionEvent(transactions); + try { + OseeEventManager.kickTransactionEvent(op, transactionEvent); + } catch (OseeCoreException ex) { + OseeLog.log(Activator.class, Level.SEVERE, "Error sending purge transaction events", ex); + } + } + }; + op.addListener(listener); + return op; + } +} |