01: /*
02: * $Id: StatementInvocationHandler.java 10489 2008-01-23 17:53:38Z dfeist $
03: * --------------------------------------------------------------------------------------
04: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
05: *
06: * The software in this package is published under the terms of the CPAL v1.0
07: * license, a copy of which has been included with this distribution in the
08: * LICENSE.txt file.
09: */
10: package org.mule.transport.jdbc.xa;
11:
12: import java.lang.reflect.InvocationHandler;
13: import java.lang.reflect.InvocationTargetException;
14: import java.lang.reflect.Method;
15: import java.sql.Statement;
16:
17: public class StatementInvocationHandler implements InvocationHandler {
18:
19: private Statement statement;
20: private ConnectionWrapper connectionWrapper;
21:
22: public StatementInvocationHandler(
23: ConnectionWrapper connectionWrapper, Statement statement) {
24: this .connectionWrapper = connectionWrapper;
25: this .statement = statement;
26: }
27:
28: /*
29: * (non-Javadoc)
30: *
31: * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object,
32: * java.lang.reflect.Method, java.lang.Object[])
33: */
34: public Object invoke(Object proxy, Method method, Object[] args)
35: throws Throwable {
36: if (method.getName().startsWith("execute")) {
37: connectionWrapper.enlist();
38: }
39: try {
40: return method.invoke(statement, args);
41: } catch (InvocationTargetException ex) {
42: throw ex.getCause();
43: }
44: }
45:
46: }
|