View Javadoc

1   /*
2    * Copyright 2002-2005 the original author or authors.
3    *
4    * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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  
17  package org.jencks.factory;
18  
19  import org.apache.geronimo.transaction.log.UnrecoverableLog;
20  import org.apache.geronimo.transaction.manager.TransactionLog;
21  import org.apache.geronimo.transaction.manager.TransactionManagerImpl;
22  import org.springframework.beans.factory.FactoryBean;
23  import org.springframework.beans.factory.InitializingBean;
24  
25  import java.util.Collection;
26  
27  /***
28   * This FactoryBean creates and configures the Geronimo implementation
29   * of the TransactionManager interface.
30   *
31   * @author Thierry Templier
32   * @see UnrecoverableLog
33   * @see org.apache.geronimo.transaction.log.HOWLLog
34   */
35  public class TransactionManagerFactoryBean implements FactoryBean, InitializingBean {
36  
37      private int defaultTransactionTimeoutSeconds = 600;
38      private TransactionLog transactionLog;
39      private Collection resourceManagers;
40  
41      private TransactionManagerImpl transactionManagerImpl;
42  
43      public Object getObject() throws Exception {
44          return transactionManagerImpl;
45      }
46  
47      public Class getObjectType() {
48          return TransactionManagerImpl.class;
49      }
50  
51      public boolean isSingleton() {
52          return true;
53      }
54  
55      /***
56       * Set the default transaction timeout in second.
57       */
58      public void setDefaultTransactionTimeoutSeconds(int timeout) {
59          defaultTransactionTimeoutSeconds = timeout;
60      }
61  
62      /***
63       * Set the transaction log for the transaction context manager.
64       */
65      public void setTransactionLog(TransactionLog log) {
66          transactionLog = log;
67      }
68  
69      public Collection getResourceManagers() {
70          return resourceManagers;
71      }
72  
73      /***
74       * Set the resource managers
75       */
76      public void setResourceManagers(Collection resourceManagers) {
77          this.resourceManagers = resourceManagers;
78      }
79  
80      public void afterPropertiesSet() throws Exception {
81          if (transactionLog == null) {
82              transactionLog = new UnrecoverableLog();
83          }
84          this.transactionManagerImpl = new TransactionManagerImpl(defaultTransactionTimeoutSeconds,
85                  transactionLog, resourceManagers);
86      }
87  
88  }