KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > ejb > cmp3 > jdbc > base > ConnectionProxyHandler


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2005, Oracle. All rights reserved.
22
package oracle.toplink.essentials.internal.ejb.cmp3.jdbc.base;
23
24 import java.lang.reflect.InvocationHandler JavaDoc;
25 import java.lang.reflect.Method JavaDoc;
26 import java.sql.Connection JavaDoc;
27
28 /**
29  * A simple invocation handler for the proxied connection.
30  *
31  * Connections are proxied only when they are obtained from a
32  * transactional data source and within the context of a JTA
33  * transaction.
34  */

35 public class ConnectionProxyHandler implements InvocationHandler JavaDoc {
36     Connection JavaDoc connection;
37
38     /************************/
39     /***** Internal API *****/
40     /************************/
41     private void debug(String JavaDoc s) {
42         System.out.println(s);
43     }
44
45     /*
46      * Use this constructor
47      */

48     public ConnectionProxyHandler(Connection JavaDoc connection) {
49         this.connection = connection;
50     }
51
52     /*********************************/
53     /***** InvocationHandler API *****/
54     /*********************************/
55
56     /*
57      * Gateway for method interception
58      */

59     public Object JavaDoc invoke(Object JavaDoc proxy, Method JavaDoc method, Object JavaDoc[] args) throws Throwable JavaDoc {
60         String JavaDoc methodName = method.getName();
61         debug("PROXY method: " + methodName);
62         // No-op if any of the following calls
63
if (methodName.equals("close") || methodName.equals("commit") || methodName.equals("rollback")) {
64             return null;
65         }
66
67         // Normal case is just to forward on to the real connection
68
return method.invoke(connection, args);
69     }
70 }
71
Popular Tags