Renamed TransactionComponent to TransactionServiceImpl

Fixed naming convention to be 'transactionService', 'TransactionService', but kept an alias 'transactionComponent'.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5905 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2007-06-11 10:10:38 +00:00
parent 23cf6181e6
commit cc948d8c39
21 changed files with 149 additions and 48 deletions

View File

@@ -25,7 +25,7 @@
<bean id="asynchronousActionExecutionQueue" class="org.alfresco.repo.action.AsynchronousActionExecutionQueueImpl"> <bean id="asynchronousActionExecutionQueue" class="org.alfresco.repo.action.AsynchronousActionExecutionQueueImpl">
<property name="transactionService"> <property name="transactionService">
<ref bean="transactionComponent"/> <ref bean="transactionService"/>
</property> </property>
<property name="authenticationComponent"> <property name="authenticationComponent">
<ref bean="AuthenticationComponent"/> <ref bean="AuthenticationComponent"/>

View File

@@ -11,7 +11,7 @@
<value>node</value> <value>node</value>
</property> </property>
<property name="transactionService"> <property name="transactionService">
<ref bean="transactionComponent"/> <ref bean="transactionService"/>
</property> </property>
</bean> </bean>
@@ -20,7 +20,7 @@
<value>layer</value> <value>layer</value>
</property> </property>
<property name="transactionService"> <property name="transactionService">
<ref bean="transactionComponent"/> <ref bean="transactionService"/>
</property> </property>
</bean> </bean>
@@ -171,7 +171,7 @@
<value>1000</value> <value>1000</value>
</property> </property>
<property name="transactionService"> <property name="transactionService">
<ref bean="transactionComponent"/> <ref bean="transactionService"/>
</property> </property>
<property name="sessionFactory"> <property name="sessionFactory">
<ref bean="sessionFactory"/> <ref bean="sessionFactory"/>

View File

@@ -254,7 +254,7 @@
<ref bean="systemBootstrap"/> <ref bean="systemBootstrap"/>
</property> </property>
<property name="transactionService"> <property name="transactionService">
<ref bean="transactionComponent"/> <ref bean="transactionService"/>
</property> </property>
<property name="namespaceService"> <property name="namespaceService">
<ref bean="namespaceService"/> <ref bean="namespaceService"/>
@@ -296,7 +296,7 @@
</property> </property>
<!-- helper beans --> <!-- helper beans -->
<property name="transactionService"> <property name="transactionService">
<ref bean="transactionComponent"/> <ref bean="transactionService"/>
</property> </property>
<property name="systemBootstrap"> <property name="systemBootstrap">
<ref bean="systemBootstrap"/> <ref bean="systemBootstrap"/>
@@ -319,7 +319,7 @@
<bean id="patchExecuter" class="org.alfresco.repo.admin.patch.PatchExecuter"> <bean id="patchExecuter" class="org.alfresco.repo.admin.patch.PatchExecuter">
<property name="transactionService"> <property name="transactionService">
<ref bean="transactionComponent" /> <ref bean="transactionService" />
</property> </property>
<property name="patchService"> <property name="patchService">
<ref bean="PatchService" /> <ref bean="PatchService" />

View File

@@ -33,7 +33,7 @@
<ref bean="avmNodeDAO"/> <ref bean="avmNodeDAO"/>
</property> </property>
<property name="transactionService" > <property name="transactionService" >
<ref bean="transactionComponent" /> <ref bean="transactionService" />
</property> </property>
<property name="protectDays" > <property name="protectDays" >
<value>14</value> <value>14</value>
@@ -52,7 +52,7 @@
<bean id="contentService" class="org.alfresco.repo.content.RoutingContentService" init-method="init"> <bean id="contentService" class="org.alfresco.repo.content.RoutingContentService" init-method="init">
<property name="transactionService"> <property name="transactionService">
<ref bean="transactionComponent" /> <ref bean="transactionService" />
</property> </property>
<property name="retryingTransactionHelper"> <property name="retryingTransactionHelper">
<ref bean="retryingTransactionHelper"/> <ref bean="retryingTransactionHelper"/>

