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.transaction.log.UnrecoverableLog; 020 import org.apache.geronimo.transaction.manager.TransactionLog; 021 import org.apache.geronimo.transaction.manager.TransactionManagerImpl; 022 import org.springframework.beans.factory.FactoryBean; 023 import org.springframework.beans.factory.InitializingBean; 024 025 import java.util.Collection; 026 027 /** 028 * This FactoryBean creates and configures the Geronimo implementation 029 * of the TransactionManager interface. 030 * 031 * @author Thierry Templier 032 * @see UnrecoverableLog 033 * @see org.apache.geronimo.transaction.log.HOWLLog 034 */ 035 public class TransactionManagerFactoryBean implements FactoryBean, InitializingBean { 036 037 private int defaultTransactionTimeoutSeconds = 600; 038 private TransactionLog transactionLog; 039 private Collection resourceManagers; 040 041 private TransactionManagerImpl transactionManagerImpl; 042 043 public Object getObject() throws Exception { 044 if (transactionManagerImpl == null) { 045 this.transactionManagerImpl = new TransactionManagerImpl(defaultTransactionTimeoutSeconds, 046 transactionLog, resourceManagers); 047 } 048 return transactionManagerImpl; 049 } 050 051 public Class getObjectType() { 052 return TransactionManagerImpl.class; 053 } 054 055 public boolean isSingleton() { 056 return true; 057 } 058 059 /** 060 * Set the default transaction timeout in second. 061 */ 062 public void setDefaultTransactionTimeoutSeconds(int timeout) { 063 defaultTransactionTimeoutSeconds = timeout; 064 } 065 066 /** 067 * Set the transaction log for the transaction context manager. 068 */ 069 public void setTransactionLog(TransactionLog log) { 070 transactionLog = log; 071 } 072 073 public Collection getResourceManagers() { 074 return resourceManagers; 075 } 076 077 /** 078 * Set the resource managers 079 */ 080 public void setResourceManagers(Collection resourceManagers) { 081 this.resourceManagers = resourceManagers; 082 } 083 084 public void afterPropertiesSet() throws Exception { 085 if (transactionLog == null) { 086 transactionLog = new UnrecoverableLog(); 087 } 088 } 089 090 }