Added method to check that a read-only or read-write txn is present

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@16326 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2009-09-16 18:59:25 +00:00
parent 95bfde2d56
commit a2970e7c49

View File

@@ -172,6 +172,29 @@ public abstract class AlfrescoTransactionSupport
}
}
/**
* Checks the state of the current transaction and throws an exception if a transaction
* is not present or if the transaction is not read-write, if required.
*
* @param requireReadWrite <tt>true</tt> if the transaction must be read-write
*
* @since 3.2
*/
public static void checkTransactionReadState(boolean requireReadWrite)
{
if (!TransactionSynchronizationManager.isSynchronizationActive())
{
throw new IllegalStateException(
"The current operation requires an active " +
(requireReadWrite ? "read-write" : "") +
"transaction.");
}
if (TransactionSynchronizationManager.isCurrentTransactionReadOnly() && requireReadWrite)
{
throw new IllegalStateException("The current operation requires an active read-write transaction.");
}
}
/**
* Are there any pending changes which must be synchronized with the store?
*