View File

@@ -145,7 +145,8 @@
</bean> </bean>
<!-- transaction service --> <!-- transaction service -->
<bean id="transactionComponent" class="org.alfresco.repo.transaction.TransactionComponent"> <alias name="transactionService" alias="transactionComponent"/>
<bean id="transactionService" class="org.alfresco.repo.transaction.TransactionServiceImpl">
<property name="transactionManager"> <property name="transactionManager">
<ref bean="transactionManager" /> <ref bean="transactionManager" />
</property> </property>
@@ -156,10 +157,10 @@
<bean id="retryingTransactionHelper" class="org.alfresco.repo.transaction.RetryingTransactionHelper"> <bean id="retryingTransactionHelper" class="org.alfresco.repo.transaction.RetryingTransactionHelper">
<property name="transactionService"> <property name="transactionService">
<ref bean="transactionComponent"/> <ref bean="transactionService"/>
</property> </property>
<property name="maxRetries"> <property name="maxRetries">
<value>20</value> <value>${server.transaction.max-retries}</value>
</property> </property>
</bean> </bean>
@@ -654,7 +655,7 @@
<ref bean="searchService"/> <ref bean="searchService"/>
</property> </property>
<property name="transactionService"> <property name="transactionService">
<ref bean="transactionComponent"/> <ref bean="transactionService"/>
</property> </property>
<property name="authenticationComponent"> <property name="authenticationComponent">
<ref bean="authenticationComponent"/> <ref bean="authenticationComponent"/>
@@ -776,7 +777,7 @@
<bean id="luceneIndexBackupComponent" <bean id="luceneIndexBackupComponent"
class="org.alfresco.repo.search.impl.lucene.AbstractLuceneIndexerAndSearcherFactory$LuceneIndexBackupComponent"> class="org.alfresco.repo.search.impl.lucene.AbstractLuceneIndexerAndSearcherFactory$LuceneIndexBackupComponent">
<property name="transactionService"> <property name="transactionService">
<ref bean="transactionComponent" /> <ref bean="transactionService" />
</property> </property>
<property name="factories"> <property name="factories">
<set> <set>

View File

@@ -7,3 +7,5 @@ server.transaction.mode.readOnly=PROPAGATION_REQUIRED, readOnly
#server.transaction.allow-writes=false #server.transaction.allow-writes=false
server.transaction.mode.default=PROPAGATION_REQUIRED server.transaction.mode.default=PROPAGATION_REQUIRED
server.transaction.allow-writes=true server.transaction.allow-writes=true
server.transaction.max-retries=20

View File

@@ -181,7 +181,7 @@
<bean id="systemInfoImporter" class="org.alfresco.repo.importer.system.SystemInfoBootstrap" abstract="true"> <bean id="systemInfoImporter" class="org.alfresco.repo.importer.system.SystemInfoBootstrap" abstract="true">
<property name="transactionService"> <property name="transactionService">
<ref bean="transactionComponent"/> <ref bean="transactionService"/>
</property> </property>
<property name="nodeService"> <property name="nodeService">
<ref bean="nodeService"/> <ref bean="nodeService"/>
@@ -203,7 +203,7 @@
<bean id="storeImporter" class="org.alfresco.repo.importer.ImporterBootstrap" abstract="true"> <bean id="storeImporter" class="org.alfresco.repo.importer.ImporterBootstrap" abstract="true">
<property name="transactionService"> <property name="transactionService">
<ref bean="transactionComponent"/> <ref bean="transactionService"/>
</property> </property>
<property name="nodeService"> <property name="nodeService">
<ref bean="nodeService"/> <ref bean="nodeService"/>

View File

@@ -7,8 +7,8 @@
<property name="authenticationComponent"> <property name="authenticationComponent">
<ref bean="authenticationComponent" /> <ref bean="authenticationComponent" />
</property> </property>
<property name="transactionComponent"> <property name="transactionService">
<ref bean="transactionComponent" /> <ref bean="transactionService" />
</property> </property>
<property name="indexer"> <property name="indexer">
<ref bean="indexerComponent" /> <ref bean="indexerComponent" />

