01: /*
02: * HA-JDBC: High-Availability JDBC
03: * Copyright (c) 2004-2007 Paul Ferraro
04: *
05: * This library is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU Lesser General Public License as published by the
07: * Free Software Foundation; either version 2.1 of the License, or (at your
08: * option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful, but WITHOUT
11: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13: * for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public License
16: * along with this library; if not, write to the Free Software Foundation,
17: * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: *
19: * Contact: ferraro@users.sourceforge.net
20: */
21: package net.sf.hajdbc.sql;
22:
23: import java.lang.reflect.Method;
24: import java.sql.CallableStatement;
25: import java.sql.Connection;
26: import java.sql.PreparedStatement;
27: import java.util.Map;
28: import java.util.Set;
29:
30: import net.sf.hajdbc.Database;
31: import net.sf.hajdbc.util.reflect.Methods;
32:
33: /**
34: * @author Paul Ferraro
35: * @param <D>
36: */
37: @SuppressWarnings("nls")
38: public class CallableStatementInvocationHandler<D>
39: extends
40: AbstractPreparedStatementInvocationHandler<D, CallableStatement> {
41: private static final Set<Method> driverWriteMethodSet = Methods
42: .findMethods(CallableStatement.class,
43: "registerOutParameter", "set\\w+");
44: private static final Set<Method> driverReadMethodSet = Methods
45: .findMethods(CallableStatement.class, "get\\w+", "wasNull");
46: {
47: driverReadMethodSet.removeAll(Methods.findMethods(
48: PreparedStatement.class, "get\\w+"));
49: }
50:
51: /**
52: * @param connection
53: * @param proxy
54: * @param invoker
55: * @param statementMap
56: * @param transactionContext
57: * @param fileSupport
58: * @throws Exception
59: */
60: public CallableStatementInvocationHandler(Connection connection,
61: SQLProxy<D, Connection> proxy,
62: Invoker<D, Connection, CallableStatement> invoker,
63: Map<Database<D>, CallableStatement> statementMap,
64: TransactionContext<D> transactionContext,
65: FileSupport fileSupport) throws Exception {
66: super (connection, proxy, invoker, CallableStatement.class,
67: statementMap, transactionContext, fileSupport);
68: }
69:
70: /**
71: * @see net.sf.hajdbc.sql.AbstractStatementInvocationHandler#getInvocationStrategy(java.sql.Statement, java.lang.reflect.Method, java.lang.Object[])
72: */
73: @Override
74: protected InvocationStrategy<D, CallableStatement, ?> getInvocationStrategy(
75: CallableStatement statement, Method method,
76: Object[] parameters) throws Exception {
77: if (driverWriteMethodSet.contains(method)) {
78: return new DriverWriteInvocationStrategy<D, CallableStatement, Object>();
79: }
80:
81: if (driverReadMethodSet.contains(method)) {
82: return new DriverReadInvocationStrategy<D, CallableStatement, Object>();
83: }
84:
85: return super .getInvocationStrategy(statement, method,
86: parameters);
87: }
88:
89: /**
90: * @see net.sf.hajdbc.sql.AbstractPreparedStatementInvocationHandler#isIndexType(java.lang.Class)
91: */
92: @Override
93: protected boolean isIndexType(Class<?> type) {
94: return super .isIndexType(type) || type.equals(String.class);
95: }
96: }
|