View Javadoc

1   package com.atlassian.sal.core.transaction;
2   
3   import com.atlassian.sal.api.transaction.TransactionCallback;
4   import com.atlassian.sal.api.transaction.TransactionTemplate;
5   import com.atlassian.sal.spi.HostContextAccessor;
6   
7   /**
8    * This provides a default implementation that delegates to the underlying host context accessor
9    */
10  public class HostContextTransactionTemplate implements TransactionTemplate
11  {
12      private final HostContextAccessor hostContentAccessor;
13  
14      public HostContextTransactionTemplate(HostContextAccessor hostContentAccessor)
15      {
16          this.hostContentAccessor = hostContentAccessor;
17      }
18  
19      public Object execute(final TransactionCallback action)
20      {
21          return hostContentAccessor.doInTransaction(new HostContextAccessor.HostTransactionCallback() {
22  
23              public Object doInTransaction()
24              {
25                  return action.doInTransaction();
26              }
27          });
28      }
29  }