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">
<property name="transactionService">
<ref bean="transactionComponent"/>
<ref bean="transactionService"/>
</property>
<property name="authenticationComponent">
<ref bean="AuthenticationComponent"/>

View File

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

View File

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

View File

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

View File

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

View File

@@ -7,3 +7,5 @@ server.transaction.mode.readOnly=PROPAGATION_REQUIRED, readOnly
#server.transaction.allow-writes=false
server.transaction.mode.default=PROPAGATION_REQUIRED
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">
<property name="transactionService">
<ref bean="transactionComponent"/>
<ref bean="transactionService"/>
</property>
<property name="nodeService">
<ref bean="nodeService"/>
@@ -203,7 +203,7 @@
<bean id="storeImporter" class="org.alfresco.repo.importer.ImporterBootstrap" abstract="true">
<property name="transactionService">
<ref bean="transactionComponent"/>
<ref bean="transactionService"/>
</property>
<property name="nodeService">
<ref bean="nodeService"/>

View File

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

View File

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

View File

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

View File

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

View File

@@ -8,7 +8,7 @@
<!-- -->
<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="workflowService" ref="WorkflowService" />
<property name="dictionaryDAO" ref="dictionaryDAO"/>
@@ -36,7 +36,7 @@
<property name="namespaceService" ref="namespaceService"/>
<property name="personService" ref="PersonService"/>
<property name="authorityDAO" ref="authorityDAO"/>
<property name="transactionService" ref="transactionComponent"/>
<property name="transactionService" ref="transactionService"/>
<property name="fileFolderService" ref="FileFolderService"/>
</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.security.authentication.AuthenticationComponent;
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.TransactionWork;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
@@ -72,7 +72,7 @@ public abstract class AbstractReindexComponent implements IndexRecovery
private AuthenticationComponent authenticationComponent;
/** provides transactions to atomically index each missed transaction */
protected TransactionComponent transactionService;
protected TransactionServiceImpl transactionService;
/** the component to index the node hierarchy */
protected Indexer indexer;
/** 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
*/
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.impl.lucene.fts.FullTextSearchIndexer;
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.TransactionWork;
import org.alfresco.service.ServiceRegistry;
@@ -89,7 +89,7 @@ public class IndexRemoteTransactionTrackerTest extends TestCase
indexTracker.setNodeDaoService(nodeDaoService);
indexTracker.setNodeService(nodeService);
indexTracker.setSearcher(searchService);
indexTracker.setTransactionComponent((TransactionComponent)transactionService);
indexTracker.setTransactionService((TransactionServiceImpl)transactionService);
// authenticate
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.fts.FullTextSearchIndexer;
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.cmr.model.FileFolderService;
import org.alfresco.service.cmr.repository.ContentData;
@@ -91,7 +91,7 @@ public class MissingContentReindexComponentTest extends TestCase
reindexer.setNodeDaoService(nodeDaoService);
reindexer.setNodeService(nodeService);
reindexer.setSearcher(searchService);
reindexer.setTransactionComponent((TransactionComponent)transactionService);
reindexer.setTransactionService((TransactionServiceImpl)transactionService);
// authenticate
authenticationComponent.setSystemUserAsCurrentUser();

View File

