Commit b7462d8977faf1d03fd7830595f8cfdb8569c0c9
1 parent
83c51577
Exists in
master
Serialização do BasicDataSource via proxy
Showing
2 changed files
with
354 additions
and
13 deletions
Show diff stats
impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/producer/DataSourceProducer.java
@@ -15,12 +15,12 @@ import javax.naming.Context; | @@ -15,12 +15,12 @@ import javax.naming.Context; | ||
15 | import javax.naming.InitialContext; | 15 | import javax.naming.InitialContext; |
16 | import javax.sql.DataSource; | 16 | import javax.sql.DataSource; |
17 | 17 | ||
18 | -import org.apache.commons.dbcp.BasicDataSource; | ||
19 | import org.slf4j.Logger; | 18 | import org.slf4j.Logger; |
20 | 19 | ||
21 | import br.gov.frameworkdemoiselle.DemoiselleException; | 20 | import br.gov.frameworkdemoiselle.DemoiselleException; |
22 | import br.gov.frameworkdemoiselle.annotation.Name; | 21 | import br.gov.frameworkdemoiselle.annotation.Name; |
23 | import br.gov.frameworkdemoiselle.internal.configuration.JDBCConfig; | 22 | import br.gov.frameworkdemoiselle.internal.configuration.JDBCConfig; |
23 | +import br.gov.frameworkdemoiselle.transaction.BasicDataSourceProxy; | ||
24 | import br.gov.frameworkdemoiselle.util.Beans; | 24 | import br.gov.frameworkdemoiselle.util.Beans; |
25 | import br.gov.frameworkdemoiselle.util.ResourceBundle; | 25 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
26 | 26 | ||
@@ -117,18 +117,7 @@ public class DataSourceProducer implements Serializable { | @@ -117,18 +117,7 @@ public class DataSourceProducer implements Serializable { | ||
117 | result = (DataSource) context.lookup(jndiMap.get(dataSourceName)); | 117 | result = (DataSource) context.lookup(jndiMap.get(dataSourceName)); |
118 | 118 | ||
119 | } else { | 119 | } else { |
120 | - String driver = config.getDriverClass().get(dataSourceName); | ||
121 | - String url = config.getUrl().get(dataSourceName); | ||
122 | - String username = config.getUsername().get(dataSourceName); | ||
123 | - String password = config.getPassword().get(dataSourceName); | ||
124 | - | ||
125 | - BasicDataSource dataSource = new BasicDataSource(); | ||
126 | - dataSource.setDriverClassName(driver); | ||
127 | - dataSource.setUrl(url); | ||
128 | - dataSource.setUsername(username); | ||
129 | - dataSource.setPassword(password); | ||
130 | - | ||
131 | - result = dataSource; | 120 | + result = new BasicDataSourceProxy(dataSourceName, config); |
132 | } | 121 | } |
133 | 122 | ||
134 | } catch (Exception cause) { | 123 | } catch (Exception cause) { |
impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/transaction/BasicDataSourceProxy.java
0 → 100644
@@ -0,0 +1,352 @@ | @@ -0,0 +1,352 @@ | ||
1 | +package br.gov.frameworkdemoiselle.transaction; | ||
2 | + | ||
3 | +import java.io.PrintWriter; | ||
4 | +import java.io.Serializable; | ||
5 | +import java.sql.Connection; | ||
6 | +import java.sql.SQLException; | ||
7 | +import java.util.Collection; | ||
8 | + | ||
9 | +import org.apache.commons.dbcp.BasicDataSource; | ||
10 | + | ||
11 | +import br.gov.frameworkdemoiselle.internal.configuration.JDBCConfig; | ||
12 | + | ||
13 | +public class BasicDataSourceProxy extends BasicDataSource implements Serializable { | ||
14 | + | ||
15 | + private static final long serialVersionUID = 1L; | ||
16 | + | ||
17 | + private String dataSourceName; | ||
18 | + | ||
19 | + private JDBCConfig config; | ||
20 | + | ||
21 | + private transient BasicDataSource delegate; | ||
22 | + | ||
23 | + public BasicDataSourceProxy(String dataSourceName, JDBCConfig config) { | ||
24 | + this.dataSourceName = dataSourceName; | ||
25 | + this.config = config; | ||
26 | + } | ||
27 | + | ||
28 | + private BasicDataSource getDelegate() { | ||
29 | + if (this.delegate == null) { | ||
30 | + String driver = config.getDriverClass().get(dataSourceName); | ||
31 | + String url = config.getUrl().get(dataSourceName); | ||
32 | + String username = config.getUsername().get(dataSourceName); | ||
33 | + String password = config.getPassword().get(dataSourceName); | ||
34 | + | ||
35 | + BasicDataSource dataSource = new BasicDataSource(); | ||
36 | + dataSource.setDriverClassName(driver); | ||
37 | + dataSource.setUrl(url); | ||
38 | + dataSource.setUsername(username); | ||
39 | + dataSource.setPassword(password); | ||
40 | + | ||
41 | + delegate = dataSource; | ||
42 | + } | ||
43 | + | ||
44 | + return this.delegate; | ||
45 | + } | ||
46 | + | ||
47 | + public boolean getDefaultAutoCommit() { | ||
48 | + return getDelegate().getDefaultAutoCommit(); | ||
49 | + } | ||
50 | + | ||
51 | + public void setDefaultAutoCommit(boolean defaultAutoCommit) { | ||
52 | + getDelegate().setDefaultAutoCommit(defaultAutoCommit); | ||
53 | + } | ||
54 | + | ||
55 | + public boolean getDefaultReadOnly() { | ||
56 | + return getDelegate().getDefaultReadOnly(); | ||
57 | + } | ||
58 | + | ||
59 | + public void setDefaultReadOnly(boolean defaultReadOnly) { | ||
60 | + getDelegate().setDefaultReadOnly(defaultReadOnly); | ||
61 | + } | ||
62 | + | ||
63 | + public int getDefaultTransactionIsolation() { | ||
64 | + return getDelegate().getDefaultTransactionIsolation(); | ||
65 | + } | ||
66 | + | ||
67 | + public void setDefaultTransactionIsolation(int defaultTransactionIsolation) { | ||
68 | + getDelegate().setDefaultTransactionIsolation(defaultTransactionIsolation); | ||
69 | + } | ||
70 | + | ||
71 | + public String getDefaultCatalog() { | ||
72 | + return getDelegate().getDefaultCatalog(); | ||
73 | + } | ||
74 | + | ||
75 | + public void setDefaultCatalog(String defaultCatalog) { | ||
76 | + getDelegate().setDefaultCatalog(defaultCatalog); | ||
77 | + } | ||
78 | + | ||
79 | + public String getDriverClassName() { | ||
80 | + return getDelegate().getDriverClassName(); | ||
81 | + } | ||
82 | + | ||
83 | + public void setDriverClassName(String driverClassName) { | ||
84 | + getDelegate().setDriverClassName(driverClassName); | ||
85 | + } | ||
86 | + | ||
87 | + public ClassLoader getDriverClassLoader() { | ||
88 | + return getDelegate().getDriverClassLoader(); | ||
89 | + } | ||
90 | + | ||
91 | + public void setDriverClassLoader(ClassLoader driverClassLoader) { | ||
92 | + getDelegate().setDriverClassLoader(driverClassLoader); | ||
93 | + } | ||
94 | + | ||
95 | + public int getMaxActive() { | ||
96 | + return getDelegate().getMaxActive(); | ||
97 | + } | ||
98 | + | ||
99 | + public void setMaxActive(int maxActive) { | ||
100 | + getDelegate().setMaxActive(maxActive); | ||
101 | + } | ||
102 | + | ||
103 | + public int getMaxIdle() { | ||
104 | + return getDelegate().getMaxIdle(); | ||
105 | + } | ||
106 | + | ||
107 | + public void setMaxIdle(int maxIdle) { | ||
108 | + getDelegate().setMaxIdle(maxIdle); | ||
109 | + } | ||
110 | + | ||
111 | + public int getMinIdle() { | ||
112 | + return getDelegate().getMinIdle(); | ||
113 | + } | ||
114 | + | ||
115 | + public void setMinIdle(int minIdle) { | ||
116 | + getDelegate().setMinIdle(minIdle); | ||
117 | + } | ||
118 | + | ||
119 | + public int getInitialSize() { | ||
120 | + return getDelegate().getInitialSize(); | ||
121 | + } | ||
122 | + | ||
123 | + public void setInitialSize(int initialSize) { | ||
124 | + getDelegate().setInitialSize(initialSize); | ||
125 | + } | ||
126 | + | ||
127 | + public long getMaxWait() { | ||
128 | + return getDelegate().getMaxWait(); | ||
129 | + } | ||
130 | + | ||
131 | + public void setMaxWait(long maxWait) { | ||
132 | + getDelegate().setMaxWait(maxWait); | ||
133 | + } | ||
134 | + | ||
135 | + public boolean isPoolPreparedStatements() { | ||
136 | + return getDelegate().isPoolPreparedStatements(); | ||
137 | + } | ||
138 | + | ||
139 | + public void setPoolPreparedStatements(boolean poolingStatements) { | ||
140 | + getDelegate().setPoolPreparedStatements(poolingStatements); | ||
141 | + } | ||
142 | + | ||
143 | + public int getMaxOpenPreparedStatements() { | ||
144 | + return getDelegate().getMaxOpenPreparedStatements(); | ||
145 | + } | ||
146 | + | ||
147 | + public void setMaxOpenPreparedStatements(int maxOpenStatements) { | ||
148 | + getDelegate().setMaxOpenPreparedStatements(maxOpenStatements); | ||
149 | + } | ||
150 | + | ||
151 | + public boolean getTestOnBorrow() { | ||
152 | + return getDelegate().getTestOnBorrow(); | ||
153 | + } | ||
154 | + | ||
155 | + public void setTestOnBorrow(boolean testOnBorrow) { | ||
156 | + getDelegate().setTestOnBorrow(testOnBorrow); | ||
157 | + } | ||
158 | + | ||
159 | + public boolean getTestOnReturn() { | ||
160 | + return getDelegate().getTestOnReturn(); | ||
161 | + } | ||
162 | + | ||
163 | + public void setTestOnReturn(boolean testOnReturn) { | ||
164 | + getDelegate().setTestOnReturn(testOnReturn); | ||
165 | + } | ||
166 | + | ||
167 | + public long getTimeBetweenEvictionRunsMillis() { | ||
168 | + return getDelegate().getTimeBetweenEvictionRunsMillis(); | ||
169 | + } | ||
170 | + | ||
171 | + public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) { | ||
172 | + getDelegate().setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); | ||
173 | + } | ||
174 | + | ||
175 | + public int getNumTestsPerEvictionRun() { | ||
176 | + return getDelegate().getNumTestsPerEvictionRun(); | ||
177 | + } | ||
178 | + | ||
179 | + public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) { | ||
180 | + getDelegate().setNumTestsPerEvictionRun(numTestsPerEvictionRun); | ||
181 | + } | ||
182 | + | ||
183 | + public long getMinEvictableIdleTimeMillis() { | ||
184 | + return getDelegate().getMinEvictableIdleTimeMillis(); | ||
185 | + } | ||
186 | + | ||
187 | + public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) { | ||
188 | + getDelegate().setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); | ||
189 | + } | ||
190 | + | ||
191 | + public boolean getTestWhileIdle() { | ||
192 | + return getDelegate().getTestWhileIdle(); | ||
193 | + } | ||
194 | + | ||
195 | + public void setTestWhileIdle(boolean testWhileIdle) { | ||
196 | + getDelegate().setTestWhileIdle(testWhileIdle); | ||
197 | + } | ||
198 | + | ||
199 | + public int getNumActive() { | ||
200 | + return getDelegate().getNumActive(); | ||
201 | + } | ||
202 | + | ||
203 | + public int getNumIdle() { | ||
204 | + return getDelegate().getNumIdle(); | ||
205 | + } | ||
206 | + | ||
207 | + public String getPassword() { | ||
208 | + return getDelegate().getPassword(); | ||
209 | + } | ||
210 | + | ||
211 | + public void setPassword(String password) { | ||
212 | + getDelegate().setPassword(password); | ||
213 | + } | ||
214 | + | ||
215 | + public String getUrl() { | ||
216 | + return getDelegate().getUrl(); | ||
217 | + } | ||
218 | + | ||
219 | + public void setUrl(String url) { | ||
220 | + getDelegate().setUrl(url); | ||
221 | + } | ||
222 | + | ||
223 | + public String getUsername() { | ||
224 | + return getDelegate().getUsername(); | ||
225 | + } | ||
226 | + | ||
227 | + public void setUsername(String username) { | ||
228 | + getDelegate().setUsername(username); | ||
229 | + } | ||
230 | + | ||
231 | + public String getValidationQuery() { | ||
232 | + return getDelegate().getValidationQuery(); | ||
233 | + } | ||
234 | + | ||
235 | + public void setValidationQuery(String validationQuery) { | ||
236 | + getDelegate().setValidationQuery(validationQuery); | ||
237 | + } | ||
238 | + | ||
239 | + public int getValidationQueryTimeout() { | ||
240 | + return getDelegate().getValidationQueryTimeout(); | ||
241 | + } | ||
242 | + | ||
243 | + public void setValidationQueryTimeout(int timeout) { | ||
244 | + getDelegate().setValidationQueryTimeout(timeout); | ||
245 | + } | ||
246 | + | ||
247 | + @SuppressWarnings("rawtypes") | ||
248 | + public Collection getConnectionInitSqls() { | ||
249 | + return getDelegate().getConnectionInitSqls(); | ||
250 | + } | ||
251 | + | ||
252 | + @SuppressWarnings("rawtypes") | ||
253 | + public void setConnectionInitSqls(Collection connectionInitSqls) { | ||
254 | + getDelegate().setConnectionInitSqls(connectionInitSqls); | ||
255 | + } | ||
256 | + | ||
257 | + public void setAccessToUnderlyingConnectionAllowed(boolean allow) { | ||
258 | + getDelegate().setAccessToUnderlyingConnectionAllowed(allow); | ||
259 | + } | ||
260 | + | ||
261 | + public Connection getConnection(String user, String pass) throws SQLException { | ||
262 | + return getDelegate().getConnection(user, pass); | ||
263 | + } | ||
264 | + | ||
265 | + public int getLoginTimeout() throws SQLException { | ||
266 | + return getDelegate().getLoginTimeout(); | ||
267 | + } | ||
268 | + | ||
269 | + public PrintWriter getLogWriter() throws SQLException { | ||
270 | + return getDelegate().getLogWriter(); | ||
271 | + } | ||
272 | + | ||
273 | + public void setLoginTimeout(int loginTimeout) throws SQLException { | ||
274 | + getDelegate().setLoginTimeout(loginTimeout); | ||
275 | + } | ||
276 | + | ||
277 | + public void setLogWriter(PrintWriter logWriter) throws SQLException { | ||
278 | + getDelegate().setLogWriter(logWriter); | ||
279 | + } | ||
280 | + | ||
281 | + public boolean getRemoveAbandoned() { | ||
282 | + return getDelegate().getRemoveAbandoned(); | ||
283 | + } | ||
284 | + | ||
285 | + public void setRemoveAbandoned(boolean removeAbandoned) { | ||
286 | + getDelegate().setRemoveAbandoned(removeAbandoned); | ||
287 | + } | ||
288 | + | ||
289 | + public int getRemoveAbandonedTimeout() { | ||
290 | + return getDelegate().getRemoveAbandonedTimeout(); | ||
291 | + } | ||
292 | + | ||
293 | + public void setRemoveAbandonedTimeout(int removeAbandonedTimeout) { | ||
294 | + getDelegate().setRemoveAbandonedTimeout(removeAbandonedTimeout); | ||
295 | + } | ||
296 | + | ||
297 | + public boolean getLogAbandoned() { | ||
298 | + return getDelegate().getLogAbandoned(); | ||
299 | + } | ||
300 | + | ||
301 | + public void setLogAbandoned(boolean logAbandoned) { | ||
302 | + getDelegate().setLogAbandoned(logAbandoned); | ||
303 | + } | ||
304 | + | ||
305 | + public void addConnectionProperty(String name, String value) { | ||
306 | + getDelegate().addConnectionProperty(name, value); | ||
307 | + } | ||
308 | + | ||
309 | + public void removeConnectionProperty(String name) { | ||
310 | + getDelegate().removeConnectionProperty(name); | ||
311 | + } | ||
312 | + | ||
313 | + public void setConnectionProperties(String connectionProperties) { | ||
314 | + getDelegate().setConnectionProperties(connectionProperties); | ||
315 | + } | ||
316 | + | ||
317 | + public void close() throws SQLException { | ||
318 | + getDelegate().close(); | ||
319 | + } | ||
320 | + | ||
321 | + public boolean equals(Object arg0) { | ||
322 | + return getDelegate().equals(arg0); | ||
323 | + } | ||
324 | + | ||
325 | + public Connection getConnection() throws SQLException { | ||
326 | + return getDelegate().getConnection(); | ||
327 | + } | ||
328 | + | ||
329 | + public int hashCode() { | ||
330 | + return getDelegate().hashCode(); | ||
331 | + } | ||
332 | + | ||
333 | + public boolean isAccessToUnderlyingConnectionAllowed() { | ||
334 | + return getDelegate().isAccessToUnderlyingConnectionAllowed(); | ||
335 | + } | ||
336 | + | ||
337 | + public boolean isClosed() { | ||
338 | + return getDelegate().isClosed(); | ||
339 | + } | ||
340 | + | ||
341 | + public boolean isWrapperFor(Class<?> iface) throws SQLException { | ||
342 | + return getDelegate().isWrapperFor(iface); | ||
343 | + } | ||
344 | + | ||
345 | + public String toString() { | ||
346 | + return getDelegate().toString(); | ||
347 | + } | ||
348 | + | ||
349 | + public <T> T unwrap(Class<T> iface) throws SQLException { | ||
350 | + return getDelegate().unwrap(iface); | ||
351 | + } | ||
352 | +} |