mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Fixed retrying wrapper for non-propogating transactions.
Fixed retrying for the scenario where a transaction is marked for rollback but without an exception. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5950 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -27,6 +27,7 @@ package org.alfresco.repo.transaction;
|
|||||||
import java.sql.BatchUpdateException;
|
import java.sql.BatchUpdateException;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import javax.transaction.RollbackException;
|
||||||
import javax.transaction.Status;
|
import javax.transaction.Status;
|
||||||
import javax.transaction.SystemException;
|
import javax.transaction.SystemException;
|
||||||
import javax.transaction.UserTransaction;
|
import javax.transaction.UserTransaction;
|
||||||
@@ -210,10 +211,12 @@ public class RetryingTransactionHelper
|
|||||||
{
|
{
|
||||||
txn = fTxnService.getUserTransaction(readOnly);
|
txn = fTxnService.getUserTransaction(readOnly);
|
||||||
}
|
}
|
||||||
// Do we need to handle transaction demarcation. If
|
// Do we need to handle transaction demarcation. If no, we cannot do retries,
|
||||||
// no, we cannot do retries, that will be up to the containing
|
// that will be up to the containing transaction.
|
||||||
// transaction.
|
isNew = newTransaction || txn.getStatus() == Status.STATUS_NO_TRANSACTION;
|
||||||
isNew = txn.getStatus() == Status.STATUS_NO_TRANSACTION;
|
// Only start a transaction if required. This check isn't necessary as the transactional
|
||||||
|
// behaviour ensures that the appropriate propogation is performed. It is a useful and
|
||||||
|
// simple optimization.
|
||||||
if (isNew)
|
if (isNew)
|
||||||
{
|
{
|
||||||
txn.begin();
|
txn.begin();
|
||||||
@@ -223,7 +226,18 @@ public class RetryingTransactionHelper
|
|||||||
// Only commit if we 'own' the transaction.
|
// Only commit if we 'own' the transaction.
|
||||||
if (isNew)
|
if (isNew)
|
||||||
{
|
{
|
||||||
txn.commit();
|
if (txn.getStatus() == Status.STATUS_MARKED_ROLLBACK)
|
||||||
|
{
|
||||||
|
// Something caused the transaction to be marked for rollback
|
||||||
|
// There is no recovery or retrying with this
|
||||||
|
txn.rollback();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// The transaction hasn't been flagged for failure so the commit
|
||||||
|
// sould still be good.
|
||||||
|
txn.commit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (fgLogger.isDebugEnabled())
|
if (fgLogger.isDebugEnabled())
|
||||||
{
|
{
|
||||||
@@ -236,6 +250,13 @@ public class RetryingTransactionHelper
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
catch (RollbackException e)
|
||||||
|
{
|
||||||
|
// Our explicit rollback didn't work
|
||||||
|
throw new AlfrescoRuntimeException(
|
||||||
|
"Unexpected rollback exception: \n" + e.getMessage(),
|
||||||
|
e);
|
||||||
|
}
|
||||||
catch (Throwable e)
|
catch (Throwable e)
|
||||||
{
|
{
|
||||||
// Somebody else 'owns' the transaction, so just rethrow.
|
// Somebody else 'owns' the transaction, so just rethrow.
|
||||||
|
Reference in New Issue
Block a user