01: package net.sourceforge.jaxor.db;
02:
03: import net.sourceforge.jaxor.util.DynamicDecorator;
04:
05: import java.lang.reflect.Method;
06: import java.sql.Connection;
07:
08: /*
09: * User: Mike
10: * Date: Jul 16, 2003
11: * Time: 6:11:04 PM
12: */
13:
14: /**
15: * We create dynamic overrides to methods b/c there are differences between the API's in 1.3 and 1.4
16: */
17: public class ConnectionDecorator {
18:
19: public static Connection createNonClosing(Connection conn) {
20: final DynamicDecorator.Override NULL_CLOSE = new DynamicDecorator.Override(
21: "close", new Class[0]);
22: return create(conn, NULL_CLOSE);
23: }
24:
25: private static Connection create(Connection conn,
26: final DynamicDecorator.Override NULL_CLOSE) {
27: return (Connection) DynamicDecorator.create(Connection.class
28: .getClassLoader(), conn,
29: new Class[] { Connection.class }, NULL_CLOSE);
30: }
31:
32: public static Connection logClose(Connection conn) {
33: DynamicDecorator.Override LOG_CLOSE = new DynamicDecorator.Override(
34: "close", new Class[0]) {
35: private boolean closed = false;
36: private Exception stack = new Exception();
37:
38: protected Object invoke(Object delegate, Object[] args,
39: Method method) throws Throwable {
40: closed = true;
41: return method.invoke(delegate, args);
42: }
43:
44: protected void finalize() throws Throwable {
45: if (!closed)
46: stack.printStackTrace();
47: }
48: };
49: return (Connection) DynamicDecorator.create(conn, LOG_CLOSE);
50: }
51: }
|