@@ -76,4 +76,13 @@ public class DummyTransactionService implements TransactionService
{
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.ExceptionStackUtil;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.service.transaction.TransactionService;
import org.apache.log4j.Logger;
import org.hibernate.StaleObjectStateException;
@@ -48,6 +49,7 @@ import org.springframework.dao.DeadlockLoserDataAccessException;
*/
public class RetryingTransactionHelper
{
private static final String MSG_READ_ONLY = "permissions.err_read_only";
private static Logger fgLogger = Logger.getLogger(RetryingTransactionHelper.class);
/**
@@ -74,6 +76,11 @@ public class RetryingTransactionHelper
*/
private int fMaxRetries;
/**
* Whether the the transactions may only be reads
*/
private boolean readOnly;
/**
* Random number generator for retry delays.
*/
@@ -119,6 +126,14 @@ public class RetryingTransactionHelper
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
* 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)
{
if (this.readOnly && !readOnly)
{
throw new AccessDeniedException(MSG_READ_ONLY);
}
// Track the last exception caught, so that we
// can throw it if we run out of retries.
RuntimeException lastException = null;
@@ -208,7 +227,9 @@ public class RetryingTransactionHelper
{
if (count != 0)
{
fgLogger.debug("Transaction succeeded after " + count + " retries");
fgLogger.debug(
"Transaction succeeded after " + count +
" retries on thread " + Thread.currentThread().getName());
}
}
return result;

View File

@@ -36,10 +36,11 @@ import org.springframework.transaction.TransactionDefinition;
*
* @author David Caruana
*/
public class TransactionComponent implements TransactionService
public class TransactionServiceImpl implements TransactionService
{
private PlatformTransactionManager transactionManager;
private boolean readOnly = false;
private int maxRetries = 20;
/**
* Set the transaction manager to use
@@ -65,6 +66,17 @@ public class TransactionComponent implements TransactionService
{
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
@@ -121,4 +133,16 @@ public class TransactionComponent implements TransactionService
TransactionDefinition.TIMEOUT_DEFAULT);
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 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.StoreRef;
import org.alfresco.util.ApplicationContextHelper;
@@ -38,24 +40,24 @@ import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.transaction.PlatformTransactionManager;
/**
* @see org.alfresco.repo.transaction.TransactionComponent
* @see org.alfresco.repo.transaction.TransactionServiceImpl
*
* @author Derek Hulley
*/
public class TransactionComponentTest extends TestCase
public class TransactionServiceImplTest extends TestCase
{
private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
private PlatformTransactionManager transactionManager;
private TransactionComponent transactionComponent;
private TransactionServiceImpl transactionService;
private NodeService nodeService;
public void setUp() throws Exception
{
transactionManager = (PlatformTransactionManager) ctx.getBean("transactionManager");
transactionComponent = new TransactionComponent();
transactionComponent.setTransactionManager(transactionManager);
transactionComponent.setAllowWrite(true);
transactionService = new TransactionServiceImpl();
transactionService.setTransactionManager(transactionManager);
transactionService.setAllowWrite(true);
nodeService = (NodeService) ctx.getBean("dbNodeService");
}
@@ -63,12 +65,12 @@ public class TransactionComponentTest extends TestCase
public void testPropagatingTxn() throws Exception
{
// start a transaction
UserTransaction txnOuter = transactionComponent.getUserTransaction();
UserTransaction txnOuter = transactionService.getUserTransaction();
txnOuter.begin();
String txnIdOuter = AlfrescoTransactionSupport.getTransactionId();
// start a propagating txn
UserTransaction txnInner = transactionComponent.getUserTransaction();
UserTransaction txnInner = transactionService.getUserTransaction();
txnInner.begin();
String txnIdInner = AlfrescoTransactionSupport.getTransactionId();
@@ -97,12 +99,12 @@ public class TransactionComponentTest extends TestCase
public void testNonPropagatingTxn() throws Exception
{
// start a transaction
UserTransaction txnOuter = transactionComponent.getUserTransaction();
UserTransaction txnOuter = transactionService.getUserTransaction();
txnOuter.begin();
String txnIdOuter = AlfrescoTransactionSupport.getTransactionId();
// start a propagating txn
UserTransaction txnInner = transactionComponent.getNonPropagatingUserTransaction();
UserTransaction txnInner = transactionService.getNonPropagatingUserTransaction();
txnInner.begin();
String txnIdInner = AlfrescoTransactionSupport.getTransactionId();
@@ -119,9 +121,9 @@ public class TransactionComponentTest extends TestCase
public void testReadOnlyTxn() throws Exception
{
// start a read-only transaction
transactionComponent.setAllowWrite(false);
transactionService.setAllowWrite(false);
UserTransaction txn = transactionComponent.getUserTransaction();
UserTransaction txn = transactionService.getUserTransaction();
txn.begin();
// do some writing
@@ -135,8 +137,39 @@ public class TransactionComponentTest extends TestCase
}
catch (InvalidDataAccessApiUsageException e)
{
@SuppressWarnings("unused")
int i = 0;
// 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
*/
@SuppressWarnings("unused")
public void xtestRevert()
public void testRevert()
{
// Create a versionable node
NodeRef versionableNode = createNewVersionableNode();

View File

@@ -26,6 +26,7 @@ package org.alfresco.service.transaction;
import javax.transaction.UserTransaction;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.service.NotAuditable;
import org.alfresco.service.PublicService;
@@ -96,4 +97,14 @@ public interface TransactionService
*/
@NotAuditable
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();
}