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      	if (transactionManagerImpl == null) {
45              this.transactionManagerImpl = new TransactionManagerImpl(defaultTransactionTimeoutSeconds,
46                      transactionLog, resourceManagers);
47      	}
48          return transactionManagerImpl;
49      }
50  
51      public Class getObjectType() {
52          return TransactionManagerImpl.class;
53      }
54  
55      public boolean isSingleton() {
56          return true;
57      }
58  
59      /***
60       * Set the default transaction timeout in second.
61       */
62      public void setDefaultTransactionTimeoutSeconds(int timeout) {
63          defaultTransactionTimeoutSeconds = timeout;
64      }
65  
66      /***
67       * Set the transaction log for the transaction context manager.
68       */
69      public void setTransactionLog(TransactionLog log) {
70          transactionLog = log;
71      }
72  
73      public Collection getResourceManagers() {
74          return resourceManagers;
75      }
76  
77      /***
78       * Set the resource managers
79       */
80      public void setResourceManagers(Collection resourceManagers) {
81          this.resourceManagers = resourceManagers;
82      }
83  
84      public void afterPropertiesSet() throws Exception {
85          if (transactionLog == null) {
86              transactionLog = new UnrecoverableLog();
87          }
88      }
89  
90  }