View File

@@ -38,7 +38,7 @@
<ref bean="personService"/> <ref bean="personService"/>
</property> </property>
<property name="transactionService"> <property name="transactionService">
<ref bean="transactionComponent"/> <ref bean="transactionService"/>
</property> </property>
<property name="diskInterface"> <property name="diskInterface">
<ref bean="contentDiskDriver"/> <ref bean="contentDiskDriver"/>
@@ -53,7 +53,7 @@
<constructor-arg> <constructor-arg>
<ref bean="cifsHelper" /> <ref bean="cifsHelper" />
</constructor-arg> </constructor-arg>
<property name="transactionService"><ref bean="transactionComponent" /></property> <property name="transactionService"><ref bean="transactionService" /></property>
<property name="nodeService"><ref bean="NodeService" /></property> <property name="nodeService"><ref bean="NodeService" /></property>
<property name="searchService"><ref bean="SearchService" /></property> <property name="searchService"><ref bean="SearchService" /></property>
<property name="namespaceService"><ref bean="namespaceService" /></property> <property name="namespaceService"><ref bean="namespaceService" /></property>
@@ -78,7 +78,7 @@
<!-- AVM Filesystem Interface --> <!-- AVM Filesystem Interface -->
<bean id="avmDiskDriver" class="org.alfresco.filesys.avm.AVMDiskDriver" > <bean id="avmDiskDriver" class="org.alfresco.filesys.avm.AVMDiskDriver" >
<property name="avmService"><ref bean="indexingAVMService" /></property> <property name="avmService"><ref bean="indexingAVMService" /></property>
<property name="transactionService"><ref bean="transactionComponent" /></property> <property name="transactionService"><ref bean="transactionService" /></property>
<property name="authenticationComponent"><ref bean="authenticationComponent"/></property> <property name="authenticationComponent"><ref bean="authenticationComponent"/></property>
<property name="authenticationService"><ref bean="authenticationService"/></property> <property name="authenticationService"><ref bean="authenticationService"/></property>
<property name="mimetypeService"><ref bean="mimetypeService" /></property> <property name="mimetypeService"><ref bean="mimetypeService" /></property>

View File

@@ -63,7 +63,7 @@
<ref bean="SearchService"/> <ref bean="SearchService"/>
</property> </property>
<property name="transactionService"> <property name="transactionService">
<ref bean="transactionComponent"/> <ref bean="transactionService"/>
</property> </property>
</bean> </bean>

View File

@@ -51,7 +51,7 @@
<ref bean="patchComponent" /> <ref bean="patchComponent" />
</property> </property>
<property name="transactionService"> <property name="transactionService">
<ref bean="transactionComponent" /> <ref bean="transactionService" />
</property> </property>
<property name="namespaceService"> <property name="namespaceService">
<ref bean="namespaceService" /> <ref bean="namespaceService" />

View File

@@ -8,7 +8,7 @@
<!-- --> <!-- -->
<bean id="workflowDeployer" class="org.alfresco.repo.workflow.WorkflowDeployer" abstract="true"> <bean id="workflowDeployer" class="org.alfresco.repo.workflow.WorkflowDeployer" abstract="true">
<property name="transactionService" ref="transactionComponent"/> <property name="transactionService" ref="transactionService"/>
<property name="authenticationComponent" ref="authenticationComponent" /> <property name="authenticationComponent" ref="authenticationComponent" />
<property name="workflowService" ref="WorkflowService" /> <property name="workflowService" ref="WorkflowService" />
<property name="dictionaryDAO" ref="dictionaryDAO"/> <property name="dictionaryDAO" ref="dictionaryDAO"/>
@@ -36,7 +36,7 @@
<property name="namespaceService" ref="namespaceService"/> <property name="namespaceService" ref="namespaceService"/>
<property name="personService" ref="PersonService"/> <property name="personService" ref="PersonService"/>
<property name="authorityDAO" ref="authorityDAO"/> <property name="authorityDAO" ref="authorityDAO"/>
<property name="transactionService" ref="transactionComponent"/> <property name="transactionService" ref="transactionService"/>
<property name="fileFolderService" ref="FileFolderService"/> <property name="fileFolderService" ref="FileFolderService"/>
</bean> </bean>

