001 /*
002 * Copyright 2002-2005 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017 package org.jencks.factory;
018
019 import org.apache.geronimo.connector.outbound.connectionmanagerconfig.TransactionSupport;
020 import org.apache.geronimo.connector.outbound.connectionmanagerconfig.XATransactions;
021 import org.springframework.beans.factory.FactoryBean;
022 import org.springframework.beans.factory.InitializingBean;
023
024 /**
025 * This FactoryBean creates the xa transaction strategy for the
026 * JCA connection manager used.
027 * <p/>
028 * This class can be injected in the ConnectionManagerFactoryBean to
029 * configure the ConnectionManager instance returned.
030 *
031 * @author Thierry Templier
032 * @see ConnectionManagerFactoryBean#setTransactionSupport(TransactionSupport)
033 */
034 public class XATransactionFactoryBean implements FactoryBean, InitializingBean {
035
036 private boolean useTransactionCaching;
037 private boolean useThreadCaching;
038
039 private TransactionSupport transactionSupport;
040
041 public Object getObject() throws Exception {
042 return transactionSupport;
043 }
044
045 public Class getObjectType() {
046 return TransactionSupport.class;
047 }
048
049 public boolean isSingleton() {
050 return true;
051 }
052
053 /**
054 * Set the useThreadCaching property to allow the ConnectionManager to
055 * cache connections for a thread.
056 */
057 public void setUseThreadCaching(boolean useThreadCaching) {
058 this.useThreadCaching = useThreadCaching;
059 }
060
061 /**
062 * Set the useTransactionCaching property to allow the ConnectionManager to
063 * cache connections for the current transaction.
064 * <p/>
065 * This allows connections to be used several times in the same transaction.
066 * So it prevents the connection to be enlisted several times in the
067 * current transaction.
068 */
069 public void setUseTransactionCaching(boolean useTransactionCaching) {
070 this.useTransactionCaching = useTransactionCaching;
071 }
072
073 /**
074 * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
075 */
076 public void afterPropertiesSet() throws Exception {
077 this.transactionSupport = new XATransactions(useTransactionCaching, useThreadCaching);
078 }
079
080 }