001: /*
002: * Distributed as part of c3p0 v.0.9.1.2
003: *
004: * Copyright (C) 2005 Machinery For Change, Inc.
005: *
006: * Author: Steve Waldman <swaldman@mchange.com>
007: *
008: * This library is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU Lesser General Public License version 2.1, as
010: * published by the Free Software Foundation.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public License
018: * along with this software; see the file LICENSE. If not, write to the
019: * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: */
022:
023: package com.mchange.v2.c3p0.stmt;
024:
025: import java.sql.Connection;
026: import java.sql.ResultSet;
027: import java.lang.reflect.Method;
028:
029: final class SimpleStatementCacheKey extends StatementCacheKey {
030: static StatementCacheKey _find(Connection pcon,
031: Method stmtProducingMethod, Object[] args) {
032: ///BEGIN FIND LOGIC///
033: String stmtText = (String) args[0];
034: boolean is_callable = stmtProducingMethod.getName().equals(
035: "prepareCall");
036: int result_set_type;
037: int result_set_concurrency;
038:
039: int[] columnIndexes;
040: String[] columnNames;
041: Integer autogeneratedKeys;
042: Integer resultSetHoldability;
043:
044: if (args.length == 1) {
045: result_set_type = ResultSet.TYPE_FORWARD_ONLY;
046: result_set_concurrency = ResultSet.CONCUR_READ_ONLY;
047: columnIndexes = null;
048: columnNames = null;
049: autogeneratedKeys = null;
050: resultSetHoldability = null;
051: } else if (args.length == 2) {
052: Class[] argTypes = stmtProducingMethod.getParameterTypes();
053: if (argTypes[1].isArray()) {
054: Class baseType = argTypes[1].getComponentType();
055: if (baseType == int.class) //second arg is columnIndexes
056: {
057: result_set_type = ResultSet.TYPE_FORWARD_ONLY;
058: result_set_concurrency = ResultSet.CONCUR_READ_ONLY;
059: columnIndexes = (int[]) args[1];
060: columnNames = null;
061: autogeneratedKeys = null;
062: resultSetHoldability = null;
063: } else if (baseType == String.class) {
064: result_set_type = ResultSet.TYPE_FORWARD_ONLY;
065: result_set_concurrency = ResultSet.CONCUR_READ_ONLY;
066: columnIndexes = null;
067: columnNames = (String[]) args[1];
068: autogeneratedKeys = null;
069: resultSetHoldability = null;
070: } else
071: throw new IllegalArgumentException(
072: "c3p0 probably needs to be updated for some new "
073: + "JDBC spec! As of JDBC3, we expect two arg statement "
074: + "producing methods where the second arg is either "
075: + "an int, int array, or String array.");
076: } else //it should be a boxed int, autogeneratedKeys
077: {
078: result_set_type = ResultSet.TYPE_FORWARD_ONLY;
079: result_set_concurrency = ResultSet.CONCUR_READ_ONLY;
080: columnIndexes = null;
081: columnNames = null;
082: autogeneratedKeys = (Integer) args[1];
083: resultSetHoldability = null;
084: }
085: } else if (args.length == 3) {
086: result_set_type = ((Integer) args[1]).intValue();
087: result_set_concurrency = ((Integer) args[2]).intValue();
088: columnIndexes = null;
089: columnNames = null;
090: autogeneratedKeys = null;
091: resultSetHoldability = null;
092: } else if (args.length == 4) {
093: result_set_type = ((Integer) args[1]).intValue();
094: result_set_concurrency = ((Integer) args[2]).intValue();
095: columnIndexes = null;
096: columnNames = null;
097: autogeneratedKeys = null;
098: resultSetHoldability = (Integer) args[3];
099: } else
100: throw new IllegalArgumentException(
101: "Unexpected number of args to "
102: + stmtProducingMethod.getName());
103: ///END FIND LOGIC///
104:
105: return new SimpleStatementCacheKey(pcon, stmtText, is_callable,
106: result_set_type, result_set_concurrency, columnIndexes,
107: columnNames, autogeneratedKeys, resultSetHoldability);
108: }
109:
110: SimpleStatementCacheKey(Connection physicalConnection,
111: String stmtText, boolean is_callable, int result_set_type,
112: int result_set_concurrency, int[] columnIndexes,
113: String[] columnNames, Integer autogeneratedKeys,
114: Integer resultSetHoldability) {
115: super (physicalConnection, stmtText, is_callable,
116: result_set_type, result_set_concurrency, columnIndexes,
117: columnNames, autogeneratedKeys, resultSetHoldability);
118: }
119:
120: public boolean equals(Object o) {
121: return StatementCacheKey.equals(this , o);
122: }
123:
124: public int hashCode() {
125: return StatementCacheKey.hashCode(this);
126: }
127: }
|