View File

@@ -38,7 +38,7 @@ import org.alfresco.repo.search.impl.lucene.LuceneQueryParser;
import org.alfresco.repo.search.impl.lucene.fts.FullTextSearchIndexer; import org.alfresco.repo.search.impl.lucene.fts.FullTextSearchIndexer;
import org.alfresco.repo.security.authentication.AuthenticationComponent; import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.transaction.TransactionComponent; import org.alfresco.repo.transaction.TransactionServiceImpl;
import org.alfresco.repo.transaction.TransactionUtil; import org.alfresco.repo.transaction.TransactionUtil;
import org.alfresco.repo.transaction.TransactionUtil.TransactionWork; import org.alfresco.repo.transaction.TransactionUtil.TransactionWork;
import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.ChildAssociationRef;
@@ -72,7 +72,7 @@ public abstract class AbstractReindexComponent implements IndexRecovery
private AuthenticationComponent authenticationComponent; private AuthenticationComponent authenticationComponent;
/** provides transactions to atomically index each missed transaction */ /** provides transactions to atomically index each missed transaction */
protected TransactionComponent transactionService; protected TransactionServiceImpl transactionService;
/** the component to index the node hierarchy */ /** the component to index the node hierarchy */
protected Indexer indexer; protected Indexer indexer;
/** the FTS indexer that we will prompt to pick up on any un-indexed text */ /** the FTS indexer that we will prompt to pick up on any un-indexed text */
@@ -136,9 +136,9 @@ public abstract class AbstractReindexComponent implements IndexRecovery
* *
* @param transactionComponent provide transactions to index each missed transaction * @param transactionComponent provide transactions to index each missed transaction
*/ */
public void setTransactionComponent(TransactionComponent transactionComponent) public void setTransactionService(TransactionServiceImpl transactionService)
{ {
this.transactionService = transactionComponent; this.transactionService = transactionService;
} }
/** /**

View File

@@ -32,7 +32,7 @@ import org.alfresco.repo.node.db.NodeDaoService;
import org.alfresco.repo.search.Indexer; import org.alfresco.repo.search.Indexer;
import org.alfresco.repo.search.impl.lucene.fts.FullTextSearchIndexer; import org.alfresco.repo.search.impl.lucene.fts.FullTextSearchIndexer;
import org.alfresco.repo.security.authentication.AuthenticationComponent; import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.transaction.TransactionComponent; import org.alfresco.repo.transaction.TransactionServiceImpl;
import org.alfresco.repo.transaction.TransactionUtil; import org.alfresco.repo.transaction.TransactionUtil;
import org.alfresco.repo.transaction.TransactionUtil.TransactionWork; import org.alfresco.repo.transaction.TransactionUtil.TransactionWork;
import org.alfresco.service.ServiceRegistry; import org.alfresco.service.ServiceRegistry;
@@ -89,7 +89,7 @@ public class IndexRemoteTransactionTrackerTest extends TestCase
indexTracker.setNodeDaoService(nodeDaoService); indexTracker.setNodeDaoService(nodeDaoService);
indexTracker.setNodeService(nodeService); indexTracker.setNodeService(nodeService);
indexTracker.setSearcher(searchService); indexTracker.setSearcher(searchService);
indexTracker.setTransactionComponent((TransactionComponent)transactionService); indexTracker.setTransactionService((TransactionServiceImpl)transactionService);
// authenticate // authenticate
authenticationComponent.setSystemUserAsCurrentUser(); authenticationComponent.setSystemUserAsCurrentUser();

View File

@@ -35,7 +35,7 @@ import org.alfresco.repo.search.Indexer;
import org.alfresco.repo.search.impl.lucene.AbstractLuceneIndexerImpl; import org.alfresco.repo.search.impl.lucene.AbstractLuceneIndexerImpl;
import org.alfresco.repo.search.impl.lucene.fts.FullTextSearchIndexer; import org.alfresco.repo.search.impl.lucene.fts.FullTextSearchIndexer;
import org.alfresco.repo.security.authentication.AuthenticationComponent; import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.transaction.TransactionComponent; import org.alfresco.repo.transaction.TransactionServiceImpl;
import org.alfresco.service.ServiceRegistry; import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.model.FileFolderService; import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.repository.ContentData; import org.alfresco.service.cmr.repository.ContentData;
@@ -91,7 +91,7 @@ public class MissingContentReindexComponentTest extends TestCase
reindexer.setNodeDaoService(nodeDaoService); reindexer.setNodeDaoService(nodeDaoService);
reindexer.setNodeService(nodeService); reindexer.setNodeService(nodeService);
reindexer.setSearcher(searchService); reindexer.setSearcher(searchService);
reindexer.setTransactionComponent((TransactionComponent)transactionService); reindexer.setTransactionService((TransactionServiceImpl)transactionService);
// authenticate // authenticate
authenticationComponent.setSystemUserAsCurrentUser(); authenticationComponent.setSystemUserAsCurrentUser();

View File

@@ -76,4 +76,13 @@ public class DummyTransactionService implements TransactionService
{ {
return txn; return txn;
} }
public RetryingTransactionHelper getRetryingTransactionHelper()
{
RetryingTransactionHelper helper = new RetryingTransactionHelper();
helper.setMaxRetries(20);
helper.setTransactionService(this);
helper.setReadOnly(false);
return helper;
}
} }

View File

@@ -32,6 +32,7 @@ import javax.transaction.UserTransaction;
import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.error.ExceptionStackUtil; import org.alfresco.error.ExceptionStackUtil;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.service.transaction.TransactionService; import org.alfresco.service.transaction.TransactionService;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.hibernate.StaleObjectStateException; import org.hibernate.StaleObjectStateException;
@@ -48,6 +49,7 @@ import org.springframework.dao.DeadlockLoserDataAccessException;
*/ */
public class RetryingTransactionHelper public class RetryingTransactionHelper
{ {
private static final String MSG_READ_ONLY = "permissions.err_read_only";
private static Logger fgLogger = Logger.getLogger(RetryingTransactionHelper.class); private static Logger fgLogger = Logger.getLogger(RetryingTransactionHelper.class);
/** /**
@@ -74,6 +76,11 @@ public class RetryingTransactionHelper
*/ */
private int fMaxRetries; private int fMaxRetries;
/**
* Whether the the transactions may only be reads
*/
private boolean readOnly;
/** /**
* Random number generator for retry delays. * Random number generator for retry delays.
*/ */
@@ -119,6 +126,14 @@ public class RetryingTransactionHelper
fMaxRetries = maxRetries; fMaxRetries = maxRetries;
} }
/**
* Set whether this helper only supports read transactions.
*/
public void setReadOnly(boolean readOnly)
{
this.readOnly = readOnly;
}
/** /**
* Execute a callback in a transaction until it succeeds, fails * Execute a callback in a transaction until it succeeds, fails
* because of an error not the result of an optimistic locking failure, * because of an error not the result of an optimistic locking failure,
@@ -172,6 +187,10 @@ public class RetryingTransactionHelper
*/ */
public <R> R doInTransaction(RetryingTransactionCallback<R> cb, boolean readOnly, boolean newTransaction) public <R> R doInTransaction(RetryingTransactionCallback<R> cb, boolean readOnly, boolean newTransaction)
{ {
if (this.readOnly && !readOnly)
{
throw new AccessDeniedException(MSG_READ_ONLY);
}
// Track the last exception caught, so that we // Track the last exception caught, so that we
// can throw it if we run out of retries. // can throw it if we run out of retries.
RuntimeException lastException = null; RuntimeException lastException = null;
@@ -208,7 +227,9 @@ public class RetryingTransactionHelper
{ {
if (count != 0) if (count != 0)
{ {
fgLogger.debug("Transaction succeeded after " + count + " retries"); fgLogger.debug(
"Transaction succeeded after " + count +
" retries on thread " + Thread.currentThread().getName());
} }
} }
return result; return result;

View File

@@ -36,10 +36,11 @@ import org.springframework.transaction.TransactionDefinition;
* *
* @author David Caruana * @author David Caruana
*/ */
public class TransactionComponent implements TransactionService public class TransactionServiceImpl implements TransactionService
{ {
private PlatformTransactionManager transactionManager; private PlatformTransactionManager transactionManager;
private boolean readOnly = false; private boolean readOnly = false;
private int maxRetries = 20;
/** /**
* Set the transaction manager to use * Set the transaction manager to use
@@ -66,6 +67,17 @@ public class TransactionComponent implements TransactionService
return readOnly; return readOnly;
} }
/**
* Set the maximum number of retries that will be done by the
* {@link RetryingTransactionHelper transaction helper}.
*
* @param maxRetries the maximum transaction retries
*/
public void setMaxRetries(int maxRetries)
{
this.maxRetries = maxRetries;
}
/** /**
* @see org.springframework.transaction.TransactionDefinition#PROPAGATION_REQUIRED * @see org.springframework.transaction.TransactionDefinition#PROPAGATION_REQUIRED
*/ */
@@ -121,4 +133,16 @@ public class TransactionComponent implements TransactionService
TransactionDefinition.TIMEOUT_DEFAULT); TransactionDefinition.TIMEOUT_DEFAULT);
return txn; return txn;
} }
/**
* Creates a new helper instance. It can be reused.
*/
public RetryingTransactionHelper getRetryingTransactionHelper()
{
RetryingTransactionHelper helper = new RetryingTransactionHelper();
helper.setMaxRetries(maxRetries);
helper.setTransactionService(this);
helper.setReadOnly(readOnly);
return helper;
}
} }

