Web Scripts: remove use of deprecated TransactionUtil.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5886 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana
2007-06-07 16:24:42 +00:00
parent 63cf2e1bfc
commit aa13da35dc
9 changed files with 44 additions and 48 deletions

View File

@@ -11,7 +11,7 @@
<property name="registry" ref="webscripts.registry" /> <property name="registry" ref="webscripts.registry" />
<property name="authenticationService" ref="authenticationService" /> <property name="authenticationService" ref="authenticationService" />
<property name="authorityService" ref="authorityService" /> <property name="authorityService" ref="authorityService" />
<property name="transactionService" ref="transactionComponent" /> <property name="transactionHelper" ref="retryingTransactionHelper" />
<property name="configService" ref="webClientConfigService" /> <property name="configService" ref="webClientConfigService" />
<property name="messages"> <property name="messages">
<bean class="org.springframework.context.support.ResourceBundleMessageSource"> <bean class="org.springframework.context.support.ResourceBundleMessageSource">

View File

@@ -56,7 +56,7 @@
</bean> </bean>
<bean id="webscripts.context" class="org.alfresco.web.scripts.WebScriptContext"> <bean id="webscripts.context" class="org.alfresco.web.scripts.WebScriptContext">
<property name="transactionService" ref="transactionComponent" /> <property name="transactionHelper" ref="retryingTransactionHelper" />
<property name="namespaceService" ref="namespaceService" /> <property name="namespaceService" ref="namespaceService" />
<property name="nodeService" ref="nodeService" /> <property name="nodeService" ref="nodeService" />
<property name="personService" ref="personService" /> <property name="personService" ref="personService" />

View File

