|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| package org.objectledge.database; |
|
29 |
| |
|
30 |
| import java.sql.SQLException; |
|
31 |
| |
|
32 |
| import javax.sql.DataSource; |
|
33 |
| import javax.sql.XAConnection; |
|
34 |
| import javax.sql.XADataSource; |
|
35 |
| |
|
36 |
| import org.enhydra.jdbc.core.CoreDataSource; |
|
37 |
| import org.enhydra.jdbc.pool.StandardXAPoolDataSource; |
|
38 |
| import org.enhydra.jdbc.standard.StandardXADataSource; |
|
39 |
| import org.jcontainer.dna.Configuration; |
|
40 |
| import org.jcontainer.dna.ConfigurationException; |
|
41 |
| import org.objectledge.database.impl.DelegatingDataSource; |
|
42 |
| import org.objectledge.logging.LoggingConfigurator; |
|
43 |
| import org.picocontainer.Startable; |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| public class XaPoolDataSource extends DelegatingDataSource |
|
52 |
| implements XADataSource, Startable |
|
53 |
| { |
|
54 |
| private Transaction transaction; |
|
55 |
| private Configuration config; |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
688
| public XaPoolDataSource(Transaction transaction, Configuration config, LoggingConfigurator
|
|
67 |
| loggingConfigurator) |
|
68 |
| throws ConfigurationException, SQLException |
|
69 |
| { |
|
70 |
688
| super(getDataSource(transaction, config));
|
|
71 |
688
| this.transaction = transaction;
|
|
72 |
688
| this.config = config;
|
|
73 |
| } |
|
74 |
| |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
0
| public void start()
|
|
79 |
| { |
|
80 |
| |
|
81 |
| } |
|
82 |
| |
|
83 |
| |
|
84 |
| |
|
85 |
| |
|
86 |
688
| public void stop()
|
|
87 |
| { |
|
88 |
688
| ((CoreDataSource)getDelegate()).shutdown(true);
|
|
89 |
| } |
|
90 |
| |
|
91 |
| |
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
| |
|
98 |
| |
|
99 |
| |
|
100 |
688
| private static DataSource getDataSource(Transaction transaction, Configuration config)
|
|
101 |
| throws ConfigurationException, SQLException |
|
102 |
| { |
|
103 |
688
| StandardXADataSource xaDataSource = new StandardXADataSource();
|
|
104 |
688
| xaDataSource.setTransactionManager(transaction.getTransactionManager());
|
|
105 |
| |
|
106 |
688
| Configuration connectionConfig = config.getChild("connection");
|
|
107 |
688
| String driverName = connectionConfig.getChild("driver").getValue();
|
|
108 |
688
| String url = connectionConfig.getChild("url").getValue();
|
|
109 |
688
| String user = connectionConfig.getChild("user").getValue(null);
|
|
110 |
688
| String password = connectionConfig.getChild("password").getValue(null);
|
|
111 |
| |
|
112 |
688
| int loginTimeout = connectionConfig.getChild("login-timeout").getValueAsInteger(-1);
|
|
113 |
688
| int transactionIsolation = connectionConfig.
|
|
114 |
| getChild("transaction-isolation").getValueAsInteger(-1); |
|
115 |
688
| int preparedStmtCacheSize = connectionConfig.
|
|
116 |
| getChild("prepared-statement-cache-size").getValueAsInteger(-1); |
|
117 |
| |
|
118 |
688
| Configuration deadlockConfig = config.getChild("deadlock");
|
|
119 |
688
| long deadlockMaxWait = deadlockConfig.getChild("max-wait").getValueAsInteger(-1);
|
|
120 |
688
| long deadlockRetryWait = deadlockConfig.getChild("retry-wait").getValueAsInteger(-1);
|
|
121 |
| |
|
122 |
| |
|
123 |
688
| if(user != null)
|
|
124 |
| { |
|
125 |
688
| xaDataSource.setUser(user);
|
|
126 |
| } |
|
127 |
688
| if(password != null)
|
|
128 |
| { |
|
129 |
86
| xaDataSource.setPassword(password);
|
|
130 |
| } |
|
131 |
688
| if(loginTimeout != -1)
|
|
132 |
| { |
|
133 |
86
| xaDataSource.setLoginTimeout(loginTimeout);
|
|
134 |
| } |
|
135 |
| |
|
136 |
688
| xaDataSource.setDriverName(driverName);
|
|
137 |
688
| xaDataSource.setUrl(url);
|
|
138 |
688
| if(transactionIsolation != -1)
|
|
139 |
| { |
|
140 |
86
| xaDataSource.setTransactionIsolation(transactionIsolation);
|
|
141 |
| } |
|
142 |
| |
|
143 |
688
| if(preparedStmtCacheSize != -1)
|
|
144 |
| { |
|
145 |
86
| xaDataSource.setPreparedStmtCacheSize(preparedStmtCacheSize);
|
|
146 |
| } |
|
147 |
| |
|
148 |
688
| if(deadlockMaxWait != -1)
|
|
149 |
| { |
|
150 |
86
| xaDataSource.setDeadLockMaxWait(deadlockMaxWait);
|
|
151 |
| } |
|
152 |
688
| if(deadlockRetryWait != -1)
|
|
153 |
| { |
|
154 |
86
| xaDataSource.setDeadLockRetryWait(deadlockRetryWait);
|
|
155 |
| } |
|
156 |
688
| xaDataSource.setTransactionManager(transaction.getTransactionManager());
|
|
157 |
| |
|
158 |
| |
|
159 |
| |
|
160 |
688
| Configuration poolConfig = config.getChild("pool");
|
|
161 |
| |
|
162 |
688
| Configuration minSizeConfig = poolConfig.getChild("capacity").getChild("min");
|
|
163 |
688
| int minSize = minSizeConfig.getValueAsInteger(-1);
|
|
164 |
688
| Configuration maxSizeConfig = poolConfig.getChild("capacity")
|
|
165 |
| .getChild("max"); |
|
166 |
688
| int maxSize = maxSizeConfig.getValueAsInteger(-1);
|
|
167 |
688
| boolean gc = poolConfig.getChild("cleanup").
|
|
168 |
| getChild("gc").getValueAsBoolean(false); |
|
169 |
688
| int lifeTime = poolConfig.getChild("cleanup").
|
|
170 |
| getChild("unused-life-time").getValueAsInteger(-1); |
|
171 |
688
| int sleepTime = poolConfig.getChild("cleanup").
|
|
172 |
| getChild("interval").getValueAsInteger(-1); |
|
173 |
688
| int checkLevel = poolConfig.getChild("checking").
|
|
174 |
| getChild("level").getValueAsInteger(0); |
|
175 |
688
| String jdbcTestStatement = poolConfig.getChild("checking").
|
|
176 |
| getChild("statement").getValue(null); |
|
177 |
| |
|
178 |
688
| StandardXAPoolDataSource xaPoolDataSource = new StandardXAPoolDataSource(xaDataSource);
|
|
179 |
688
| xaPoolDataSource.setTransactionManager(transaction.getTransactionManager());
|
|
180 |
688
| xaPoolDataSource.setDataSource(xaDataSource);
|
|
181 |
| |
|
182 |
| |
|
183 |
688
| if(user != null)
|
|
184 |
| { |
|
185 |
688
| xaPoolDataSource.setUser(user);
|
|
186 |
| } |
|
187 |
688
| if(password != null)
|
|
188 |
| { |
|
189 |
86
| xaPoolDataSource.setPassword(password);
|
|
190 |
| } |
|
191 |
| |
|
192 |
688
| if(minSize != -1)
|
|
193 |
| { |
|
194 |
86
| try
|
|
195 |
| { |
|
196 |
86
| xaPoolDataSource.setMinSize(minSize);
|
|
197 |
| } |
|
198 |
| catch(Exception e) |
|
199 |
| { |
|
200 |
0
| throw new ConfigurationException("illegal minimum pool size",
|
|
201 |
| minSizeConfig.getPath(), minSizeConfig.getLocation(), e); |
|
202 |
| } |
|
203 |
| } |
|
204 |
688
| if(maxSize != -1)
|
|
205 |
| { |
|
206 |
86
| try
|
|
207 |
| { |
|
208 |
86
| xaPoolDataSource.setMaxSize(maxSize);
|
|
209 |
| } |
|
210 |
| catch(Exception e) |
|
211 |
| { |
|
212 |
0
| throw new ConfigurationException("illegal maximum pool size",
|
|
213 |
| maxSizeConfig.getPath(), maxSizeConfig.getLocation(), e); |
|
214 |
| } |
|
215 |
| } |
|
216 |
688
| xaPoolDataSource.setGC(gc);
|
|
217 |
688
| if(lifeTime != -1)
|
|
218 |
| { |
|
219 |
86
| xaPoolDataSource.setLifeTime(lifeTime);
|
|
220 |
| } |
|
221 |
688
| if(sleepTime != -1)
|
|
222 |
| { |
|
223 |
86
| xaPoolDataSource.setLifeTime(sleepTime);
|
|
224 |
| } |
|
225 |
688
| xaPoolDataSource.setCheckLevelObject(checkLevel);
|
|
226 |
688
| if(jdbcTestStatement != null)
|
|
227 |
| { |
|
228 |
86
| xaPoolDataSource.setJdbcTestStmt(jdbcTestStatement);
|
|
229 |
| } |
|
230 |
688
| return xaPoolDataSource;
|
|
231 |
| } |
|
232 |
| |
|
233 |
| |
|
234 |
| |
|
235 |
| |
|
236 |
86
| public XAConnection getXAConnection()
|
|
237 |
| throws SQLException |
|
238 |
| { |
|
239 |
86
| return ((XADataSource)getDelegate()).getXAConnection();
|
|
240 |
| } |
|
241 |
| |
|
242 |
| |
|
243 |
| |
|
244 |
| |
|
245 |
0
| public XAConnection getXAConnection(String user, String password)
|
|
246 |
| throws SQLException |
|
247 |
| { |
|
248 |
0
| return ((XADataSource)getDelegate()).getXAConnection(user, password);
|
|
249 |
| } |
|
250 |
| } |