View File

@@ -30,6 +30,8 @@ import javax.transaction.UserTransaction;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.util.ApplicationContextHelper; import org.alfresco.util.ApplicationContextHelper;
@@ -38,24 +40,24 @@ import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.PlatformTransactionManager;
/** /**
* @see org.alfresco.repo.transaction.TransactionComponent * @see org.alfresco.repo.transaction.TransactionServiceImpl
* *
* @author Derek Hulley * @author Derek Hulley
*/ */
public class TransactionComponentTest extends TestCase public class TransactionServiceImplTest extends TestCase
{ {
private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext(); private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
private PlatformTransactionManager transactionManager; private PlatformTransactionManager transactionManager;
private TransactionComponent transactionComponent; private TransactionServiceImpl transactionService;
private NodeService nodeService; private NodeService nodeService;
public void setUp() throws Exception public void setUp() throws Exception
{ {
transactionManager = (PlatformTransactionManager) ctx.getBean("transactionManager"); transactionManager = (PlatformTransactionManager) ctx.getBean("transactionManager");
transactionComponent = new TransactionComponent(); transactionService = new TransactionServiceImpl();
transactionComponent.setTransactionManager(transactionManager); transactionService.setTransactionManager(transactionManager);
transactionComponent.setAllowWrite(true); transactionService.setAllowWrite(true);
nodeService = (NodeService) ctx.getBean("dbNodeService"); nodeService = (NodeService) ctx.getBean("dbNodeService");
} }
@@ -63,12 +65,12 @@ public class TransactionComponentTest extends TestCase
public void testPropagatingTxn() throws Exception public void testPropagatingTxn() throws Exception
{ {
// start a transaction // start a transaction
UserTransaction txnOuter = transactionComponent.getUserTransaction(); UserTransaction txnOuter = transactionService.getUserTransaction();
txnOuter.begin(); txnOuter.begin();
String txnIdOuter = AlfrescoTransactionSupport.getTransactionId(); String txnIdOuter = AlfrescoTransactionSupport.getTransactionId();
// start a propagating txn // start a propagating txn
UserTransaction txnInner = transactionComponent.getUserTransaction(); UserTransaction txnInner = transactionService.getUserTransaction();
txnInner.begin(); txnInner.begin();
String txnIdInner = AlfrescoTransactionSupport.getTransactionId(); String txnIdInner = AlfrescoTransactionSupport.getTransactionId();
@@ -97,12 +99,12 @@ public class TransactionComponentTest extends TestCase
public void testNonPropagatingTxn() throws Exception public void testNonPropagatingTxn() throws Exception
{ {
// start a transaction // start a transaction
UserTransaction txnOuter = transactionComponent.getUserTransaction(); UserTransaction txnOuter = transactionService.getUserTransaction();
txnOuter.begin(); txnOuter.begin();
String txnIdOuter = AlfrescoTransactionSupport.getTransactionId(); String txnIdOuter = AlfrescoTransactionSupport.getTransactionId();
// start a propagating txn // start a propagating txn
UserTransaction txnInner = transactionComponent.getNonPropagatingUserTransaction(); UserTransaction txnInner = transactionService.getNonPropagatingUserTransaction();
txnInner.begin(); txnInner.begin();
String txnIdInner = AlfrescoTransactionSupport.getTransactionId(); String txnIdInner = AlfrescoTransactionSupport.getTransactionId();
@@ -119,9 +121,9 @@ public class TransactionComponentTest extends TestCase
public void testReadOnlyTxn() throws Exception public void testReadOnlyTxn() throws Exception
{ {
// start a read-only transaction // start a read-only transaction
transactionComponent.setAllowWrite(false); transactionService.setAllowWrite(false);
UserTransaction txn = transactionComponent.getUserTransaction(); UserTransaction txn = transactionService.getUserTransaction();
txn.begin(); txn.begin();
// do some writing // do some writing
@@ -135,8 +137,39 @@ public class TransactionComponentTest extends TestCase
} }
catch (InvalidDataAccessApiUsageException e) catch (InvalidDataAccessApiUsageException e)
{ {
@SuppressWarnings("unused")
int i = 0; int i = 0;
// expected // expected
} }
} }
public void testGetRetryingTransactionHelper()
{
RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>()
{
public Object execute() throws Throwable
{
return null;
}
};
assertFalse("Retriers must be new instances",
transactionService.getRetryingTransactionHelper() == transactionService.getRetryingTransactionHelper());
transactionService.setAllowWrite(true);
transactionService.getRetryingTransactionHelper().doInTransaction(callback, true);
transactionService.getRetryingTransactionHelper().doInTransaction(callback, false);
transactionService.setAllowWrite(false);
transactionService.getRetryingTransactionHelper().doInTransaction(callback, true);
try
{
transactionService.getRetryingTransactionHelper().doInTransaction(callback, false);
fail("Expected AccessDeniedException when starting to write to a read-only transaction service.");
}
catch (AccessDeniedException e)
{
// Expected
}
}
} }

View File

@@ -256,7 +256,7 @@ public class VersionServiceImplTest extends BaseVersionStoreTest
* Test revert * Test revert
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
public void xtestRevert() public void testRevert()
{ {
// Create a versionable node // Create a versionable node
NodeRef versionableNode = createNewVersionableNode(); NodeRef versionableNode = createNewVersionableNode();

View File

@@ -26,6 +26,7 @@ package org.alfresco.service.transaction;
import javax.transaction.UserTransaction; import javax.transaction.UserTransaction;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.service.NotAuditable; import org.alfresco.service.NotAuditable;
import org.alfresco.service.PublicService; import org.alfresco.service.PublicService;
@@ -96,4 +97,14 @@ public interface TransactionService
*/ */
@NotAuditable @NotAuditable
UserTransaction getNonPropagatingUserTransaction(boolean readOnly); UserTransaction getNonPropagatingUserTransaction(boolean readOnly);
/**
* Get the standard instance of the helper object that supports transaction retrying.
*
* @return
* Returns a helper object that executes units of work transactionally. The helper
* can be reused or altered as required.
*/
@NotAuditable
RetryingTransactionHelper getRetryingTransactionHelper();
} }