KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mchange > v2 > c3p0 > stmt > SimpleStatementCacheKey


1 /*
2  * Distributed as part of c3p0 v.0.9.1
3  *
4  * Copyright (C) 2005 Machinery For Change, Inc.
5  *
6  * Author: Steve Waldman <swaldman@mchange.com>
7  *
8  * This library is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License version 2.1, as
10  * published by the Free Software Foundation.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this software; see the file LICENSE. If not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */

22
23
24 package com.mchange.v2.c3p0.stmt;
25
26 import java.sql.Connection JavaDoc;
27 import java.sql.ResultSet JavaDoc;
28 import java.lang.reflect.Method JavaDoc;
29
30 final class SimpleStatementCacheKey extends StatementCacheKey
31 {
32     static StatementCacheKey _find( Connection JavaDoc pcon, Method JavaDoc stmtProducingMethod, Object JavaDoc[] args )
33     {
34     ///BEGIN FIND LOGIC///
35
String JavaDoc stmtText = (String JavaDoc) args[0];
36     boolean is_callable = stmtProducingMethod.getName().equals("prepareCall");
37     int result_set_type;
38     int result_set_concurrency;
39
40     int[] columnIndexes;
41     String JavaDoc[] columnNames;
42     Integer JavaDoc autogeneratedKeys;
43     Integer JavaDoc resultSetHoldability;
44
45     if (args.length == 1)
46         {
47         result_set_type = ResultSet.TYPE_FORWARD_ONLY;
48         result_set_concurrency = ResultSet.CONCUR_READ_ONLY;
49         columnIndexes = null;
50         columnNames = null;
51         autogeneratedKeys = null;
52         resultSetHoldability = null;
53         }
54     else if (args.length == 2)
55         {
56         Class JavaDoc[] argTypes = stmtProducingMethod.getParameterTypes();
57         if (argTypes[1].isArray())
58             {
59             Class JavaDoc baseType = argTypes[1].getComponentType();
60             if (baseType == int.class) //second arg is columnIndexes
61
{
62                 result_set_type = ResultSet.TYPE_FORWARD_ONLY;
63                 result_set_concurrency = ResultSet.CONCUR_READ_ONLY;
64                 columnIndexes = (int[]) args[1];
65                 columnNames = null;
66                 autogeneratedKeys = null;
67                 resultSetHoldability = null;
68                 }
69             else if (baseType == String JavaDoc.class)
70                 {
71                 result_set_type = ResultSet.TYPE_FORWARD_ONLY;
72                 result_set_concurrency = ResultSet.CONCUR_READ_ONLY;
73                 columnIndexes = null;
74                 columnNames = (String JavaDoc[]) args[1];
75                 autogeneratedKeys = null;
76                 resultSetHoldability = null;
77                 }
78             else
79                 throw new IllegalArgumentException JavaDoc("c3p0 probably needs to be updated for some new " +
80                                    "JDBC spec! As of JDBC3, we expect two arg statement " +
81                                    "producing methods where the second arg is either " +
82                                    "an int, int array, or String array.");
83             }
84         else //it should be a boxed int, autogeneratedKeys
85
{
86             result_set_type = ResultSet.TYPE_FORWARD_ONLY;
87             result_set_concurrency = ResultSet.CONCUR_READ_ONLY;
88             columnIndexes = null;
89             columnNames = null;
90             autogeneratedKeys = (Integer JavaDoc) args[1];
91             resultSetHoldability = null;
92             }
93         }
94     else if (args.length == 3)
95         {
96         result_set_type = ((Integer JavaDoc) args[1]).intValue();
97         result_set_concurrency = ((Integer JavaDoc) args[2]).intValue();
98         columnIndexes = null;
99         columnNames = null;
100         autogeneratedKeys = null;
101         resultSetHoldability = null;
102         }
103     else if (args.length == 4)
104         {
105         result_set_type = ((Integer JavaDoc) args[1]).intValue();
106         result_set_concurrency = ((Integer JavaDoc) args[2]).intValue();
107         columnIndexes = null;
108         columnNames = null;
109         autogeneratedKeys = null;
110         resultSetHoldability = (Integer JavaDoc) args[3];
111         }
112     else
113         throw new IllegalArgumentException JavaDoc("Unexpected number of args to " +
114                            stmtProducingMethod.getName() );
115     ///END FIND LOGIC///
116

117
118     return new SimpleStatementCacheKey( pcon,
119                         stmtText,
120                         is_callable,
121                         result_set_type,
122                         result_set_concurrency,
123                         columnIndexes,
124                         columnNames,
125                         autogeneratedKeys,
126                         resultSetHoldability );
127     }
128
129     SimpleStatementCacheKey( Connection JavaDoc physicalConnection,
130                  String JavaDoc stmtText,
131                  boolean is_callable,
132                  int result_set_type,
133                  int result_set_concurrency,
134                  int[] columnIndexes,
135                  String JavaDoc[] columnNames,
136                  Integer JavaDoc autogeneratedKeys,
137                  Integer JavaDoc resultSetHoldability )
138     {
139     super( physicalConnection,
140            stmtText,
141            is_callable,
142            result_set_type,
143            result_set_concurrency,
144            columnIndexes,
145            columnNames,
146            autogeneratedKeys,
147            resultSetHoldability );
148     }
149
150     public boolean equals( Object JavaDoc o )
151     { return StatementCacheKey.equals( this, o ); }
152
153     public int hashCode()
154     { return StatementCacheKey.hashCode( this ); }
155 }
156
Popular Tags