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