本文整理汇总了Java中javax.transaction.Status.STATUS_ROLLEDBACK属性的典型用法代码示例。如果您正苦于以下问题:Java Status.STATUS_ROLLEDBACK属性的具体用法?Java Status.STATUS_ROLLEDBACK怎么用?Java Status.STATUS_ROLLEDBACK使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.transaction.Status
的用法示例。
在下文中一共展示了Status.STATUS_ROLLEDBACK属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: restartTransaction
/**
* Commits or rolls back or does nothing with the current transaction and begins a new {@link UserTransaction}
*
* @param transactionAction - one of the {@link TransactionActionEnum} values which specifies action to be done for the current transaction
* @throws Exception
*/
private void restartTransaction(TransactionActionEnum transactionAction) throws Exception
{
if ((null != transaction) && (Status.STATUS_ROLLEDBACK != transaction.getStatus()) && (Status.STATUS_COMMITTED != transaction.getStatus()))
{
if (TransactionActionEnum.ACTION_COMMIT == transactionAction)
{
transaction.commit();
}
else if (TransactionActionEnum.ACTION_ROLLBACK == transactionAction)
{
transaction.rollback();
}
}
transaction = transactionService.getUserTransaction();
transaction.begin();
}
示例2: afterCompletion
@Override
public void afterCompletion(int status) {
switch (status) {
case Status.STATUS_COMMITTED:
try {
TransactionSynchronizationUtils.invokeAfterCommit(this.synchronizations);
}
finally {
TransactionSynchronizationUtils.invokeAfterCompletion(
this.synchronizations, TransactionSynchronization.STATUS_COMMITTED);
}
break;
case Status.STATUS_ROLLEDBACK:
TransactionSynchronizationUtils.invokeAfterCompletion(
this.synchronizations, TransactionSynchronization.STATUS_ROLLED_BACK);
break;
default:
TransactionSynchronizationUtils.invokeAfterCompletion(
this.synchronizations, TransactionSynchronization.STATUS_UNKNOWN);
}
}
示例3: tearDown
@After
@Override
public void tearDown() throws Exception
{
scheduler.getScheduler().unscheduleJob(scheduler.getTriggerName(), scheduler.getJobGroup());
if (Status.STATUS_ROLLEDBACK != transaction.getStatus())
{
transaction.rollback();
}
freshNodes.clear();
yesterdayNodes.clear();
AuthenticationUtil.clearCurrentSecurityContext();
}
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:16,代码来源:CronScheduledQueryBasedTemplateActionDefinitionTest.java
示例4: afterCompletion
/**
* JTA {@code afterCompletion} callback: invoked after commit/rollback.
* <p>Needs to invoke the Spring synchronization's {@code beforeCompletion}
* at this late stage in case of a rollback, since there is no corresponding
* callback with JTA.
* @see org.springframework.transaction.support.TransactionSynchronization#beforeCompletion
* @see org.springframework.transaction.support.TransactionSynchronization#afterCompletion
*/
@Override
public void afterCompletion(int status) {
if (!this.beforeCompletionCalled) {
// beforeCompletion not called before (probably because of JTA rollback).
// Perform the cleanup here.
this.springSynchronization.beforeCompletion();
}
// Call afterCompletion with the appropriate status indication.
switch (status) {
case Status.STATUS_COMMITTED:
this.springSynchronization.afterCompletion(TransactionSynchronization.STATUS_COMMITTED);
break;
case Status.STATUS_ROLLEDBACK:
this.springSynchronization.afterCompletion(TransactionSynchronization.STATUS_ROLLED_BACK);
break;
default:
this.springSynchronization.afterCompletion(TransactionSynchronization.STATUS_UNKNOWN);
}
}
示例5: buildErrorString
/**
* Utility method to report errors about invalid state.
*
* @return - an error based on status
*/
private String buildErrorString()
{
StringBuilder buffer = new StringBuilder(128);
buffer.append("The indexer is unable to accept more work: ");
switch (getStatus().getStatus())
{
case Status.STATUS_COMMITTED:
buffer.append("The indexer has been committed");
break;
case Status.STATUS_COMMITTING:
buffer.append("The indexer is committing");
break;
case Status.STATUS_MARKED_ROLLBACK:
buffer.append("The indexer is marked for rollback");
break;
case Status.STATUS_PREPARED:
buffer.append("The indexer is prepared to commit");
break;
case Status.STATUS_PREPARING:
buffer.append("The indexer is preparing to commit");
break;
case Status.STATUS_ROLLEDBACK:
buffer.append("The indexer has been rolled back");
break;
case Status.STATUS_ROLLING_BACK:
buffer.append("The indexer is rolling back");
break;
case Status.STATUS_UNKNOWN:
buffer.append("The indexer is in an unknown state");
break;
default:
break;
}
return buffer.toString();
}
示例6: rollback
/**
* Roll back the index changes (this just means they are never added)
*
* @throws LuceneIndexException
*/
public void rollback() throws LuceneIndexException
{
switch (getStatus().getStatus())
{
case Status.STATUS_COMMITTED:
throw new IndexerException("Unable to roll back: Transaction is committed ");
case Status.STATUS_ROLLING_BACK:
throw new IndexerException("Unable to roll back: Transaction is rolling back");
case Status.STATUS_ROLLEDBACK:
throw new IndexerException("Unable to roll back: Transaction is already rolled back");
case Status.STATUS_COMMITTING:
// Can roll back during commit
default:
try
{
setStatus(TransactionStatus.ROLLINGBACK);
doRollBack();
setStatus(TransactionStatus.ROLLEDBACK);
}
catch (IOException e)
{
throw new LuceneIndexException("rollback failed ", e);
}
break;
}
}
示例7: tearDown
public void tearDown() throws Exception
{
try
{
if (txn.getStatus() != Status.STATUS_ROLLEDBACK && txn.getStatus() != Status.STATUS_COMMITTED)
{
txn.rollback();
}
}
catch (Throwable e)
{
e.printStackTrace();
}
}
示例8: tearDown
@After
public void tearDown() throws Exception
{
try
{
if (txn.getStatus() != Status.STATUS_ROLLEDBACK && txn.getStatus() != Status.STATUS_COMMITTED)
{
txn.commit();
}
}
catch (Throwable e)
{
e.printStackTrace();
}
}
示例9: tearDown
@After
public void tearDown() throws Exception
{
AuthenticationUtil.clearCurrentSecurityContext();
if ((null != transaction) && (Status.STATUS_COMMITTED != transaction.getStatus()) && (Status.STATUS_ROLLEDBACK != transaction.getStatus()))
{
transaction.rollback();
}
}
示例10: isTransactionActive
/**
* Checks if the current transaction is active, rolled back or marked for
* rollback.
*
* @return {@code true} if the current transaction is active, rolled back or
* marked for rollback, {@code false} otherwise.
* @throws SystemException thrown if the transaction manager encounters an
* unexpected error condition
*/
private boolean isTransactionActive(TransactionManager transactionManager) throws SystemException {
switch (transactionManager.getStatus()) {
case Status.STATUS_ACTIVE:
case Status.STATUS_MARKED_ROLLBACK:
case Status.STATUS_ROLLEDBACK:
return true;
default:
return false;
}
}
示例11: getStatus
/**
* This status is a combination of the internal status, as recorded during explicit operations,
* and the status provided by the Spring support.
*
* @see Status
*/
public synchronized int getStatus() throws SystemException
{
TransactionInfo txnInfo = getTransactionInfo();
// if the txn info is null, then we are outside a transaction
if (txnInfo == null)
{
return internalStatus; // this is checked in getTransactionInfo
}
// normally the internal status is correct, but we only need to double check
// for the case where the transaction was marked for rollback, or rolledback
// in a deeper transaction
TransactionStatus txnStatus = txnInfo.getTransactionStatus();
if (internalStatus == Status.STATUS_ROLLEDBACK)
{
// explicitly rolled back at some point
return internalStatus;
}
else if (txnStatus.isRollbackOnly())
{
// marked for rollback at some point in the stack
return Status.STATUS_MARKED_ROLLBACK;
}
else
{
// just rely on the internal status
return internalStatus;
}
}
示例12: afterCompletion
public void afterCompletion(int status) {
// System.err.println("start afterCompletion");
final long opStart = CachePerfStats.getStatTime();
switch (status) {
case Status.STATUS_COMMITTED:
// System.err.println("begin commit in afterCompletion");
Assert.assertTrue(this.locks != null,
"Gemfire Transaction afterCompletion called with illegal state.");
try {
this.proxy.getTxMgr().setTXState(null);
commit();
} catch (CommitConflictException error) {
Assert.assertTrue(false, "Gemfire Transaction " + getTransactionId()
+ " afterCompletion failed.due to CommitConflictException: " + error);
}
this.proxy.getTxMgr().noteCommitSuccess(opStart, this.jtaLifeTime, this);
this.locks = null;
// System.err.println("end commit in afterCompletion");
break;
case Status.STATUS_ROLLEDBACK:
this.jtaLifeTime = opStart - getBeginTime();
this.proxy.getTxMgr().setTXState(null);
rollback();
this.proxy.getTxMgr().noteRollbackSuccess(opStart, this.jtaLifeTime, this);
break;
default:
Assert.assertTrue(false, "Unknown JTA Synchronization status " + status);
}
// System.err.println("end afterCompletion");
}
示例13: doRegisterAfterCompletionWithJtaTransaction
/**
* Register a JTA synchronization on the JTA TransactionManager, for calling
* {@code afterCompletion} on the given Spring TransactionSynchronizations.
* <p>The default implementation registers the synchronizations on the
* JTA 1.1 TransactionSynchronizationRegistry, if available, or on the
* JTA TransactionManager's current Transaction - again, if available.
* If none of the two is available, a warning will be logged.
* <p>Can be overridden in subclasses, for specific JTA implementations.
* @param txObject the current transaction object
* @param synchronizations List of TransactionSynchronization objects
* @throws RollbackException if thrown by JTA methods
* @throws SystemException if thrown by JTA methods
* @see #getTransactionManager()
* @see javax.transaction.Transaction#registerSynchronization
* @see javax.transaction.TransactionSynchronizationRegistry#registerInterposedSynchronization
*/
protected void doRegisterAfterCompletionWithJtaTransaction(
JtaTransactionObject txObject, List<TransactionSynchronization> synchronizations)
throws RollbackException, SystemException {
int jtaStatus = txObject.getUserTransaction().getStatus();
if (jtaStatus == Status.STATUS_NO_TRANSACTION) {
throw new RollbackException("JTA transaction already completed - probably rolled back");
}
if (jtaStatus == Status.STATUS_ROLLEDBACK) {
throw new RollbackException("JTA transaction already rolled back (probably due to a timeout)");
}
if (this.transactionSynchronizationRegistry != null) {
// JTA 1.1 TransactionSynchronizationRegistry available - use it.
this.transactionSynchronizationRegistry.registerInterposedSynchronization(
new JtaAfterCompletionSynchronization(synchronizations));
}
else if (getTransactionManager() != null) {
// At least the JTA TransactionManager available - use that one.
Transaction transaction = getTransactionManager().getTransaction();
if (transaction == null) {
throw new IllegalStateException("No JTA Transaction available");
}
transaction.registerSynchronization(new JtaAfterCompletionSynchronization(synchronizations));
}
else {
// No JTA TransactionManager available - log a warning.
logger.warn("Participating in existing JTA transaction, but no JTA TransactionManager available: " +
"cannot register Spring after-completion callbacks with outer JTA transaction - " +
"processing Spring after-completion callbacks with outcome status 'unknown'");
invokeAfterCompletion(synchronizations, TransactionSynchronization.STATUS_UNKNOWN);
}
}
示例14: endTransaction
/**
* End an active transaction
*
* @param sess SrvSession
* @param tx Object
*/
public void endTransaction(SrvSession sess, Object tx) {
// Check that the transaction object is valid
if ( tx == null)
return;
// Get the filesystem transaction
FilesysTransaction filesysTx = (FilesysTransaction) tx;
// Check if there is an active transaction
if ( filesysTx != null && filesysTx.hasTransaction())
{
// Get the active transaction
UserTransaction ftx = filesysTx.getTransaction();
try
{
// Commit or rollback the transaction
if ( ftx.getStatus() == Status.STATUS_MARKED_ROLLBACK ||
ftx.getStatus() == Status.STATUS_ROLLEDBACK ||
ftx.getStatus() == Status.STATUS_ROLLING_BACK)
{
// Transaction is marked for rollback
ftx.rollback();
// DEBUG
if ( logger.isDebugEnabled())
logger.debug("End transaction (rollback)");
}
else
{
// Commit the transaction
ftx.commit();
// DEBUG
if ( logger.isDebugEnabled())
logger.debug("End transaction (commit)");
}
}
catch ( Exception ex)
{
if ( logger.isDebugEnabled())
logger.debug("Failed to end transaction, " + ex.getMessage());
// throw new AlfrescoRuntimeException("Failed to end transaction", ex);
}
finally
{
// Clear the current transaction
sess.clearTransaction();
}
}
}
示例15: commit
/**
* @throws IllegalStateException if a transaction was not started
*/
public synchronized void commit()
throws RollbackException, HeuristicMixedException, HeuristicRollbackException,
SecurityException, IllegalStateException, SystemException
{
// perform checks
TransactionInfo txnInfo = getTransactionInfo();
int status = getStatus();
// check the status
if (status == Status.STATUS_NO_TRANSACTION)
{
throw new IllegalStateException("The transaction has not yet begun");
}
else if (status == Status.STATUS_ROLLING_BACK || status == Status.STATUS_ROLLEDBACK)
{
throw new RollbackException("The transaction has already been rolled back");
}
else if (status == Status.STATUS_MARKED_ROLLBACK)
{
throw new RollbackException("The transaction has already been marked for rollback");
}
else if (status == Status.STATUS_COMMITTING || status == Status.STATUS_COMMITTED)
{
throw new IllegalStateException("The transaction has already been committed");
}
else if (status != Status.STATUS_ACTIVE || txnInfo == null)
{
throw new IllegalStateException("No user transaction is active");
}
if (!finalized)
{
try
{
// the status seems correct - we can try a commit
commitTransactionAfterReturning(txnInfo);
}
catch (Throwable e)
{
if (logger.isDebugEnabled())
{
logger.debug("Transaction didn't commit", e);
}
// commit failed
internalStatus = Status.STATUS_ROLLEDBACK;
RollbackException re = new RollbackException("Transaction didn't commit: " + e.getMessage());
// Stick the originating reason for failure into the exception.
re.initCause(e);
throw re;
}
finally
{
// make sure that we clean up the stack
cleanupTransactionInfo(txnInfo);
finalized = true;
// clean up leaked transaction logging
isBeginMatched = true;
beginCallStack = null;
}
}
// regardless of whether the transaction was finally committed or not, the status
// as far as UserTransaction is concerned should be 'committed'
// keep track that this UserTransaction was explicitly committed
internalStatus = Status.STATUS_COMMITTED;
// done
if (logger.isDebugEnabled())
{
logger.debug("Committed user transaction: " + this);
}
}