2
* HA-JDBC: High-Availability JDBC
3
* Copyright (c) 2004-2007 Paul Ferraro
5
* This library is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU Lesser General Public License as published by the
7
* Free Software Foundation; either version 2.1 of the License, or (at your
8
* option) any later version.
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
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
19
* Contact: ferraro@users.sourceforge.net
21
package net.sf.hajdbc.sql;
23
import java.lang.reflect.Method;
24
import java.sql.CallableStatement;
25
import java.sql.Connection;
26
import java.sql.PreparedStatement;
30
import net.sf.hajdbc.Database;
31
import net.sf.hajdbc.util.reflect.Methods;
34
* @author Paul Ferraro
37
@SuppressWarnings("nls")
38
public class CallableStatementInvocationHandler<D> extends AbstractPreparedStatementInvocationHandler<D, CallableStatement>
40
private static final Set<Method> registerOutParameterMethodSet = Methods.findMethods(CallableStatement.class, "registerOutParameter");
41
private static final Set<Method> setMethodSet = Methods.findMethods(CallableStatement.class, "set\\w+");
42
private static final Set<Method> driverReadMethodSet = Methods.findMethods(CallableStatement.class, "get\\w+", "wasNull");
44
driverReadMethodSet.removeAll(Methods.findMethods(PreparedStatement.class, "get\\w+"));
52
* @param transactionContext
56
public CallableStatementInvocationHandler(Connection connection, SQLProxy<D, Connection> proxy, Invoker<D, Connection, CallableStatement> invoker, Map<Database<D>, CallableStatement> statementMap, TransactionContext<D> transactionContext, FileSupport fileSupport) throws Exception
58
super(connection, proxy, invoker, CallableStatement.class, statementMap, transactionContext, fileSupport, setMethodSet);
62
* @see net.sf.hajdbc.sql.AbstractStatementInvocationHandler#getInvocationStrategy(java.sql.Statement, java.lang.reflect.Method, java.lang.Object[])
65
protected InvocationStrategy<D, CallableStatement, ?> getInvocationStrategy(CallableStatement statement, Method method, Object[] parameters) throws Exception
67
if (registerOutParameterMethodSet.contains(method))
69
return new DriverWriteInvocationStrategy<D, CallableStatement, Object>();
72
if (driverReadMethodSet.contains(method))
74
return new DriverReadInvocationStrategy<D, CallableStatement, Object>();
77
return super.getInvocationStrategy(statement, method, parameters);
81
* @see net.sf.hajdbc.sql.AbstractPreparedStatementInvocationHandler#isBatchMethod(java.lang.reflect.Method)
84
protected boolean isBatchMethod(Method method)
86
return registerOutParameterMethodSet.contains(method) || super.isBatchMethod(method);
90
* @see net.sf.hajdbc.sql.AbstractPreparedStatementInvocationHandler#isIndexType(java.lang.Class)
93
protected boolean isIndexType(Class<?> type)
95
return type.equals(String.class) || super.isIndexType(type);