Commit 1b901217e5bfd9b8ee67edb60582b06077b1c7f1
1 parent
53c710d3
Medida de contorno para permitir que classe ConnectionProxy compile no
JDK 7 ou superior.
Showing
1 changed file
with
80 additions
and
0 deletions
Show diff stats
impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/proxy/ConnectionProxy.java
... | ... | @@ -54,6 +54,7 @@ import java.sql.Statement; |
54 | 54 | import java.sql.Struct; |
55 | 55 | import java.util.Map; |
56 | 56 | import java.util.Properties; |
57 | +import java.util.concurrent.Executor; | |
57 | 58 | |
58 | 59 | import br.gov.frameworkdemoiselle.internal.producer.ConnectionProducer; |
59 | 60 | import br.gov.frameworkdemoiselle.util.Beans; |
... | ... | @@ -64,6 +65,10 @@ public class ConnectionProxy implements Connection, Serializable { |
64 | 65 | |
65 | 66 | private final String dataSourceName; |
66 | 67 | |
68 | + //TODO determinar o que fazer para manter compatibilidade com Java 6 e 7, pois a interface | |
69 | + // Connection ganhou métodos novos no Java 7. | |
70 | + private final int javaVersion = Integer.valueOf( System.getProperty("java.version").substring(2, 3) ); | |
71 | + | |
67 | 72 | public ConnectionProxy(String dataSourceName) { |
68 | 73 | this.dataSourceName = dataSourceName; |
69 | 74 | } |
... | ... | @@ -272,5 +277,80 @@ public class ConnectionProxy implements Connection, Serializable { |
272 | 277 | public <T> T unwrap(Class<T> iface) throws SQLException { |
273 | 278 | return getDelegate().unwrap(iface); |
274 | 279 | } |
280 | + | |
281 | + //TODO Método novo do Java 7, estudar solução de compatibilidade | |
282 | + public void setSchema(String schema) throws SQLException { | |
283 | + if (!isJavaSeven()){ | |
284 | + throw new UnsupportedOperationException(); | |
285 | + } | |
286 | + else{ | |
287 | + try { | |
288 | + Connection.class.getMethod("setSchema",String.class).invoke(getDelegate(),schema); | |
289 | + } catch (Exception e) { | |
290 | + throw new UnsupportedOperationException(); | |
291 | + } | |
292 | + } | |
293 | + } | |
294 | + | |
295 | + //TODO Método novo do Java 7, estudar solução de compatibilidade | |
296 | + public String getSchema() throws SQLException { | |
297 | + if (!isJavaSeven()){ | |
298 | + throw new UnsupportedOperationException(); | |
299 | + } | |
300 | + else{ | |
301 | + try { | |
302 | + return (String)Connection.class.getMethod("getSchema").invoke(getDelegate()); | |
303 | + } catch (Exception e) { | |
304 | + throw new UnsupportedOperationException(); | |
305 | + } | |
306 | + } | |
307 | + } | |
308 | + | |
309 | + //TODO Método novo do Java 7, estudar solução de compatibilidade | |
310 | + public void abort(Executor executor) throws SQLException { | |
311 | + if (!isJavaSeven()){ | |
312 | + throw new UnsupportedOperationException(); | |
313 | + } | |
314 | + else{ | |
315 | + try { | |
316 | + Connection.class.getMethod("abort",Executor.class).invoke(getDelegate(),executor); | |
317 | + } catch (Exception e) { | |
318 | + throw new UnsupportedOperationException(); | |
319 | + } | |
320 | + } | |
321 | + } | |
322 | + | |
323 | + //TODO Método novo do Java 7, estudar solução de compatibilidade | |
324 | + public void setNetworkTimeout(Executor executor, int milliseconds) | |
325 | + throws SQLException { | |
326 | + if (!isJavaSeven()){ | |
327 | + throw new UnsupportedOperationException(); | |
328 | + } | |
329 | + else{ | |
330 | + try { | |
331 | + Connection.class.getMethod("setNetworkTimeout",Executor.class,Integer.TYPE).invoke(getDelegate(),executor,milliseconds); | |
332 | + } catch (Exception e) { | |
333 | + throw new UnsupportedOperationException(); | |
334 | + } | |
335 | + } | |
336 | + } | |
337 | + | |
338 | + //TODO Método novo do Java 7, estudar solução de compatibilidade | |
339 | + public int getNetworkTimeout() throws SQLException { | |
340 | + if (!isJavaSeven()){ | |
341 | + throw new UnsupportedOperationException(); | |
342 | + } | |
343 | + else{ | |
344 | + try { | |
345 | + return (Integer)Connection.class.getMethod("getNetworkTimeout").invoke(getDelegate()); | |
346 | + } catch (Exception e) { | |
347 | + throw new UnsupportedOperationException(); | |
348 | + } | |
349 | + } | |
350 | + } | |
351 | + | |
352 | + private boolean isJavaSeven(){ | |
353 | + return javaVersion>=7; | |
354 | + } | |
275 | 355 | |
276 | 356 | } | ... | ... |