From a2970e7c49d8871284bfd2116f2de17b1c938287 Mon Sep 17 00:00:00 2001 From: Derek Hulley Date: Wed, 16 Sep 2009 18:59:25 +0000 Subject: [PATCH] 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 --- .../AlfrescoTransactionSupport.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/source/java/org/alfresco/repo/transaction/AlfrescoTransactionSupport.java b/source/java/org/alfresco/repo/transaction/AlfrescoTransactionSupport.java index ef275719fa..e97799d5b4 100644 --- a/source/java/org/alfresco/repo/transaction/AlfrescoTransactionSupport.java +++ b/source/java/org/alfresco/repo/transaction/AlfrescoTransactionSupport.java @@ -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 true 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? *