View Javadoc

1   /**
2    * Copyright 2005-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.ken.util;
17  
18  import java.util.concurrent.Callable;
19  
20  import org.springframework.transaction.TransactionStatus;
21  import org.springframework.transaction.support.TransactionCallback;
22  import org.springframework.transaction.support.TransactionTemplate;
23  
24  /**
25   * A Callable that performs work within a transaction and returns the
26   * TransactionCallback's result
27   * @author Kuali Rice Team (rice.collab@kuali.org)
28   */
29  public class TransactionedCallable implements Callable, TransactionCallback {
30      private TransactionTemplate txTemplate;
31      private TransactionCallback callback;
32      
33      /**
34       * Constructs a TransactionedCallable.java.
35       * @param txTemplate
36       */
37      public TransactionedCallable(TransactionTemplate txTemplate) {
38          this.txTemplate = txTemplate;
39      }
40  
41      /**
42       * Constructs a TransactionedCallable.java.
43       * @param txTemplate
44       * @param callback
45       */
46      public TransactionedCallable(TransactionTemplate txTemplate, TransactionCallback callback) {
47          this.txTemplate = txTemplate;
48          this.callback = callback;
49      }
50  
51      /**
52       * @see java.util.concurrent.Callable#call()
53       */
54      public Object call() throws Exception {
55          TransactionCallback cb;
56          if (callback != null) {
57              cb = callback;
58          } else {
59              cb = this;
60          }
61          return txTemplate.execute(cb);
62      }
63  
64      /**
65       * @see org.springframework.transaction.support.TransactionCallback#doInTransaction(org.springframework.transaction.TransactionStatus)
66       */
67      public Object doInTransaction(TransactionStatus txStatus) {
68          return null;
69      }
70  }