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.connectiontracking.ConnectionTrackingCoordinator;
20  import org.apache.geronimo.transaction.context.TransactionContextManager;
21  import org.apache.geronimo.transaction.context.UserTransactionImpl;
22  import org.springframework.beans.factory.FactoryBean;
23  import org.springframework.beans.factory.InitializingBean;
24  
25  import javax.transaction.UserTransaction;
26  
27  /***
28   * This FactoryBean creates and configures the Geronimo implementation
29   * of the UserTransaction interface.
30   * <p/>
31   * This factory is based on the Geronimo Transaction Context Manager
32   * and Connection Tracking Coordinator.
33   *
34   * @author ttemplier
35   * @see UserTransactionImpl#setUp(TransactionContextManager, org.apache.geronimo.transaction.TrackedConnectionAssociator)
36   * @see UserTransactionImpl#setOnline(boolean)
37   */
38  public class UserTransactionFactoryBean implements FactoryBean, InitializingBean {
39  
40      private TransactionContextManager transactionContextManager;
41      private ConnectionTrackingCoordinator connectionTrackingCoordinator;
42  
43      private UserTransaction userTransaction;
44  
45      public Object getObject() throws Exception {
46          return userTransaction;
47      }
48  
49      public Class getObjectType() {
50          return UserTransaction.class;
51      }
52  
53      public boolean isSingleton() {
54          return true;
55      }
56  
57      /***
58       * Set the transaction context manager to configure the user transaction.
59       */
60      public void setTransactionContextManager(TransactionContextManager manager) {
61          transactionContextManager = manager;
62      }
63  
64      /***
65       * Set the connection tracking coordinator to configure the user transaction.
66       */
67      public void setConnectionTrackingCoordinator(ConnectionTrackingCoordinator coordinator) {
68          connectionTrackingCoordinator = coordinator;
69      }
70  
71      /***
72       * This method instanciates the Geronimo user transaction implementation
73       * and sets up it with the transaction context manager used and a connection
74       * tracking coordinator.
75       *
76       * It then sets the online property to true in order that the application
77       * can used it.
78       */
79      public void afterPropertiesSet() throws Exception {
80          this.userTransaction = new UserTransactionImpl();
81          ((UserTransactionImpl) this.userTransaction).setUp(transactionContextManager,
82                  connectionTrackingCoordinator);
83          ((UserTransactionImpl) this.userTransaction).setOnline(true);
84      }
85  
86  
87  }