@@ -40,10 +40,10 @@ import org.alfresco.config.ConfigService;
import org.alfresco.repo.security.authentication.AuthenticationException; import org.alfresco.repo.security.authentication.AuthenticationException;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.transaction.TransactionUtil; import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.cmr.security.AuthenticationService; import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.service.cmr.security.AuthorityService; import org.alfresco.service.cmr.security.AuthorityService;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.web.config.ServerConfigElement; import org.alfresco.web.config.ServerConfigElement;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
@@ -62,7 +62,7 @@ public class TestWebScriptServer
{ {
// dependencies // dependencies
protected AuthenticationService authenticationService; protected AuthenticationService authenticationService;
protected TransactionService transactionService; protected RetryingTransactionHelper retryingTransactionHelper;
protected AuthorityService authorityService; protected AuthorityService authorityService;
protected DeclarativeWebScriptRegistry registry; protected DeclarativeWebScriptRegistry registry;
protected ConfigService configService; protected ConfigService configService;
@@ -87,13 +87,11 @@ public class TestWebScriptServer
/** /**
* Sets the transaction service * Sets helper that provides transaction callbacks
*
* @param transactionService
*/ */
public void setTransactionService(TransactionService transactionService) public void setTransactionHelper(RetryingTransactionHelper retryingTransactionHelper)
{ {
this.transactionService = transactionService; this.retryingTransactionHelper = retryingTransactionHelper;
} }
/** /**
@@ -213,7 +211,7 @@ public class TestWebScriptServer
MockHttpServletRequest req = createRequest(method, uri); MockHttpServletRequest req = createRequest(method, uri);
MockHttpServletResponse res = new MockHttpServletResponse(); MockHttpServletResponse res = new MockHttpServletResponse();
WebScriptRuntime runtime = new WebScriptServletRuntime(registry, transactionService, authorityService, null, req, res, serverConfig); WebScriptRuntime runtime = new WebScriptServletRuntime(registry, retryingTransactionHelper, authorityService, null, req, res, serverConfig);
runtime.executeScript(); runtime.executeScript();
return res; return res;
@@ -238,7 +236,7 @@ public class TestWebScriptServer
} }
MockHttpServletResponse res = new MockHttpServletResponse(); MockHttpServletResponse res = new MockHttpServletResponse();
WebScriptRuntime runtime = new WebScriptServletRuntime(registry, transactionService, authorityService, null, req, res, serverConfig); WebScriptRuntime runtime = new WebScriptServletRuntime(registry, retryingTransactionHelper, authorityService, null, req, res, serverConfig);
runtime.executeScript(); runtime.executeScript();
return res; return res;
@@ -291,9 +289,9 @@ public class TestWebScriptServer
{ {
try try
{ {
TransactionUtil.executeInUserTransaction(transactionService, new TransactionUtil.TransactionWork<Object>() retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Object>()
{ {
public Object doWork() throws Throwable public Object execute() throws Exception
{ {
authenticationService.validate(username); authenticationService.validate(username);
return null; return null;

View File

@@ -28,14 +28,14 @@ import java.util.List;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.transaction.TransactionUtil; import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
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.service.cmr.search.SearchService; import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.cmr.security.PersonService; import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.AbstractLifecycleBean; import org.alfresco.util.AbstractLifecycleBean;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
@@ -54,7 +54,7 @@ public class WebScriptContext implements ApplicationContextAware, ApplicationLis
private ProcessorLifecycle lifecycle = new ProcessorLifecycle(); private ProcessorLifecycle lifecycle = new ProcessorLifecycle();
// dependencies // dependencies
private TransactionService transactionService; private RetryingTransactionHelper retryingTransactionHelper;
private NamespaceService namespaceService; private NamespaceService namespaceService;
private SearchService searchService; private SearchService searchService;
private NodeService nodeService; private NodeService nodeService;
@@ -87,13 +87,11 @@ public class WebScriptContext implements ApplicationContextAware, ApplicationLis
} }
/** /**
* Sets the transaction service * Sets helper that provides transaction callbacks
*
* @param transactionService
*/ */
public void setTransactionService(TransactionService transactionService) public void setTransactionHelper(RetryingTransactionHelper retryingTransactionHelper)
{ {
this.transactionService = transactionService; this.retryingTransactionHelper = retryingTransactionHelper;
} }
/** /**
@@ -174,10 +172,10 @@ public class WebScriptContext implements ApplicationContextAware, ApplicationLis
*/ */
protected void initContext() protected void initContext()
{ {
TransactionUtil.executeInUserTransaction(transactionService, new TransactionUtil.TransactionWork<Object>() retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Object>()
{ {
@SuppressWarnings("synthetic-access") @SuppressWarnings("synthetic-access")
public Object doWork() throws Exception public Object execute() throws Exception
{ {
List<NodeRef> refs = searchService.selectNodes(nodeService.getRootNode(companyHomeStore), companyHomePath, null, namespaceService, false); List<NodeRef> refs = searchService.selectNodes(nodeService.getRootNode(companyHomeStore), companyHomePath, null, namespaceService, false);
if (refs.size() != 1) if (refs.size() != 1)

View File

@@ -33,9 +33,9 @@ import javax.servlet.http.HttpServletResponse;
import org.alfresco.i18n.I18NUtil; import org.alfresco.i18n.I18NUtil;
import org.alfresco.repo.content.MimetypeMap; import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.transaction.TransactionUtil; import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.cmr.security.AuthorityService; import org.alfresco.service.cmr.security.AuthorityService;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.web.scripts.WebScriptDescription.RequiredAuthentication; import org.alfresco.web.scripts.WebScriptDescription.RequiredAuthentication;
import org.alfresco.web.scripts.WebScriptDescription.RequiredTransaction; import org.alfresco.web.scripts.WebScriptDescription.RequiredTransaction;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@@ -61,7 +61,7 @@ public abstract class WebScriptRuntime
/** Component Dependencies */ /** Component Dependencies */
private WebScriptRegistry registry; private WebScriptRegistry registry;
private TransactionService transactionService; private RetryingTransactionHelper retryingTransactionHelper;
private AuthorityService authorityService; private AuthorityService authorityService;
/** /**
@@ -70,10 +70,10 @@ public abstract class WebScriptRuntime
* @param registry web script registry * @param registry web script registry
* @param transactionService transaction service * @param transactionService transaction service
*/ */
public WebScriptRuntime(WebScriptRegistry registry, TransactionService transactionService, AuthorityService authorityService) public WebScriptRuntime(WebScriptRegistry registry, RetryingTransactionHelper transactionHelper, AuthorityService authorityService)
{ {
this.registry = registry; this.registry = registry;
this.transactionService = transactionService; this.retryingTransactionHelper = transactionHelper;
this.authorityService = authorityService; this.authorityService = authorityService;
} }
@@ -149,9 +149,9 @@ public abstract class WebScriptRuntime
else else
{ {
// encapsulate script within transaction // encapsulate script within transaction
TransactionUtil.TransactionWork<Object> work = new TransactionUtil.TransactionWork<Object>() RetryingTransactionCallback<Object> work = new RetryingTransactionCallback<Object>()
{ {
public Object doWork() throws Throwable public Object execute() throws Exception
{ {
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("Begin transaction: " + description.getRequiredTransaction()); logger.debug("Begin transaction: " + description.getRequiredTransaction());
@@ -167,11 +167,11 @@ public abstract class WebScriptRuntime
if (description.getRequiredTransaction() == RequiredTransaction.required) if (description.getRequiredTransaction() == RequiredTransaction.required)
{ {
TransactionUtil.executeInUserTransaction(transactionService, work); retryingTransactionHelper.doInTransaction(work);
} }
else else
{ {
TransactionUtil.executeInNonPropagatingUserTransaction(transactionService, work); retryingTransactionHelper.doInTransaction(work, false, true);
} }
} }
} }

View File

@@ -33,8 +33,8 @@ import javax.servlet.http.HttpServletResponse;
import org.alfresco.config.Config; import org.alfresco.config.Config;
import org.alfresco.config.ConfigService; import org.alfresco.config.ConfigService;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.service.cmr.security.AuthorityService; import org.alfresco.service.cmr.security.AuthorityService;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.web.config.ServerConfigElement; import org.alfresco.web.config.ServerConfigElement;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@@ -56,7 +56,7 @@ public class WebScriptServlet extends HttpServlet
// Component Dependencies // Component Dependencies
private DeclarativeWebScriptRegistry registry; private DeclarativeWebScriptRegistry registry;
private TransactionService transactionService; private RetryingTransactionHelper transactionHelper;
private AuthorityService authorityService; private AuthorityService authorityService;
private WebScriptServletAuthenticator authenticator; private WebScriptServletAuthenticator authenticator;
protected ConfigService configService; protected ConfigService configService;
@@ -71,7 +71,7 @@ public class WebScriptServlet extends HttpServlet
super.init(); super.init();
ApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext()); ApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
registry = (DeclarativeWebScriptRegistry)context.getBean("webscripts.registry"); registry = (DeclarativeWebScriptRegistry)context.getBean("webscripts.registry");
transactionService = (TransactionService)context.getBean("transactionComponent"); transactionHelper = (RetryingTransactionHelper)context.getBean("retryingTransactionHelper");
authorityService = (AuthorityService)context.getBean("authorityService"); authorityService = (AuthorityService)context.getBean("authorityService");
configService = (ConfigService)context.getBean("webClientConfigService"); configService = (ConfigService)context.getBean("webClientConfigService");
@@ -108,7 +108,7 @@ public class WebScriptServlet extends HttpServlet
res.setHeader("Cache-Control", "no-cache"); res.setHeader("Cache-Control", "no-cache");
res.setHeader("Pragma", "no-cache"); res.setHeader("Pragma", "no-cache");
WebScriptRuntime runtime = new WebScriptServletRuntime(registry, transactionService, authorityService, authenticator, req, res, serverConfig); WebScriptRuntime runtime = new WebScriptServletRuntime(registry, transactionHelper, authorityService, authenticator, req, res, serverConfig);
runtime.executeScript(); runtime.executeScript();
} }

View File

@@ -27,8 +27,8 @@ package org.alfresco.web.scripts;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.service.cmr.security.AuthorityService; import org.alfresco.service.cmr.security.AuthorityService;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.web.config.ServerConfigElement; import org.alfresco.web.config.ServerConfigElement;
import org.alfresco.web.scripts.WebScriptDescription.RequiredAuthentication; import org.alfresco.web.scripts.WebScriptDescription.RequiredAuthentication;
@@ -55,11 +55,11 @@ public class WebScriptServletRuntime extends WebScriptRuntime
* @param req * @param req
* @param res * @param res
*/ */
public WebScriptServletRuntime(WebScriptRegistry registry, TransactionService transactionService, public WebScriptServletRuntime(WebScriptRegistry registry, RetryingTransactionHelper transactionHelper,
AuthorityService authorityService, WebScriptServletAuthenticator authenticator, AuthorityService authorityService, WebScriptServletAuthenticator authenticator,
HttpServletRequest req, HttpServletResponse res, ServerConfigElement serverConfig) HttpServletRequest req, HttpServletResponse res, ServerConfigElement serverConfig)
{ {
super(registry, transactionService, authorityService); super(registry, transactionHelper, authorityService);
this.req = req; this.req = req;
this.res = res; this.res = res;
this.authenticator = authenticator; this.authenticator = authenticator;

View File

@@ -37,8 +37,8 @@ import javax.faces.event.ActionEvent;
import javax.faces.event.FacesEvent; import javax.faces.event.FacesEvent;
import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.service.cmr.security.AuthorityService; import org.alfresco.service.cmr.security.AuthorityService;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.web.scripts.DeclarativeWebScriptRegistry; import org.alfresco.web.scripts.DeclarativeWebScriptRegistry;
import org.alfresco.web.scripts.WebScriptMatch; import org.alfresco.web.scripts.WebScriptMatch;
import org.alfresco.web.scripts.WebScriptRegistry; import org.alfresco.web.scripts.WebScriptRegistry;
@@ -70,7 +70,7 @@ public class UIWebScript extends SelfRenderingComponent
private boolean scriptUrlModified = false; private boolean scriptUrlModified = false;
private WebScriptRegistry registry; private WebScriptRegistry registry;
private TransactionService txnService; private RetryingTransactionHelper txnHelper;
private AuthorityService authorityService; private AuthorityService authorityService;
/** /**
@@ -81,7 +81,7 @@ public class UIWebScript extends SelfRenderingComponent
WebApplicationContext ctx = FacesContextUtils.getRequiredWebApplicationContext( WebApplicationContext ctx = FacesContextUtils.getRequiredWebApplicationContext(
FacesContext.getCurrentInstance()); FacesContext.getCurrentInstance());
this.registry = (DeclarativeWebScriptRegistry)ctx.getBean("webscripts.registry"); this.registry = (DeclarativeWebScriptRegistry)ctx.getBean("webscripts.registry");
this.txnService = (TransactionService)ctx.getBean("transactionComponent"); this.txnHelper = (RetryingTransactionHelper)ctx.getBean("retryingTransactionHelper");
this.authorityService = (AuthorityService)ctx.getBean("authorityService"); this.authorityService = (AuthorityService)ctx.getBean("authorityService");
} }
@@ -228,7 +228,7 @@ public class UIWebScript extends SelfRenderingComponent
WebScriptJSFRuntime(FacesContext fc, String scriptUrl) WebScriptJSFRuntime(FacesContext fc, String scriptUrl)
{ {
super(registry, txnService, authorityService); super(registry, txnHelper, authorityService);
this.fc = fc; this.fc = fc;
this.scriptUrl = scriptUrl; this.scriptUrl = scriptUrl;
this.script = WebScriptURLRequest.splitURL(scriptUrl)[2]; this.script = WebScriptURLRequest.splitURL(scriptUrl)[2];

View File

@@ -39,8 +39,8 @@ import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse; import javax.portlet.RenderResponse;
import javax.portlet.WindowState; import javax.portlet.WindowState;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.service.cmr.security.AuthorityService; import org.alfresco.service.cmr.security.AuthorityService;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.web.scripts.DeclarativeWebScriptRegistry; import org.alfresco.web.scripts.DeclarativeWebScriptRegistry;
import org.alfresco.web.scripts.WebScript; import org.alfresco.web.scripts.WebScript;
import org.alfresco.web.scripts.WebScriptDescription; import org.alfresco.web.scripts.WebScriptDescription;
@@ -73,7 +73,7 @@ public class WebScriptPortlet implements Portlet
// Component Dependencies // Component Dependencies
protected DeclarativeWebScriptRegistry registry; protected DeclarativeWebScriptRegistry registry;
protected TransactionService transactionService; protected RetryingTransactionHelper transactionHelper;
protected AuthorityService authorityService; protected AuthorityService authorityService;
protected WebScriptPortletAuthenticator authenticator; protected WebScriptPortletAuthenticator authenticator;
@@ -87,7 +87,7 @@ public class WebScriptPortlet implements Portlet
PortletContext portletCtx = config.getPortletContext(); PortletContext portletCtx = config.getPortletContext();
WebApplicationContext ctx = (WebApplicationContext)portletCtx.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); WebApplicationContext ctx = (WebApplicationContext)portletCtx.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
registry = (DeclarativeWebScriptRegistry)ctx.getBean("webscripts.registry"); registry = (DeclarativeWebScriptRegistry)ctx.getBean("webscripts.registry");
transactionService = (TransactionService)ctx.getBean("transactionComponent"); transactionHelper = (RetryingTransactionHelper)ctx.getBean("retryingTransactionHelper");
authorityService = (AuthorityService)ctx.getBean("authorityService"); authorityService = (AuthorityService)ctx.getBean("authorityService");
authenticator = (WebScriptPortletAuthenticator)ctx.getBean("webscripts.authenticator.jsr168"); authenticator = (WebScriptPortletAuthenticator)ctx.getBean("webscripts.authenticator.jsr168");
} }
@@ -212,7 +212,7 @@ public class WebScriptPortlet implements Portlet
*/ */
public WebScriptPortalRuntime(RenderRequest req, RenderResponse res, String requestUrl) public WebScriptPortalRuntime(RenderRequest req, RenderResponse res, String requestUrl)
{ {
super(registry, transactionService, authorityService); super(registry, transactionHelper, authorityService);
this.req = req; this.req = req;
this.res = res; this.res = res;
this.requestUrlParts = WebScriptURLRequest.splitURL(requestUrl); this.requestUrlParts = WebScriptURLRequest.splitURL(requestUrl);