mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.1/Cloud)
99764: Merged 5.0.N (5.0.2) to HEAD-BUG-FIX (5.1/Cloud) 99695: Merged V4.2-BUG-FIX (4.2.5) to 5.0.N (5.0.2) 99553: MNT-12628: Following on from MNT-12501 - Rollback of synchronous transactions is not behaving consistently - Added a static variable holding the RollbackOnly state to RetryingTransactionHelper. Currently used by RetryingTransactionInterceptor. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@100491 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -208,6 +208,12 @@ public class RetryingTransactionHelper
|
||||
*/
|
||||
private List<Class<?>> extraExceptions;
|
||||
|
||||
/**
|
||||
* A local variable holding the Rollback-only transaction flag which can be set by {@link #setRollbackOnly()}
|
||||
* and is flushed by the
|
||||
*/
|
||||
private static ThreadLocal<Boolean> rollbackOnly = new ThreadLocal<Boolean>();
|
||||
|
||||
/**
|
||||
* Callback interface
|
||||
* @author Derek Hulley
|
||||
@@ -458,7 +464,11 @@ public class RetryingTransactionHelper
|
||||
// Only commit if we 'own' the transaction.
|
||||
if (txn != null)
|
||||
{
|
||||
if (txn.getStatus() == Status.STATUS_MARKED_ROLLBACK)
|
||||
// Check if force rollback is on
|
||||
boolean mustRollBack = isRollbackOnly();
|
||||
// This method owns the transaction; make sure we don't leak the state
|
||||
rollbackOnly.set(null);
|
||||
if (txn.getStatus() == Status.STATUS_MARKED_ROLLBACK || mustRollBack)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
@@ -511,6 +521,10 @@ public class RetryingTransactionHelper
|
||||
" Exception follows:",
|
||||
e);
|
||||
}
|
||||
|
||||
// make sure we don't leak the state
|
||||
rollbackOnly.set(null);
|
||||
|
||||
// Rollback if we can.
|
||||
if (txn != null)
|
||||
{
|
||||
@@ -670,6 +684,29 @@ public class RetryingTransactionHelper
|
||||
return retryCause;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns <tt>true</tt> if the current thread transaction was marked as RollbackOnly
|
||||
*/
|
||||
public static boolean isRollbackOnly()
|
||||
{
|
||||
if (rollbackOnly.get() == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return rollbackOnly.get();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to set the RollbackOnly state of the transaction in the current thread
|
||||
*/
|
||||
public static void setRollbackOnly()
|
||||
{
|
||||
rollbackOnly.set(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to get the active transaction. The transaction status can be queried and
|
||||
* marked for rollback.
|
||||
|
Reference in New Issue
Block a user