cancel
Showing results for 
Search instead for 
Did you mean: 

Why AuthenticationUtil.runAs() ?

mohammed_amr
Champ in-the-making
Champ in-the-making
Question for all,

When i'm trying to locking a node for edit its properties, the lock was throw an exception as well as there is no User Context.

To set the user context i write the following snipe of code

      AuthenticationUtil.runAs(new RunAsWork<String>(){
         public String doWork()throws Exception{
            return doProcess();
         }
      }, AuthenticationUtil.getSystemUserName());

and in the doProcess method i put the

RetryingTransactionCallback<String> callback = new RetryingTransactionCallback<String>() {
         public String execute() throws Throwable {
                        // My Business Code
}

And i need to ask

- Why i need to use AuthenticationUtil.runAs() to put the user context for the locking operation ?
   - Is to gain user context, or there are another several reasons ?
- Why i need to use RetryingTransactionCallback for put my business development lines ?
  - Is for retrying the action, even if the action failed for locking as example, or there are other reasons ?
Your advise is highly appreciated.

Mohammed Amr
Senior System Developer
Digital Series Co.
1 REPLY 1

mrogers
Star Contributor
Star Contributor
Why indeed!  I agree that the lock service is a little tricky to use, in fact I raised a JIRA enhancement request to rework it.   You could vote for it if you agree.

As for your second point all code within alfresco needs to be within a retrying transaction handler.    For performance reasons Alfresco uses optimistic locking which in general means that everything needs to be retried after a relativly rare concurrency error.   The good news is that the RetryingTransactionHandler does this for you and most of the interfaces, in particular web scripts, already automatically retry. http://en.wikipedia.org/wiki/Optimistic_concurrency_control
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.