View Javadoc
1   package org.kuali.ole.docstore.engine.service;
2   
3   import org.kuali.ole.docstore.common.document.BibTree;
4   import org.kuali.ole.docstore.engine.service.storage.DocstoreRDBMSStorageService;
5   import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
6   import org.springframework.transaction.PlatformTransactionManager;
7   import org.springframework.transaction.TransactionStatus;
8   import org.springframework.transaction.support.TransactionCallback;
9   import org.springframework.transaction.support.TransactionTemplate;
10  
11  import javax.servlet.ServletException;
12  import java.io.IOException;
13  import java.util.concurrent.Callable;
14  
15  /**
16   * Created by pvsubrah on 5/26/15.
17   */
18  public class BibTreeProcessor implements Callable {
19      private BibTree bibTree;
20      private PlatformTransactionManager transactionManager;
21  
22      public BibTreeProcessor(BibTree bibTree) {
23          this.bibTree = bibTree;
24      }
25  
26      @Override
27      public Object call() throws Exception {
28          final BibTree localBibTree = this.bibTree;
29          final TransactionTemplate template = new TransactionTemplate(getTransactionManager());
30          try {
31              template.execute(new TransactionCallback<Object>() {
32                  @Override
33                  public Object doInTransaction(TransactionStatus status) {
34                      new DocstoreRDBMSStorageService().processBibTree(localBibTree);
35                      return localBibTree;
36  
37                  }
38              });
39          } catch (RuntimeException ex) {
40              if (ex.getCause() instanceof IOException) {
41                  throw (IOException) ex.getCause();
42              } else if (ex.getCause() instanceof ServletException) {
43                  throw (ServletException) ex.getCause();
44              }
45              throw ex;
46          } finally {
47              bibTree = null;
48              this.transactionManager = null;
49  
50          }
51          return localBibTree;
52      }
53  
54      public PlatformTransactionManager getTransactionManager() {
55          if (transactionManager == null) {
56              transactionManager = GlobalResourceLoader.getService("transactionManager");
57          }
58          return this.transactionManager;
59      }
60  }