~brian-thomason/+junk/ha-jdbc

« back to all changes in this revision

Viewing changes to src/net/sf/hajdbc/sql/CallableStatementInvocationHandler.java

  • Committer: Brian Thomason
  • Date: 2011-12-20 17:34:21 UTC
  • Revision ID: brian.thomason@canonical.com-20111220173421-p9jg95iq91jgdihh
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * HA-JDBC: High-Availability JDBC
 
3
 * Copyright (c) 2004-2007 Paul Ferraro
 
4
 * 
 
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.
 
9
 * 
 
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> extends AbstractPreparedStatementInvocationHandler<D, CallableStatement>
 
39
{
 
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");
 
43
        {
 
44
                driverReadMethodSet.removeAll(Methods.findMethods(PreparedStatement.class, "get\\w+"));
 
45
        }
 
46
        
 
47
        /**
 
48
         * @param connection
 
49
         * @param proxy
 
50
         * @param invoker
 
51
         * @param statementMap
 
52
         * @param transactionContext 
 
53
         * @param fileSupport 
 
54
         * @throws Exception
 
55
         */
 
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
 
57
        {
 
58
                super(connection, proxy, invoker, CallableStatement.class, statementMap, transactionContext, fileSupport, setMethodSet);
 
59
        }
 
60
 
 
61
        /**
 
62
         * @see net.sf.hajdbc.sql.AbstractStatementInvocationHandler#getInvocationStrategy(java.sql.Statement, java.lang.reflect.Method, java.lang.Object[])
 
63
         */
 
64
        @Override
 
65
        protected InvocationStrategy<D, CallableStatement, ?> getInvocationStrategy(CallableStatement statement, Method method, Object[] parameters) throws Exception
 
66
        {
 
67
                if (registerOutParameterMethodSet.contains(method))
 
68
                {
 
69
                        return new DriverWriteInvocationStrategy<D, CallableStatement, Object>();
 
70
                }
 
71
                
 
72
                if (driverReadMethodSet.contains(method))
 
73
                {
 
74
                        return new DriverReadInvocationStrategy<D, CallableStatement, Object>();
 
75
                }
 
76
                
 
77
                return super.getInvocationStrategy(statement, method, parameters);
 
78
        }
 
79
 
 
80
        /**
 
81
         * @see net.sf.hajdbc.sql.AbstractPreparedStatementInvocationHandler#isBatchMethod(java.lang.reflect.Method)
 
82
         */
 
83
        @Override
 
84
        protected boolean isBatchMethod(Method method)
 
85
        {
 
86
                return registerOutParameterMethodSet.contains(method) || super.isBatchMethod(method);
 
87
        }
 
88
 
 
89
        /**
 
90
         * @see net.sf.hajdbc.sql.AbstractPreparedStatementInvocationHandler#isIndexType(java.lang.Class)
 
91
         */
 
92
        @Override
 
93
        protected boolean isIndexType(Class<?> type)
 
94
        {
 
95
                return type.equals(String.class) || super.isIndexType(type);
 
96
        }
 
97
}