1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 }