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.connector.outbound.connectionmanagerconfig.TransactionSupport;
20  import org.apache.geronimo.connector.outbound.connectionmanagerconfig.XATransactions;
21  import org.springframework.beans.factory.FactoryBean;
22  import org.springframework.beans.factory.InitializingBean;
23  
24  /***
25   * This FactoryBean creates the xa transaction strategy for the
26   * JCA connection manager used.
27   * <p/>
28   * This class can be injected in the ConnectionManagerFactoryBean to
29   * configure the ConnectionManager instance returned.
30   *
31   * @author Thierry Templier
32   * @see ConnectionManagerFactoryBean#setTransactionSupport(TransactionSupport)
33   */
34  public class XATransactionFactoryBean implements FactoryBean, InitializingBean {
35  
36      private boolean useTransactionCaching;
37      private boolean useThreadCaching;
38  
39      private TransactionSupport transactionSupport;
40  
41      public Object getObject() throws Exception {
42          return transactionSupport;
43      }
44  
45      public Class getObjectType() {
46          return TransactionSupport.class;
47      }
48  
49      public boolean isSingleton() {
50          return true;
51      }
52  
53      /***
54       * Set the useThreadCaching property to allow the ConnectionManager to
55       * cache connections for a thread.
56       */
57      public void setUseThreadCaching(boolean useThreadCaching) {
58          this.useThreadCaching = useThreadCaching;
59      }
60  
61      /***
62       * Set the useTransactionCaching property to allow the ConnectionManager to
63       * cache connections for the current transaction.
64       * <p/>
65       * This allows connections to be used several times in the same transaction.
66       * So it prevents the connection to be enlisted several times in the
67       * current transaction.
68       */
69      public void setUseTransactionCaching(boolean useTransactionCaching) {
70          this.useTransactionCaching = useTransactionCaching;
71      }
72  
73      /***
74       * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
75       */
76      public void afterPropertiesSet() throws Exception {
77          this.transactionSupport = new XATransactions(useTransactionCaching, useThreadCaching);
78      }
79  
80  }