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.GenericConnectionManager;
20 import org.apache.geronimo.connector.outbound.connectionmanagerconfig.NoPool;
21 import org.apache.geronimo.connector.outbound.connectionmanagerconfig.NoTransactions;
22 import org.apache.geronimo.connector.outbound.connectionmanagerconfig.PoolingSupport;
23 import org.apache.geronimo.connector.outbound.connectionmanagerconfig.TransactionSupport;
24 import org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTracker;
25 import org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTrackingCoordinator;
26 import org.apache.geronimo.security.bridge.RealmBridge;
27 import org.apache.geronimo.transaction.context.TransactionContextManager;
28 import org.springframework.beans.factory.FactoryBean;
29 import org.springframework.beans.factory.InitializingBean;
30
31 import javax.resource.spi.ConnectionManager;
32 import javax.security.auth.Subject;
33 import javax.security.auth.login.LoginException;
34
35 /***
36 * This FactoryBean creates a local JCA connection factory outside
37 * a J2EE application server.
38 * <p/>
39 * The connection manager will be then injected in the
40 * LocalConnectionFactoryBean, class of the JCA support of Spring.
41 *
42 * @author Thierry Templier
43 * @see org.springframework.jca.support.LocalConnectionFactoryBean#setConnectionManager(ConnectionManager)
44 * @see NoTransactionFactoryBean
45 * @see LocalTransactionFactoryBean
46 * @see XATransactionFactoryBean
47 * @see PartitionedPoolFactoryBean
48 * @see SinglePoolFactoryBean
49 */
50 public class ConnectionManagerFactoryBean implements FactoryBean, InitializingBean {
51
52 private TransactionSupport transactionSupport;
53 private PoolingSupport poolingSupport;
54 private RealmBridge realmBridge;
55 private TransactionContextManager transactionContextManager;
56 private ConnectionTracker connectionTracker;
57
58 private ConnectionManager connectionManager;
59
60 public Object getObject() throws Exception {
61 return connectionManager;
62 }
63
64 public Class getObjectType() {
65 return ConnectionManager.class;
66 }
67
68 public boolean isSingleton() {
69 return true;
70 }
71
72 /***
73 * Set the pooling support for the Geronimo Connection Manager.
74 * Geronimo provides two kinds of pool: single and partitioned.
75 *
76 * @see org.apache.geronimo.connector.outbound.connectionmanagerconfig.SinglePool
77 * @see org.apache.geronimo.connector.outbound.connectionmanagerconfig.PartitionedPool
78 */
79 public void setPoolingSupport(PoolingSupport support) {
80 poolingSupport = support;
81 }
82
83 /***
84 * Set the realm bridge for the Geronimo Connection Manager. This
85 * mechnism allows the application to map the application subject
86 * with the subject used by the EIS.
87 */
88 public void setRealmBridge(RealmBridge bridge) {
89 realmBridge = bridge;
90 }
91
92 /***
93 * Set the transaction context manager for the Geronimo Connection Manager.
94 */
95 public void setTransactionContextManager(TransactionContextManager manager) {
96 transactionContextManager = manager;
97 }
98
99 /***
100 * Set the transaction support for the Geronimo Connection Manager.
101 * Geronimo provides in this case three kinds of support like the
102 * JCA specification: no transaction, local transactions, XA transactions.
103 *
104 * @see NoTransactions
105 * @see org.apache.geronimo.connector.outbound.connectionmanagerconfig.LocalTransactions
106 * @see org.apache.geronimo.connector.outbound.connectionmanagerconfig.XATransactions
107 */
108 public void setTransactionSupport(TransactionSupport support) {
109 transactionSupport = support;
110 }
111
112 /***
113 * Set the connection tracker for the Geronimo Connection Manager.
114 */
115 public void setConnectionTracker(ConnectionTracker tracker) {
116 connectionTracker = tracker;
117 }
118
119 /***
120 * This method checks all the needed parameters to construct
121 * the Geronimo connection manager which is implemented by the
122 * GenericConnectionManager class.
123 * If the transaction support property is not set, the method
124 * configures the connection manager with the no transaction value.
125 * If the pooling support property is not set, the method
126 * configures the connection manager with the no pool value.
127 * If the realm bridge is not set, the method configure
128 * the connection manager with an identity realm bridge.
129 * @see GenericConnectionManager
130 */
131 public void afterPropertiesSet() throws Exception {
132
133 if (this.transactionSupport == null) {
134
135 this.transactionSupport = NoTransactions.INSTANCE;
136 }
137 if (this.poolingSupport == null) {
138
139 this.poolingSupport = new NoPool();
140 }
141 if (this.realmBridge == null) {
142
143 this.realmBridge = new RealmBridge() {
144 public Subject mapSubject(Subject subject) throws LoginException {
145 return subject;
146 }
147 };
148 }
149 if (this.connectionTracker == null) {
150
151 this.connectionTracker = new ConnectionTrackingCoordinator();
152 }
153
154
155 this.connectionManager = new GenericConnectionManager(this.transactionSupport, this.poolingSupport,
156 this.realmBridge, this.connectionTracker, this.transactionContextManager,
157 getClass().getName(), getClass().getClassLoader());
158 }
159
160 }