EMMA Coverage Report (generated Wed Jul 26 14:28:59 CDT 2006)
[all classes][com.mysql.jdbc]

COVERAGE SUMMARY FOR SOURCE FILE [CallableStatement.java]

nameclass, %method, %block, %line, %
CallableStatement.java100% (4/4)32%  (39/123)47%  (1184/2502)50%  (300.5/596)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CallableStatement100% (1/1)28%  (29/103)45%  (955/2137)47%  (236.5/508)
CallableStatement (Connection, String): void 0%   (0/1)0%   (0/19)0%   (0/7)
getArray (String): Array 0%   (0/1)0%   (0/16)0%   (0/4)
getArray (int): Array 0%   (0/1)0%   (0/16)0%   (0/4)
getBigDecimal (String): BigDecimal 0%   (0/1)0%   (0/16)0%   (0/4)
getBigDecimal (int): BigDecimal 0%   (0/1)0%   (0/16)0%   (0/4)
getBigDecimal (int, int): BigDecimal 0%   (0/1)0%   (0/17)0%   (0/4)
getBlob (String): Blob 0%   (0/1)0%   (0/16)0%   (0/4)
getBlob (int): Blob 0%   (0/1)0%   (0/16)0%   (0/4)
getBoolean (String): boolean 0%   (0/1)0%   (0/16)0%   (0/4)
getBoolean (int): boolean 0%   (0/1)0%   (0/16)0%   (0/4)
getByte (String): byte 0%   (0/1)0%   (0/16)0%   (0/4)
getByte (int): byte 0%   (0/1)0%   (0/16)0%   (0/4)
getBytes (String): byte [] 0%   (0/1)0%   (0/16)0%   (0/4)
getBytes (int): byte [] 0%   (0/1)0%   (0/16)0%   (0/4)
getClob (String): Clob 0%   (0/1)0%   (0/16)0%   (0/4)
getClob (int): Clob 0%   (0/1)0%   (0/16)0%   (0/4)
getDate (String): Date 0%   (0/1)0%   (0/16)0%   (0/4)
getDate (String, Calendar): Date 0%   (0/1)0%   (0/17)0%   (0/4)
getDate (int): Date 0%   (0/1)0%   (0/16)0%   (0/4)
getDate (int, Calendar): Date 0%   (0/1)0%   (0/17)0%   (0/4)
getDouble (String): double 0%   (0/1)0%   (0/16)0%   (0/4)
getDouble (int): double 0%   (0/1)0%   (0/16)0%   (0/4)
getFloat (String): float 0%   (0/1)0%   (0/16)0%   (0/4)
getFloat (int): float 0%   (0/1)0%   (0/16)0%   (0/4)
getLong (String): long 0%   (0/1)0%   (0/16)0%   (0/4)
getLong (int): long 0%   (0/1)0%   (0/16)0%   (0/4)
getObject (String): Object 0%   (0/1)0%   (0/16)0%   (0/4)
getObject (String, Map): Object 0%   (0/1)0%   (0/17)0%   (0/4)
getObject (int, Map): Object 0%   (0/1)0%   (0/17)0%   (0/4)
getParameterMetaData (): ParameterMetaData 0%   (0/1)0%   (0/4)0%   (0/1)
getRef (String): Ref 0%   (0/1)0%   (0/16)0%   (0/4)
getRef (int): Ref 0%   (0/1)0%   (0/16)0%   (0/4)
getShort (String): short 0%   (0/1)0%   (0/16)0%   (0/4)
getShort (int): short 0%   (0/1)0%   (0/16)0%   (0/4)
getString (String): String 0%   (0/1)0%   (0/16)0%   (0/4)
getString (int): String 0%   (0/1)0%   (0/16)0%   (0/4)
getTime (String): Time 0%   (0/1)0%   (0/16)0%   (0/4)
getTime (String, Calendar): Time 0%   (0/1)0%   (0/17)0%   (0/4)
getTime (int): Time 0%   (0/1)0%   (0/16)0%   (0/4)
getTime (int, Calendar): Time 0%   (0/1)0%   (0/17)0%   (0/4)
getTimestamp (String): Timestamp 0%   (0/1)0%   (0/16)0%   (0/4)
getTimestamp (String, Calendar): Timestamp 0%   (0/1)0%   (0/17)0%   (0/4)
getTimestamp (int): Timestamp 0%   (0/1)0%   (0/16)0%   (0/4)
getTimestamp (int, Calendar): Timestamp 0%   (0/1)0%   (0/17)0%   (0/4)
getURL (String): URL 0%   (0/1)0%   (0/16)0%   (0/4)
getURL (int): URL 0%   (0/1)0%   (0/16)0%   (0/4)
registerOutParameter (String, int, String): void 0%   (0/1)0%   (0/9)0%   (0/2)
registerOutParameter (String, int, int): void 0%   (0/1)0%   (0/8)0%   (0/2)
registerOutParameter (int, int, String): void 0%   (0/1)0%   (0/5)0%   (0/2)
registerOutParameter (int, int, int): void 0%   (0/1)0%   (0/5)0%   (0/2)
setAsciiStream (String, InputStream, int): void 0%   (0/1)0%   (0/9)0%   (0/2)
setBigDecimal (String, BigDecimal): void 0%   (0/1)0%   (0/8)0%   (0/2)
setBinaryStream (String, InputStream, int): void 0%   (0/1)0%   (0/9)0%   (0/2)
setBoolean (String, boolean): void 0%   (0/1)0%   (0/8)0%   (0/2)
setByte (String, byte): void 0%   (0/1)0%   (0/8)0%   (0/2)
setBytes (String, byte []): void 0%   (0/1)0%   (0/8)0%   (0/2)
setCharacterStream (String, Reader, int): void 0%   (0/1)0%   (0/9)0%   (0/2)
setDate (String, Date): void 0%   (0/1)0%   (0/8)0%   (0/2)
setDate (String, Date, Calendar): void 0%   (0/1)0%   (0/9)0%   (0/2)
setDouble (String, double): void 0%   (0/1)0%   (0/8)0%   (0/2)
setFloat (String, float): void 0%   (0/1)0%   (0/8)0%   (0/2)
setLong (String, long): void 0%   (0/1)0%   (0/8)0%   (0/2)
setNull (String, int): void 0%   (0/1)0%   (0/8)0%   (0/2)
setNull (String, int, String): void 0%   (0/1)0%   (0/9)0%   (0/2)
setObject (String, Object): void 0%   (0/1)0%   (0/8)0%   (0/2)
setObject (String, Object, int): void 0%   (0/1)0%   (0/9)0%   (0/2)
setObject (String, Object, int, int): void 0%   (0/1)0%   (0/1)0%   (0/1)
setShort (String, short): void 0%   (0/1)0%   (0/8)0%   (0/2)
setString (String, String): void 0%   (0/1)0%   (0/8)0%   (0/2)
setTime (String, Time): void 0%   (0/1)0%   (0/8)0%   (0/2)
setTime (String, Time, Calendar): void 0%   (0/1)0%   (0/9)0%   (0/2)
setTimestamp (String, Timestamp): void 0%   (0/1)0%   (0/8)0%   (0/2)
setTimestamp (String, Timestamp, Calendar): void 0%   (0/1)0%   (0/9)0%   (0/2)
setURL (String, URL): void 0%   (0/1)0%   (0/8)0%   (0/2)
fixParameterName (String): String 100% (1/1)31%  (8/26)67%  (2/3)
executeUpdate (): int 100% (1/1)36%  (14/39)46%  (6/13)
checkStreamability (): void 100% (1/1)58%  (7/12)67%  (2/3)
executeBatch (): int [] 100% (1/1)60%  (6/10)67%  (2/3)
getOutputParameters (int): ResultSet 100% (1/1)60%  (21/35)62%  (5/8)
setInOutParamsOnServer (): void 100% (1/1)61%  (86/142)84%  (20.1/24)
getNamedParamIndex (String, boolean): int 100% (1/1)63%  (59/94)75%  (9.8/13)
clearParameters (): void 100% (1/1)68%  (13/19)90%  (5.4/6)
mapOutputParameterIndexToRsIndex (int): int 100% (1/1)70%  (35/50)90%  (9/10)
executeQuery (): ResultSet 100% (1/1)84%  (26/31)98%  (9.8/10)
retrieveOutParams (): void 100% (1/1)87%  (116/133)89%  (31.9/36)
determineParameterTypes (): void 100% (1/1)88%  (71/81)86%  (18.8/22)
mangleParameterName (String): String 100% (1/1)89%  (34/38)78%  (7/9)
execute (): boolean 100% (1/1)90%  (45/50)97%  (15.5/16)
extractProcedureName (): String 100% (1/1)91%  (62/68)88%  (14/16)
checkIsOutputParam (int): CallableStatement$CallableStatementParam 100% (1/1)99%  (71/72)93%  (14/15)
CallableStatement (Connection, CallableStatement$CallableStatementParamInfo):... 100% (1/1)100% (25/25)100% (7/7)
CallableStatement (Connection, String, String, boolean): void 100% (1/1)100% (22/22)100% (8/8)
addBatch (): void 100% (1/1)100% (5/5)100% (3/3)
checkParameterIndexBounds (int): void 100% (1/1)100% (5/5)100% (2/2)
generateParameterMap (): void 100% (1/1)100% (87/87)100% (16/16)
getInt (String): int 100% (1/1)100% (16/16)100% (4/4)
getInt (int): int 100% (1/1)100% (16/16)100% (4/4)
getObject (int): Object 100% (1/1)100% (22/22)100% (5/5)
registerOutParameter (String, int): void 100% (1/1)100% (8/8)100% (2/2)
registerOutParameter (int, int): void 100% (1/1)100% (8/8)100% (3/3)
setInt (String, int): void 100% (1/1)100% (8/8)100% (2/2)
setOutParams (): void 100% (1/1)100% (56/56)100% (11/11)
wasNull (): boolean 100% (1/1)100% (3/3)100% (1/1)
     
class CallableStatement$CallableStatementParamInfo100% (1/1)47%  (8/17)58%  (185/318)68%  (49/72)
clone (): Object 0%   (0/1)0%   (0/3)0%   (0/1)
getParameterClassName (int): String 0%   (0/1)0%   (0/44)0%   (0/7)
getParameterMode (int): int 0%   (0/1)0%   (0/10)0%   (0/2)
getParameterType (int): int 0%   (0/1)0%   (0/10)0%   (0/2)
getParameterTypeName (int): String 0%   (0/1)0%   (0/10)0%   (0/2)
getPrecision (int): int 0%   (0/1)0%   (0/10)0%   (0/2)
getScale (int): int 0%   (0/1)0%   (0/10)0%   (0/2)
isNullable (int): int 0%   (0/1)0%   (0/10)0%   (0/2)
isSigned (int): boolean 0%   (0/1)0%   (0/5)0%   (0/2)
checkBounds (int): void 100% (1/1)34%  (11/32)75%  (3/4)
CallableStatement$CallableStatementParamInfo (CallableStatement, ResultSet): ... 100% (1/1)100% (50/50)100% (13/13)
addParametersFromDBMD (ResultSet): void 100% (1/1)100% (96/96)100% (26/26)
getParameter (String): CallableStatement$CallableStatementParam 100% (1/1)100% (6/6)100% (1/1)
getParameter (int): CallableStatement$CallableStatementParam 100% (1/1)100% (6/6)100% (1/1)
getParameterCount (): int 100% (1/1)100% (9/9)100% (3/3)
iterator (): Iterator 100% (1/1)100% (4/4)100% (1/1)
numberOfParameters (): int 100% (1/1)100% (3/3)100% (1/1)
     
class CallableStatement$CallableStatementParam100% (1/1)50%  (1/2)92%  (36/39)92%  (12/13)
clone (): Object 0%   (0/1)0%   (0/3)0%   (0/1)
CallableStatement$CallableStatementParam (CallableStatement, String, int, boo... 100% (1/1)100% (36/36)100% (12/12)
     
class CallableStatement$CallableStatementParamInfoJDBC3100% (1/1)100% (1/1)100% (8/8)100% (3/3)
CallableStatement$CallableStatementParamInfoJDBC3 (CallableStatement, ResultS... 100% (1/1)100% (8/8)100% (3/3)

1/*
2 Copyright (C) 2002-2005 MySQL AB
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of version 2 of the GNU General Public License as 
6 published by the Free Software Foundation.
7 
8 There are special exceptions to the terms and conditions of the GPL 
9 as it is applied to this software. View the full text of the 
10 exception in file EXCEPTIONS-CONNECTOR-J in the directory of this 
11 software distribution.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 
22 */
23package com.mysql.jdbc;
24 
25import java.io.InputStream;
26import java.io.Reader;
27import java.io.UnsupportedEncodingException;
28 
29import java.math.BigDecimal;
30 
31import java.net.URL;
32 
33import java.sql.Array;
34import java.sql.Blob;
35import java.sql.Clob;
36import java.sql.Date;
37import java.sql.ParameterMetaData;
38import java.sql.Ref;
39import java.sql.SQLException;
40import java.sql.Time;
41import java.sql.Timestamp;
42import java.sql.Types;
43 
44import java.util.ArrayList;
45import java.util.Calendar;
46import java.util.HashMap;
47import java.util.Iterator;
48import java.util.List;
49import java.util.Locale;
50import java.util.Map;
51 
52/**
53 * Representation of stored procedures for JDBC
54 * 
55 * @author Mark Matthews
56 * @version $Id: CallableStatement.java,v 1.1.2.1 2005/05/13 18:58:38 mmatthews
57 *          Exp $
58 */
59public class CallableStatement extends PreparedStatement implements
60                java.sql.CallableStatement {
61        class CallableStatementParam {
62                int desiredJdbcType;
63 
64                int index;
65 
66                int inOutModifier;
67 
68                boolean isIn;
69 
70                boolean isOut;
71 
72                int jdbcType;
73 
74                short nullability;
75 
76                String paramName;
77 
78                int precision;
79 
80                int scale;
81 
82                String typeName;
83 
84                CallableStatementParam(String name, int idx, boolean in, boolean out,
85                                int jdbcType, String typeName, int precision, int scale,
86                                short nullability, int inOutModifier) {
87                        this.paramName = name;
88                        this.isIn = in;
89                        this.isOut = out;
90                        this.index = idx;
91 
92                        this.jdbcType = jdbcType;
93                        this.typeName = typeName;
94                        this.precision = precision;
95                        this.scale = scale;
96                        this.nullability = nullability;
97                        this.inOutModifier = inOutModifier;
98                }
99 
100                /*
101                 * (non-Javadoc)
102                 * 
103                 * @see java.lang.Object#clone()
104                 */
105                protected Object clone() throws CloneNotSupportedException {
106                        return super.clone();
107                }
108        }
109 
110        class CallableStatementParamInfo {
111                String catalogInUse;
112 
113                boolean isFunctionCall;
114 
115                String nativeSql;
116 
117                int numParameters;
118 
119                List parameterList;
120 
121                Map parameterMap;
122 
123                CallableStatementParamInfo(java.sql.ResultSet paramTypesRs)
124                                throws SQLException {
125                        boolean hadRows = paramTypesRs.last();
126 
127                        this.nativeSql = originalSql;
128                        this.catalogInUse = currentCatalog;
129                        isFunctionCall = callingStoredFunction;
130 
131                        if (hadRows) {
132                                this.numParameters = paramTypesRs.getRow();
133 
134                                this.parameterList = new ArrayList(this.numParameters);
135                                this.parameterMap = new HashMap(this.numParameters);
136 
137                                paramTypesRs.beforeFirst();
138 
139                                addParametersFromDBMD(paramTypesRs);
140                        } else {
141                                this.numParameters = 0;
142                        }
143                }
144 
145                private void addParametersFromDBMD(java.sql.ResultSet paramTypesRs)
146                                throws SQLException {
147                        int i = 0;
148 
149                        if (isFunctionCall) {
150                                // first row will be return value parameter
151                                paramTypesRs.next();
152                        }
153 
154                        while (paramTypesRs.next()) {
155                                String paramName = paramTypesRs.getString(4);
156                                int inOutModifier = paramTypesRs.getInt(5);
157 
158                                boolean isOutParameter = false;
159                                boolean isInParameter = false;
160 
161                                if (inOutModifier == DatabaseMetaData.procedureColumnInOut) {
162                                        isOutParameter = true;
163                                        isInParameter = true;
164                                } else if (inOutModifier == DatabaseMetaData.procedureColumnIn) {
165                                        isOutParameter = false;
166                                        isInParameter = true;
167                                } else if (inOutModifier == DatabaseMetaData.procedureColumnOut) {
168                                        isOutParameter = true;
169                                        isInParameter = false;
170                                }
171 
172                                int jdbcType = paramTypesRs.getInt(6);
173                                String typeName = paramTypesRs.getString(7);
174                                int precision = paramTypesRs.getInt(8);
175                                int scale = paramTypesRs.getInt(10);
176                                short nullability = paramTypesRs.getShort(12);
177 
178                                CallableStatementParam paramInfoToAdd = new CallableStatementParam(
179                                                paramName, i++, isInParameter, isOutParameter,
180                                                jdbcType, typeName, precision, scale, nullability,
181                                                inOutModifier);
182 
183                                this.parameterList.add(paramInfoToAdd);
184                                this.parameterMap.put(paramName, paramInfoToAdd);
185                        }
186                }
187 
188                protected void checkBounds(int paramIndex) throws SQLException {
189                        int localParamIndex = paramIndex - 1;
190 
191                        if ((paramIndex < 0) || (localParamIndex >= this.numParameters)) {
192                                throw SQLError.createSQLException(
193                                                Messages.getString("CallableStatement.11") + paramIndex //$NON-NLS-1$
194                                                                + Messages.getString("CallableStatement.12") + numParameters //$NON-NLS-1$
195                                                                + Messages.getString("CallableStatement.13"), SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$
196                        }
197                }
198 
199                /*
200                 * (non-Javadoc)
201                 * 
202                 * @see java.lang.Object#clone()
203                 */
204                protected Object clone() throws CloneNotSupportedException {
205                        // TODO Auto-generated method stub
206                        return super.clone();
207                }
208 
209                CallableStatementParam getParameter(int index) {
210                        return (CallableStatementParam) this.parameterList.get(index);
211                }
212 
213                CallableStatementParam getParameter(String name) {
214                        return (CallableStatementParam) this.parameterMap.get(name);
215                }
216 
217                public String getParameterClassName(int arg0) throws SQLException {
218                        String mysqlTypeName = getParameterTypeName(arg0);
219                        
220                        boolean isBinaryOrBlob = StringUtils.indexOfIgnoreCase(mysqlTypeName, "BLOB") != -1 || 
221                                StringUtils.indexOfIgnoreCase(mysqlTypeName, "BINARY") != -1;
222                        
223                        boolean isUnsigned = StringUtils.indexOfIgnoreCase(mysqlTypeName, "UNSIGNED") != -1;
224                        
225                        int mysqlTypeIfKnown = 0;
226                        
227                        if (StringUtils.startsWithIgnoreCase(mysqlTypeName, "MEDIUMINT")) {
228                                mysqlTypeIfKnown = MysqlDefs.FIELD_TYPE_INT24;
229                        }
230                        
231                        return ResultSetMetaData.getClassNameForJavaType(getParameterType(arg0), 
232                                        isUnsigned, mysqlTypeIfKnown, isBinaryOrBlob, false);
233                }
234 
235                public int getParameterCount() throws SQLException {
236                        if (this.parameterList == null) {
237                                return 0;
238                        }
239                        
240                        return this.parameterList.size();
241                }
242 
243                public int getParameterMode(int arg0) throws SQLException {
244                        checkBounds(arg0);
245 
246                        return getParameter(arg0 - 1).inOutModifier;
247                }
248 
249                public int getParameterType(int arg0) throws SQLException {
250                        checkBounds(arg0);
251 
252                        return getParameter(arg0 - 1).jdbcType;
253                }
254 
255                public String getParameterTypeName(int arg0) throws SQLException {
256                        checkBounds(arg0);
257 
258                        return getParameter(arg0 - 1).typeName;
259                }
260 
261                public int getPrecision(int arg0) throws SQLException {
262                        checkBounds(arg0);
263 
264                        return getParameter(arg0 - 1).precision;
265                }
266 
267                public int getScale(int arg0) throws SQLException {
268                        checkBounds(arg0);
269 
270                        return getParameter(arg0 - 1).scale;
271                }
272 
273                public int isNullable(int arg0) throws SQLException {
274                        checkBounds(arg0);
275 
276                        return getParameter(arg0 - 1).nullability;
277                }
278 
279                public boolean isSigned(int arg0) throws SQLException {
280                        checkBounds(arg0);
281 
282                        return false;
283                }
284 
285                Iterator iterator() {
286                        return this.parameterList.iterator();
287                }
288 
289                int numberOfParameters() {
290                        return this.numParameters;
291                }
292        }
293 
294        /**
295         * Can't implement this directly, as then you can't use callable statements
296         * on JDK-1.3.1, which unfortunately isn't EOL'd yet, and still present
297         * quite a bit out there in the wild (Websphere, FreeBSD, anyone?)
298         */
299 
300        class CallableStatementParamInfoJDBC3 extends CallableStatementParamInfo
301                        implements ParameterMetaData {
302 
303                CallableStatementParamInfoJDBC3(java.sql.ResultSet paramTypesRs)
304                                throws SQLException {
305                        super(paramTypesRs);
306                }
307        }
308 
309        private final static int NOT_OUTPUT_PARAMETER_INDICATOR = Integer.MIN_VALUE;
310 
311        private final static String PARAMETER_NAMESPACE_PREFIX = "@com_mysql_jdbc_outparam_"; //$NON-NLS-1$
312 
313        private static String mangleParameterName(String origParameterName) {
314                if (origParameterName == null) {
315                        return null;
316                }
317 
318                int offset = 0;
319 
320                if (origParameterName.length() > 0
321                                && origParameterName.charAt(0) == '@') {
322                        offset = 1;
323                }
324 
325                StringBuffer paramNameBuf = new StringBuffer(PARAMETER_NAMESPACE_PREFIX
326                                .length()
327                                + origParameterName.length());
328                paramNameBuf.append(PARAMETER_NAMESPACE_PREFIX);
329                paramNameBuf.append(origParameterName.substring(offset));
330 
331                return paramNameBuf.toString();
332        }
333 
334        private boolean callingStoredFunction = false;
335 
336        private ResultSet functionReturnValueResults;
337 
338        private boolean hasOutputParams = false;
339 
340        // private List parameterList;
341        // private Map parameterMap;
342        private ResultSet outputParameterResults;
343 
344        private boolean outputParamWasNull = false;
345 
346        private int[] parameterIndexToRsIndex;
347 
348        protected CallableStatementParamInfo paramInfo;
349 
350        private CallableStatementParam returnValueParam;
351 
352        /**
353         * Creates a new CallableStatement
354         * 
355         * @param conn
356         *            the connection creating this statement
357         * @param paramInfo
358         *            the SQL to prepare
359         * 
360         * @throws SQLException
361         *             if an error occurs
362         */
363        public CallableStatement(Connection conn,
364                        CallableStatementParamInfo paramInfo) throws SQLException {
365                super(conn, paramInfo.nativeSql, paramInfo.catalogInUse);
366 
367                this.paramInfo = paramInfo;
368                this.callingStoredFunction = this.paramInfo.isFunctionCall;
369        }
370 
371        /**
372         * Creates a new CallableStatement
373         * 
374         * @param conn
375         *            the connection creating this statement
376         * @param catalog
377         *            catalog the current catalog
378         * 
379         * @throws SQLException
380         *             if an error occurs
381         */
382        public CallableStatement(Connection conn, String catalog)
383                        throws SQLException {
384                super(conn, catalog, null);
385 
386                determineParameterTypes();
387                generateParameterMap();
388        }
389 
390        private int[] placeholderToParameterIndexMap;
391        
392        private void generateParameterMap() throws SQLException {
393                // if the user specified some parameters as literals, we need to
394                // provide a map from the specified placeholders to the actual
395                // parameter numbers
396                
397                if (this.paramInfo != null &&
398                                this.parameterCount != this.paramInfo.getParameterCount()) {
399                        this.placeholderToParameterIndexMap = new int[this.parameterCount];
400                        
401                        int startPos = StringUtils.indexOfIgnoreCase(this.originalSql, 
402                                        "CALL");
403                        if (startPos != -1) {
404                                int parenOpenPos = this.originalSql.indexOf('(', startPos + 4);
405                                
406                                if (parenOpenPos != -1) {
407                                        int parenClosePos = StringUtils.indexOfIgnoreCaseRespectQuotes(parenOpenPos, 
408                                                        this.originalSql, ")", '\'', true);
409                                        
410                                        if (parenClosePos != -1) {
411                                                List parsedParameters = StringUtils.split(this.originalSql.substring(parenOpenPos + 1, parenClosePos), ",", "'\"", "'\"", true);
412                                                
413                                                int numParsedParameters = parsedParameters.size();
414                                                
415                                                // sanity check
416                                                
417                                                if (numParsedParameters != this.parameterCount) {
418                                                        // bail?
419                                                }
420                                                
421                                                int placeholderCount = 0;
422                                                
423                                                for (int i = 0; i < numParsedParameters; i++) {
424                                                        if (((String)parsedParameters.get(i)).equals("?")) {
425                                                                this.placeholderToParameterIndexMap[placeholderCount++] = i;
426                                                        }
427                                                }
428                                        }
429                                }
430                        }
431                }
432        }
433 
434        /**
435         * Creates a new CallableStatement
436         * 
437         * @param conn
438         *            the connection creating this statement
439         * @param sql
440         *            the SQL to prepare
441         * @param catalog
442         *            the current catalog
443         * 
444         * @throws SQLException
445         *             if an error occurs
446         */
447        public CallableStatement(Connection conn, String sql, String catalog,
448                        boolean isFunctionCall) throws SQLException {
449                super(conn, sql, catalog);
450 
451                this.callingStoredFunction = isFunctionCall;
452 
453                determineParameterTypes();
454                generateParameterMap();
455        }
456 
457        /*
458         * (non-Javadoc)
459         * 
460         * @see java.sql.PreparedStatement#addBatch()
461         */
462        public void addBatch() throws SQLException {
463                setOutParams();
464 
465                super.addBatch();
466        }
467 
468        private CallableStatementParam checkIsOutputParam(int paramIndex)
469                        throws SQLException {
470 
471                if (this.callingStoredFunction) {
472                        if (paramIndex == 1) {
473 
474                                if (this.returnValueParam == null) {
475                                        this.returnValueParam = new CallableStatementParam("", 0,
476                                                        false, true, Types.VARCHAR, "VARCHAR", 0, 0,
477                                                        DatabaseMetaData.attributeNullableUnknown,
478                                                        DatabaseMetaData.procedureColumnReturn);
479                                }
480 
481                                return this.returnValueParam;
482                        }
483 
484                        // Move to position in output result set
485                        paramIndex--;
486                }
487 
488                checkParameterIndexBounds(paramIndex);
489 
490                int localParamIndex = paramIndex - 1;
491 
492                if (this.placeholderToParameterIndexMap != null) {
493                        localParamIndex = this.placeholderToParameterIndexMap[localParamIndex];
494                }
495                
496                CallableStatementParam paramDescriptor = this.paramInfo
497                                .getParameter(localParamIndex);
498 
499                if (!paramDescriptor.isOut) {
500                        throw SQLError.createSQLException(
501                                        Messages.getString("CallableStatement.9") + paramIndex //$NON-NLS-1$
502                                                        + Messages.getString("CallableStatement.10"), //$NON-NLS-1$
503                                        SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
504                }
505 
506                this.hasOutputParams = true;
507 
508                return paramDescriptor;
509        }
510 
511        /**
512         * DOCUMENT ME!
513         * 
514         * @param paramIndex
515         * 
516         * @throws SQLException
517         */
518        private void checkParameterIndexBounds(int paramIndex) throws SQLException {
519                this.paramInfo.checkBounds(paramIndex);
520        }
521 
522        /**
523         * Checks whether or not this statement is supposed to be providing
524         * streamable result sets...If output parameters are registered, the driver
525         * can not stream the results.
526         * 
527         * @throws SQLException
528         *             DOCUMENT ME!
529         */
530        private void checkStreamability() throws SQLException {
531                if (this.hasOutputParams && createStreamingResultSet()) {
532                        throw SQLError.createSQLException(Messages.getString("CallableStatement.14"), //$NON-NLS-1$
533                                        SQLError.SQL_STATE_DRIVER_NOT_CAPABLE);
534                }
535        }
536 
537        public synchronized void clearParameters() throws SQLException {
538                super.clearParameters();
539 
540                try {
541                        if (this.outputParameterResults != null) {
542                                this.outputParameterResults.close();
543                        }
544                } finally {
545                        this.outputParameterResults = null;
546                }
547        }
548 
549        /**
550         * Used to fake up some metadata when we don't have access to 
551         * SHOW CREATE PROCEDURE or mysql.proc.
552         * 
553         * @throws SQLException if we can't build the metadata.
554         */
555        private void fakeParameterTypes() throws SQLException {
556                Field[] fields = new Field[13];
557 
558                fields[0] = new Field("", "PROCEDURE_CAT", Types.CHAR, 0);
559                fields[1] = new Field("", "PROCEDURE_SCHEM", Types.CHAR, 0);
560                fields[2] = new Field("", "PROCEDURE_NAME", Types.CHAR, 0);
561                fields[3] = new Field("", "COLUMN_NAME", Types.CHAR, 0);
562                fields[4] = new Field("", "COLUMN_TYPE", Types.CHAR, 0);
563                fields[5] = new Field("", "DATA_TYPE", Types.SMALLINT, 0);
564                fields[6] = new Field("", "TYPE_NAME", Types.CHAR, 0);
565                fields[7] = new Field("", "PRECISION", Types.INTEGER, 0);
566                fields[8] = new Field("", "LENGTH", Types.INTEGER, 0);
567                fields[9] = new Field("", "SCALE", Types.SMALLINT, 0);
568                fields[10] = new Field("", "RADIX", Types.SMALLINT, 0);
569                fields[11] = new Field("", "NULLABLE", Types.SMALLINT, 0);
570                fields[12] = new Field("", "REMARKS", Types.CHAR, 0);
571 
572                String procName = extractProcedureName();
573 
574                byte[] procNameAsBytes = null;
575 
576                try {
577                        procNameAsBytes = procName.getBytes("UTF-8");
578                } catch (UnsupportedEncodingException ueEx) {
579                        procNameAsBytes = StringUtils.s2b(procName, this.connection);
580                }
581 
582                ArrayList resultRows = new ArrayList();
583 
584                for (int i = 0; i < this.parameterCount; i++) {
585                        byte[][] row = new byte[13][];
586                        row[0] = null; // PROCEDURE_CAT
587                        row[1] = null; // PROCEDURE_SCHEM
588                        row[2] = procNameAsBytes; // PROCEDURE/NAME
589                        row[3] = StringUtils.s2b(String.valueOf(i), this.connection); // COLUMN_NAME
590 
591                        row[4] = StringUtils.s2b(String
592                                        .valueOf(DatabaseMetaData.procedureColumnInOut),
593                                        this.connection);
594 
595                        row[5] = StringUtils.s2b(String.valueOf(Types.VARCHAR),
596                                        this.connection); // DATA_TYPE
597                        row[6] = StringUtils.s2b("VARCHAR", this.connection); // TYPE_NAME
598                        row[7] = StringUtils.s2b(Integer.toString(65535), this.connection); // PRECISION
599                        row[8] = StringUtils.s2b(Integer.toString(65535), this.connection); // LENGTH
600                        row[9] = StringUtils.s2b(Integer.toString(0), this.connection); // SCALE
601                        row[10] = StringUtils.s2b(Integer.toString(10), this.connection); // RADIX
602 
603                        row[11] = StringUtils.s2b(Integer
604                                        .toString(DatabaseMetaData.procedureNullableUnknown),
605                                        this.connection); // nullable
606 
607                        row[12] = null;
608 
609                        resultRows.add(row);
610                }
611 
612                java.sql.ResultSet paramTypesRs = DatabaseMetaData.buildResultSet(
613                                fields, resultRows, this.connection);
614 
615                convertGetProcedureColumnsToInternalDescriptors(paramTypesRs);
616        }
617        
618        private void determineParameterTypes() throws SQLException {
619                if (this.connection.getNoAccessToProcedureBodies()) {
620                        fakeParameterTypes();
621                        
622                        return;
623                }
624                
625                java.sql.ResultSet paramTypesRs = null;
626 
627                try {
628                        String procName = extractProcedureName();
629 
630                        java.sql.DatabaseMetaData dbmd = this.connection.getMetaData();
631 
632                        boolean useCatalog = false;
633 
634                        if (procName.indexOf(".") == -1) {
635                                useCatalog = true;
636                        }
637 
638                        paramTypesRs = dbmd.getProcedureColumns(this.connection
639                                        .versionMeetsMinimum(5, 0, 2)
640                                        & useCatalog ? this.currentCatalog : null, null, procName,
641                                        "%"); //$NON-NLS-1$
642 
643                        convertGetProcedureColumnsToInternalDescriptors(paramTypesRs);
644                } finally {
645                        SQLException sqlExRethrow = null;
646 
647                        if (paramTypesRs != null) {
648                                try {
649                                        paramTypesRs.close();
650                                } catch (SQLException sqlEx) {
651                                        sqlExRethrow = sqlEx;
652                                }
653 
654                                paramTypesRs = null;
655                        }
656 
657                        if (sqlExRethrow != null) {
658                                throw sqlExRethrow;
659                        }
660                }
661        }
662 
663        private void convertGetProcedureColumnsToInternalDescriptors(java.sql.ResultSet paramTypesRs) throws SQLException {
664                if (!this.connection.isRunningOnJDK13()) {
665                        this.paramInfo = new CallableStatementParamInfoJDBC3(
666                                        paramTypesRs);
667                } else {
668                        this.paramInfo = new CallableStatementParamInfo(paramTypesRs);
669                }
670        }
671 
672        /*
673         * (non-Javadoc)
674         * 
675         * @see java.sql.PreparedStatement#execute()
676         */
677        public boolean execute() throws SQLException {
678                boolean returnVal = false;
679 
680                checkClosed();
681 
682                checkStreamability();
683 
684                synchronized (this.connection.getMutex()) {
685                        setInOutParamsOnServer();
686                        setOutParams();
687 
688                        returnVal = super.execute();
689 
690                        if (this.callingStoredFunction) {
691                                this.functionReturnValueResults = this.results;
692                                this.functionReturnValueResults.next();
693                                this.results = null;
694                        }
695 
696                        retrieveOutParams();
697                }
698 
699                if (!this.callingStoredFunction) {
700                        return returnVal;
701                }
702 
703                // Functions can't return results
704                return false;
705        }
706 
707        /*
708         * (non-Javadoc)
709         * 
710         * @see java.sql.PreparedStatement#executeQuery()
711         */
712        public java.sql.ResultSet executeQuery() throws SQLException {
713                checkClosed();
714 
715                checkStreamability();
716 
717                java.sql.ResultSet execResults = null;
718 
719                synchronized (this.connection.getMutex()) {
720                        setInOutParamsOnServer();
721                        setOutParams();
722 
723                        execResults = super.executeQuery();
724 
725                        retrieveOutParams();
726                }
727 
728                return execResults;
729        }
730 
731        /*
732         * (non-Javadoc)
733         * 
734         * @see java.sql.PreparedStatement#executeUpdate()
735         */
736        public int executeUpdate() throws SQLException {
737                int returnVal = -1;
738 
739                checkClosed();
740 
741                checkStreamability();
742 
743                if (this.callingStoredFunction) {
744                        execute();
745 
746                        return -1;
747                }
748 
749                synchronized (this.connection.getMutex()) {
750                        setInOutParamsOnServer();
751                        setOutParams();
752 
753                        returnVal = super.executeUpdate();
754 
755                        retrieveOutParams();
756                }
757 
758                return returnVal;
759        }
760 
761        private String extractProcedureName() throws SQLException {
762                // TODO: Do this with less memory allocation
763                int endCallIndex = StringUtils.indexOfIgnoreCase(this.originalSql,
764                                "CALL "); //$NON-NLS-1$
765                int offset = 5;
766 
767                if (endCallIndex == -1) {
768                        endCallIndex = StringUtils.indexOfIgnoreCase(this.originalSql,
769                                        "SELECT ");
770                        offset = 7;
771                }
772 
773                if (endCallIndex != -1) {
774                        StringBuffer nameBuf = new StringBuffer();
775 
776                        String trimmedStatement = this.originalSql.substring(
777                                        endCallIndex + offset).trim();
778 
779                        int statementLength = trimmedStatement.length();
780 
781                        for (int i = 0; i < statementLength; i++) {
782                                char c = trimmedStatement.charAt(i);
783 
784                                if (Character.isWhitespace(c) || (c == '(') || (c == '?')) {
785                                        break;
786                                }
787                                nameBuf.append(c);
788 
789                        }
790 
791                        return nameBuf.toString();
792                }
793                throw SQLError.createSQLException(Messages.getString("CallableStatement.1"), //$NON-NLS-1$
794                                SQLError.SQL_STATE_GENERAL_ERROR);
795 
796        }
797 
798        /**
799         * Adds 'at' symbol to beginning of parameter names if needed.
800         * 
801         * @param paramNameIn
802         *            the parameter name to 'fix'
803         * 
804         * @return the parameter name with an 'a' prepended, if needed
805         * 
806         * @throws SQLException
807         *             if the parameter name is null or empty.
808         */
809        private String fixParameterName(String paramNameIn) throws SQLException {
810                if ((paramNameIn == null) || (paramNameIn.length() == 0)) {
811                        throw SQLError.createSQLException(
812                                        ((Messages.getString("CallableStatement.0") + paramNameIn) == null) //$NON-NLS-1$
813                                                        ? Messages.getString("CallableStatement.15") : Messages.getString("CallableStatement.16"), SQLError.SQL_STATE_ILLEGAL_ARGUMENT); //$NON-NLS-1$ //$NON-NLS-2$
814                }
815 
816                if (this.connection.getNoAccessToProcedureBodies()) {
817                        throw SQLError.createSQLException("No access to parameters by name when connection has been configured not to access procedure bodies",
818                                        SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
819                }
820                
821                return mangleParameterName(paramNameIn);
822 
823                /*
824                 * if (paramNameIn.startsWith("@")) { return paramNameIn; } else {
825                 * StringBuffer paramNameBuf = new StringBuffer("@");
826                 * paramNameBuf.append(paramNameIn);
827                 * 
828                 * return paramNameBuf.toString(); }
829                 */
830        }
831 
832        /**
833         * @see java.sql.CallableStatement#getArray(int)
834         */
835        public synchronized Array getArray(int i) throws SQLException {
836                ResultSet rs = getOutputParameters(i);
837 
838                Array retValue = rs.getArray(mapOutputParameterIndexToRsIndex(i));
839 
840                this.outputParamWasNull = rs.wasNull();
841 
842                return retValue;
843        }
844 
845        /**
846         * @see java.sql.CallableStatement#getArray(java.lang.String)
847         */
848        public synchronized Array getArray(String parameterName)
849                        throws SQLException {
850                ResultSet rs = getOutputParameters(0); // definitely not going to be
851                // from ?=
852 
853                Array retValue = rs.getArray(fixParameterName(parameterName));
854 
855                this.outputParamWasNull = rs.wasNull();
856 
857                return retValue;
858        }
859 
860        /**
861         * @see java.sql.CallableStatement#getBigDecimal(int)
862         */
863        public synchronized BigDecimal getBigDecimal(int parameterIndex)
864                        throws SQLException {
865                ResultSet rs = getOutputParameters(parameterIndex);
866 
867                BigDecimal retValue = rs
868                                .getBigDecimal(mapOutputParameterIndexToRsIndex(parameterIndex));
869 
870                this.outputParamWasNull = rs.wasNull();
871 
872                return retValue;
873        }
874 
875        /**
876         * DOCUMENT ME!
877         * 
878         * @param parameterIndex
879         *            DOCUMENT ME!
880         * @param scale
881         *            DOCUMENT ME!
882         * 
883         * @return DOCUMENT ME!
884         * 
885         * @throws SQLException
886         *             DOCUMENT ME!
887         * 
888         * @see java.sql.CallableStatement#getBigDecimal(int, int)
889         * @deprecated
890         */
891        public synchronized BigDecimal getBigDecimal(int parameterIndex, int scale)
892                        throws SQLException {
893                ResultSet rs = getOutputParameters(parameterIndex);
894 
895                BigDecimal retValue = rs.getBigDecimal(
896                                mapOutputParameterIndexToRsIndex(parameterIndex), scale);
897 
898                this.outputParamWasNull = rs.wasNull();
899 
900                return retValue;
901        }
902 
903        /**
904         * @see java.sql.CallableStatement#getBigDecimal(java.lang.String)
905         */
906        public synchronized BigDecimal getBigDecimal(String parameterName)
907                        throws SQLException {
908                ResultSet rs = getOutputParameters(0); // definitely not going to be
909                // from ?=
910 
911                BigDecimal retValue = rs.getBigDecimal(fixParameterName(parameterName));
912 
913                this.outputParamWasNull = rs.wasNull();
914 
915                return retValue;
916        }
917 
918        /**
919         * @see java.sql.CallableStatement#getBlob(int)
920         */
921        public synchronized Blob getBlob(int parameterIndex) throws SQLException {
922                ResultSet rs = getOutputParameters(parameterIndex);
923 
924                Blob retValue = rs
925                                .getBlob(mapOutputParameterIndexToRsIndex(parameterIndex));
926 
927                this.outputParamWasNull = rs.wasNull();
928 
929                return retValue;
930        }
931 
932        /**
933         * @see java.sql.CallableStatement#getBlob(java.lang.String)
934         */
935        public synchronized Blob getBlob(String parameterName) throws SQLException {
936                ResultSet rs = getOutputParameters(0); // definitely not going to be
937                // from ?=
938 
939                Blob retValue = rs.getBlob(fixParameterName(parameterName));
940 
941                this.outputParamWasNull = rs.wasNull();
942 
943                return retValue;
944        }
945 
946        /**
947         * @see java.sql.CallableStatement#getBoolean(int)
948         */
949        public synchronized boolean getBoolean(int parameterIndex)
950                        throws SQLException {
951                ResultSet rs = getOutputParameters(parameterIndex);
952 
953                boolean retValue = rs
954                                .getBoolean(mapOutputParameterIndexToRsIndex(parameterIndex));
955 
956                this.outputParamWasNull = rs.wasNull();
957 
958                return retValue;
959        }
960 
961        /**
962         * @see java.sql.CallableStatement#getBoolean(java.lang.String)
963         */
964        public synchronized boolean getBoolean(String parameterName)
965                        throws SQLException {
966                ResultSet rs = getOutputParameters(0); // definitely not going to be
967                // from ?=
968 
969                boolean retValue = rs.getBoolean(fixParameterName(parameterName));
970 
971                this.outputParamWasNull = rs.wasNull();
972 
973                return retValue;
974        }
975 
976        /**
977         * @see java.sql.CallableStatement#getByte(int)
978         */
979        public synchronized byte getByte(int parameterIndex) throws SQLException {
980                ResultSet rs = getOutputParameters(parameterIndex);
981 
982                byte retValue = rs
983                                .getByte(mapOutputParameterIndexToRsIndex(parameterIndex));
984 
985                this.outputParamWasNull = rs.wasNull();
986 
987                return retValue;
988        }
989 
990        /**
991         * @see java.sql.CallableStatement#getByte(java.lang.String)
992         */
993        public synchronized byte getByte(String parameterName) throws SQLException {
994                ResultSet rs = getOutputParameters(0); // definitely not going to be
995                // from ?=
996 
997                byte retValue = rs.getByte(fixParameterName(parameterName));
998 
999                this.outputParamWasNull = rs.wasNull();
1000 
1001                return retValue;
1002        }
1003 
1004        /**
1005         * @see java.sql.CallableStatement#getBytes(int)
1006         */
1007        public synchronized byte[] getBytes(int parameterIndex) throws SQLException {
1008                ResultSet rs = getOutputParameters(parameterIndex);
1009 
1010                byte[] retValue = rs
1011                                .getBytes(mapOutputParameterIndexToRsIndex(parameterIndex));
1012 
1013                this.outputParamWasNull = rs.wasNull();
1014 
1015                return retValue;
1016        }
1017 
1018        /**
1019         * @see java.sql.CallableStatement#getBytes(java.lang.String)
1020         */
1021        public synchronized byte[] getBytes(String parameterName)
1022                        throws SQLException {
1023                ResultSet rs = getOutputParameters(0); // definitely not going to be
1024                // from ?=
1025 
1026                byte[] retValue = rs.getBytes(fixParameterName(parameterName));
1027 
1028                this.outputParamWasNull = rs.wasNull();
1029 
1030                return retValue;
1031        }
1032 
1033        /**
1034         * @see java.sql.CallableStatement#getClob(int)
1035         */
1036        public synchronized Clob getClob(int parameterIndex) throws SQLException {
1037                ResultSet rs = getOutputParameters(parameterIndex);
1038 
1039                Clob retValue = rs
1040                                .getClob(mapOutputParameterIndexToRsIndex(parameterIndex));
1041 
1042                this.outputParamWasNull = rs.wasNull();
1043 
1044                return retValue;
1045        }
1046 
1047        /**
1048         * @see java.sql.CallableStatement#getClob(java.lang.String)
1049         */
1050        public synchronized Clob getClob(String parameterName) throws SQLException {
1051                ResultSet rs = getOutputParameters(0); // definitely not going to be
1052                // from ?=
1053 
1054                Clob retValue = rs.getClob(fixParameterName(parameterName));
1055 
1056                this.outputParamWasNull = rs.wasNull();
1057 
1058                return retValue;
1059        }
1060 
1061        /**
1062         * @see java.sql.CallableStatement#getDate(int)
1063         */
1064        public synchronized Date getDate(int parameterIndex) throws SQLException {
1065                ResultSet rs = getOutputParameters(parameterIndex);
1066 
1067                Date retValue = rs
1068                                .getDate(mapOutputParameterIndexToRsIndex(parameterIndex));
1069 
1070                this.outputParamWasNull = rs.wasNull();
1071 
1072                return retValue;
1073        }
1074 
1075        /**
1076         * @see java.sql.CallableStatement#getDate(int, java.util.Calendar)
1077         */
1078        public synchronized Date getDate(int parameterIndex, Calendar cal)
1079                        throws SQLException {
1080                ResultSet rs = getOutputParameters(parameterIndex);
1081 
1082                Date retValue = rs.getDate(
1083                                mapOutputParameterIndexToRsIndex(parameterIndex), cal);
1084 
1085                this.outputParamWasNull = rs.wasNull();
1086 
1087                return retValue;
1088        }
1089 
1090        /**
1091         * @see java.sql.CallableStatement#getDate(java.lang.String)
1092         */
1093        public synchronized Date getDate(String parameterName) throws SQLException {
1094                ResultSet rs = getOutputParameters(0); // definitely not going to be
1095                // from ?=
1096 
1097                Date retValue = rs.getDate(fixParameterName(parameterName));
1098 
1099                this.outputParamWasNull = rs.wasNull();
1100 
1101                return retValue;
1102        }
1103 
1104        /**
1105         * @see java.sql.CallableStatement#getDate(java.lang.String,
1106         *      java.util.Calendar)
1107         */
1108        public synchronized Date getDate(String parameterName, Calendar cal)
1109                        throws SQLException {
1110                ResultSet rs = getOutputParameters(0); // definitely not going to be
1111                // from ?=
1112 
1113                Date retValue = rs.getDate(fixParameterName(parameterName), cal);
1114 
1115                this.outputParamWasNull = rs.wasNull();
1116 
1117                return retValue;
1118        }
1119 
1120        /**
1121         * @see java.sql.CallableStatement#getDouble(int)
1122         */
1123        public synchronized double getDouble(int parameterIndex)
1124                        throws SQLException {
1125                ResultSet rs = getOutputParameters(parameterIndex);
1126 
1127                double retValue = rs
1128                                .getDouble(mapOutputParameterIndexToRsIndex(parameterIndex));
1129 
1130                this.outputParamWasNull = rs.wasNull();
1131 
1132                return retValue;
1133        }
1134 
1135        /**
1136         * @see java.sql.CallableStatement#getDouble(java.lang.String)
1137         */
1138        public synchronized double getDouble(String parameterName)
1139                        throws SQLException {
1140                ResultSet rs = getOutputParameters(0); // definitely not going to be
1141                // from ?=
1142 
1143                double retValue = rs.getDouble(fixParameterName(parameterName));
1144 
1145                this.outputParamWasNull = rs.wasNull();
1146 
1147                return retValue;
1148        }
1149 
1150        /**
1151         * @see java.sql.CallableStatement#getFloat(int)
1152         */
1153        public synchronized float getFloat(int parameterIndex) throws SQLException {
1154                ResultSet rs = getOutputParameters(parameterIndex);
1155 
1156                float retValue = rs
1157                                .getFloat(mapOutputParameterIndexToRsIndex(parameterIndex));
1158 
1159                this.outputParamWasNull = rs.wasNull();
1160 
1161                return retValue;
1162        }
1163 
1164        /**
1165         * @see java.sql.CallableStatement#getFloat(java.lang.String)
1166         */
1167        public synchronized float getFloat(String parameterName)
1168                        throws SQLException {
1169                ResultSet rs = getOutputParameters(0); // definitely not going to be
1170                // from ?=
1171 
1172                float retValue = rs.getFloat(fixParameterName(parameterName));
1173 
1174                this.outputParamWasNull = rs.wasNull();
1175 
1176                return retValue;
1177        }
1178 
1179        /**
1180         * @see java.sql.CallableStatement#getInt(int)
1181         */
1182        public synchronized int getInt(int parameterIndex) throws SQLException {
1183                ResultSet rs = getOutputParameters(parameterIndex);
1184 
1185                int retValue = rs
1186                                .getInt(mapOutputParameterIndexToRsIndex(parameterIndex));
1187 
1188                this.outputParamWasNull = rs.wasNull();
1189 
1190                return retValue;
1191        }
1192 
1193        /**
1194         * @see java.sql.CallableStatement#getInt(java.lang.String)
1195         */
1196        public synchronized int getInt(String parameterName) throws SQLException {
1197                ResultSet rs = getOutputParameters(0); // definitely not going to be
1198                // from ?=
1199 
1200                int retValue = rs.getInt(fixParameterName(parameterName));
1201 
1202                this.outputParamWasNull = rs.wasNull();
1203 
1204                return retValue;
1205        }
1206 
1207        /**
1208         * @see java.sql.CallableStatement#getLong(int)
1209         */
1210        public synchronized long getLong(int parameterIndex) throws SQLException {
1211                ResultSet rs = getOutputParameters(parameterIndex);
1212 
1213                long retValue = rs
1214                                .getLong(mapOutputParameterIndexToRsIndex(parameterIndex));
1215 
1216                this.outputParamWasNull = rs.wasNull();
1217 
1218                return retValue;
1219        }
1220 
1221        /**
1222         * @see java.sql.CallableStatement#getLong(java.lang.String)
1223         */
1224        public synchronized long getLong(String parameterName) throws SQLException {
1225                ResultSet rs = getOutputParameters(0); // definitely not going to be
1226                // from ?=
1227 
1228                long retValue = rs.getLong(fixParameterName(parameterName));
1229 
1230                this.outputParamWasNull = rs.wasNull();
1231 
1232                return retValue;
1233        }
1234 
1235        private int getNamedParamIndex(String paramName, boolean forOut)
1236        throws SQLException {
1237                if (this.connection.getNoAccessToProcedureBodies()) {
1238                        throw SQLError.createSQLException("No access to parameters by name when connection has been configured not to access procedure bodies",
1239                                        SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
1240                }
1241                
1242                if ((paramName == null) || (paramName.length() == 0)) {
1243                        throw SQLError.createSQLException(Messages.getString("CallableStatement.2"), //$NON-NLS-1$
1244                                        SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
1245                }
1246 
1247                CallableStatementParam namedParamInfo = this.paramInfo
1248                .getParameter(paramName);
1249 
1250                if (this.paramInfo == null) {
1251                        throw SQLError.createSQLException(
1252                                        Messages.getString("CallableStatement.3") + paramName + Messages.getString("CallableStatement.4"), //$NON-NLS-1$ //$NON-NLS-2$
1253                                        SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
1254                }
1255 
1256                if (forOut && !namedParamInfo.isOut) {
1257                        throw SQLError.createSQLException(
1258                                        Messages.getString("CallableStatement.5") + paramName //$NON-NLS-1$
1259                                        + Messages.getString("CallableStatement.6"), //$NON-NLS-1$
1260                                        SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
1261                }
1262 
1263 
1264                if (this.placeholderToParameterIndexMap == null) {
1265                        return namedParamInfo.index + 1; // JDBC indices are 1-based
1266                } 
1267 
1268                for (int i = 0; i < this.placeholderToParameterIndexMap.length; i++) {
1269                        if (this.placeholderToParameterIndexMap[i] == namedParamInfo.index) {
1270                                return i + 1;
1271                        }
1272                }
1273 
1274                throw SQLError.createSQLException("Can't find local placeholder mapping for parameter named \"" + 
1275                                paramName + "\".", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
1276        }
1277 
1278        /**
1279         * @see java.sql.CallableStatement#getObject(int)
1280         */
1281        public synchronized Object getObject(int parameterIndex)
1282                        throws SQLException {
1283                CallableStatementParam paramDescriptor = checkIsOutputParam(parameterIndex);
1284 
1285                ResultSet rs = getOutputParameters(parameterIndex);
1286 
1287                Object retVal = rs.getObjectStoredProc(
1288                                mapOutputParameterIndexToRsIndex(parameterIndex),
1289                                paramDescriptor.desiredJdbcType);
1290 
1291                this.outputParamWasNull = rs.wasNull();
1292 
1293                return retVal;
1294        }
1295 
1296        /**
1297         * @see java.sql.CallableStatement#getObject(int, java.util.Map)
1298         */
1299        public synchronized Object getObject(int parameterIndex, Map map)
1300                        throws SQLException {
1301                ResultSet rs = getOutputParameters(parameterIndex);
1302 
1303                Object retVal = rs.getObject(
1304                                mapOutputParameterIndexToRsIndex(parameterIndex), map);
1305 
1306                this.outputParamWasNull = rs.wasNull();
1307 
1308                return retVal;
1309        }
1310 
1311        /**
1312         * @see java.sql.CallableStatement#getObject(java.lang.String)
1313         */
1314        public synchronized Object getObject(String parameterName)
1315                        throws SQLException {
1316                ResultSet rs = getOutputParameters(0); // definitely not going to be
1317                // from ?=
1318 
1319                Object retValue = rs.getObject(fixParameterName(parameterName));
1320 
1321                this.outputParamWasNull = rs.wasNull();
1322 
1323                return retValue;
1324        }
1325 
1326        /**
1327         * @see java.sql.CallableStatement#getObject(java.lang.String,
1328         *      java.util.Map)
1329         */
1330        public synchronized Object getObject(String parameterName, Map map)
1331                        throws SQLException {
1332                ResultSet rs = getOutputParameters(0); // definitely not going to be
1333                // from ?=
1334 
1335                Object retValue = rs.getObject(fixParameterName(parameterName), map);
1336 
1337                this.outputParamWasNull = rs.wasNull();
1338 
1339                return retValue;
1340        }
1341 
1342        /**
1343         * Returns the ResultSet that holds the output parameters, or throws an
1344         * appropriate exception if none exist, or they weren't returned.
1345         * 
1346         * @return the ResultSet that holds the output parameters
1347         * 
1348         * @throws SQLException
1349         *             if no output parameters were defined, or if no output
1350         *             parameters were returned.
1351         */
1352        private ResultSet getOutputParameters(int paramIndex) throws SQLException {
1353                this.outputParamWasNull = false;
1354 
1355                if (paramIndex == 1 && this.callingStoredFunction
1356                                && this.returnValueParam != null) {
1357                        return this.functionReturnValueResults;
1358                }
1359 
1360                if (this.outputParameterResults == null) {
1361                        if (this.paramInfo.numberOfParameters() == 0) {
1362                                throw SQLError.createSQLException(Messages
1363                                                .getString("CallableStatement.7"), //$NON-NLS-1$
1364                                                SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
1365                        }
1366                        throw SQLError.createSQLException(Messages.getString("CallableStatement.8"), //$NON-NLS-1$
1367                                        SQLError.SQL_STATE_GENERAL_ERROR);
1368                }
1369 
1370                return this.outputParameterResults;
1371 
1372        }
1373 
1374        public synchronized ParameterMetaData getParameterMetaData()
1375                        throws SQLException {
1376                return (CallableStatementParamInfoJDBC3) this.paramInfo;
1377        }
1378 
1379        /**
1380         * @see java.sql.CallableStatement#getRef(int)
1381         */
1382        public synchronized Ref getRef(int parameterIndex) throws SQLException {
1383                ResultSet rs = getOutputParameters(parameterIndex);
1384 
1385                Ref retValue = rs
1386                                .getRef(mapOutputParameterIndexToRsIndex(parameterIndex));
1387 
1388                this.outputParamWasNull = rs.wasNull();
1389 
1390                return retValue;
1391        }
1392 
1393        /**
1394         * @see java.sql.CallableStatement#getRef(java.lang.String)
1395         */
1396        public synchronized Ref getRef(String parameterName) throws SQLException {
1397                ResultSet rs = getOutputParameters(0); // definitely not going to be
1398                // from ?=
1399 
1400                Ref retValue = rs.getRef(fixParameterName(parameterName));
1401 
1402                this.outputParamWasNull = rs.wasNull();
1403 
1404                return retValue;
1405        }
1406 
1407        /**
1408         * @see java.sql.CallableStatement#getShort(int)
1409         */
1410        public synchronized short getShort(int parameterIndex) throws SQLException {
1411                ResultSet rs = getOutputParameters(parameterIndex);
1412 
1413                short retValue = rs
1414                                .getShort(mapOutputParameterIndexToRsIndex(parameterIndex));
1415 
1416                this.outputParamWasNull = rs.wasNull();
1417 
1418                return retValue;
1419        }
1420 
1421        /**
1422         * @see java.sql.CallableStatement#getShort(java.lang.String)
1423         */
1424        public synchronized short getShort(String parameterName)
1425                        throws SQLException {
1426                ResultSet rs = getOutputParameters(0); // definitely not going to be
1427                // from ?=
1428 
1429                short retValue = rs.getShort(fixParameterName(parameterName));
1430 
1431                this.outputParamWasNull = rs.wasNull();
1432 
1433                return retValue;
1434        }
1435 
1436        /**
1437         * @see java.sql.CallableStatement#getString(int)
1438         */
1439        public synchronized String getString(int parameterIndex)
1440                        throws SQLException {
1441                ResultSet rs = getOutputParameters(parameterIndex);
1442 
1443                String retValue = rs
1444                                .getString(mapOutputParameterIndexToRsIndex(parameterIndex));
1445 
1446                this.outputParamWasNull = rs.wasNull();
1447 
1448                return retValue;
1449        }
1450 
1451        /**
1452         * @see java.sql.CallableStatement#getString(java.lang.String)
1453         */
1454        public synchronized String getString(String parameterName)
1455                        throws SQLException {
1456                ResultSet rs = getOutputParameters(0); // definitely not going to be
1457                // from ?=
1458 
1459                String retValue = rs.getString(fixParameterName(parameterName));
1460 
1461                this.outputParamWasNull = rs.wasNull();
1462 
1463                return retValue;
1464        }
1465 
1466        /**
1467         * @see java.sql.CallableStatement#getTime(int)
1468         */
1469        public synchronized Time getTime(int parameterIndex) throws SQLException {
1470                ResultSet rs = getOutputParameters(parameterIndex);
1471 
1472                Time retValue = rs
1473                                .getTime(mapOutputParameterIndexToRsIndex(parameterIndex));
1474 
1475                this.outputParamWasNull = rs.wasNull();
1476 
1477                return retValue;
1478        }
1479 
1480        /**
1481         * @see java.sql.CallableStatement#getTime(int, java.util.Calendar)
1482         */
1483        public synchronized Time getTime(int parameterIndex, Calendar cal)
1484                        throws SQLException {
1485                ResultSet rs = getOutputParameters(parameterIndex);
1486 
1487                Time retValue = rs.getTime(
1488                                mapOutputParameterIndexToRsIndex(parameterIndex), cal);
1489 
1490                this.outputParamWasNull = rs.wasNull();
1491 
1492                return retValue;
1493        }
1494 
1495        /**
1496         * @see java.sql.CallableStatement#getTime(java.lang.String)
1497         */
1498        public synchronized Time getTime(String parameterName) throws SQLException {
1499                ResultSet rs = getOutputParameters(0); // definitely not going to be
1500                // from ?=
1501 
1502                Time retValue = rs.getTime(fixParameterName(parameterName));
1503 
1504                this.outputParamWasNull = rs.wasNull();
1505 
1506                return retValue;
1507        }
1508 
1509        /**
1510         * @see java.sql.CallableStatement#getTime(java.lang.String,
1511         *      java.util.Calendar)
1512         */
1513        public synchronized Time getTime(String parameterName, Calendar cal)
1514                        throws SQLException {
1515                ResultSet rs = getOutputParameters(0); // definitely not going to be
1516                // from ?=
1517 
1518                Time retValue = rs.getTime(fixParameterName(parameterName), cal);
1519 
1520                this.outputParamWasNull = rs.wasNull();
1521 
1522                return retValue;
1523        }
1524 
1525        /**
1526         * @see java.sql.CallableStatement#getTimestamp(int)
1527         */
1528        public synchronized Timestamp getTimestamp(int parameterIndex)
1529                        throws SQLException {
1530                ResultSet rs = getOutputParameters(parameterIndex);
1531 
1532                Timestamp retValue = rs
1533                                .getTimestamp(mapOutputParameterIndexToRsIndex(parameterIndex));
1534 
1535                this.outputParamWasNull = rs.wasNull();
1536 
1537                return retValue;
1538        }
1539 
1540        /**
1541         * @see java.sql.CallableStatement#getTimestamp(int, java.util.Calendar)
1542         */
1543        public synchronized Timestamp getTimestamp(int parameterIndex, Calendar cal)
1544                        throws SQLException {
1545                ResultSet rs = getOutputParameters(parameterIndex);
1546 
1547                Timestamp retValue = rs.getTimestamp(
1548                                mapOutputParameterIndexToRsIndex(parameterIndex), cal);
1549 
1550                this.outputParamWasNull = rs.wasNull();
1551 
1552                return retValue;
1553        }
1554 
1555        /**
1556         * @see java.sql.CallableStatement#getTimestamp(java.lang.String)
1557         */
1558        public synchronized Timestamp getTimestamp(String parameterName)
1559                        throws SQLException {
1560                ResultSet rs = getOutputParameters(0); // definitely not going to be
1561                // from ?=
1562 
1563                Timestamp retValue = rs.getTimestamp(fixParameterName(parameterName));
1564 
1565                this.outputParamWasNull = rs.wasNull();
1566 
1567                return retValue;
1568        }
1569 
1570        /**
1571         * @see java.sql.CallableStatement#getTimestamp(java.lang.String,
1572         *      java.util.Calendar)
1573         */
1574        public synchronized Timestamp getTimestamp(String parameterName,
1575                        Calendar cal) throws SQLException {
1576                ResultSet rs = getOutputParameters(0); // definitely not going to be
1577                // from ?=
1578 
1579                Timestamp retValue = rs.getTimestamp(fixParameterName(parameterName),
1580                                cal);
1581 
1582                this.outputParamWasNull = rs.wasNull();
1583 
1584                return retValue;
1585        }
1586 
1587        /**
1588         * @see java.sql.CallableStatement#getURL(int)
1589         */
1590        public synchronized URL getURL(int parameterIndex) throws SQLException {
1591                ResultSet rs = getOutputParameters(parameterIndex);
1592 
1593                URL retValue = rs
1594                                .getURL(mapOutputParameterIndexToRsIndex(parameterIndex));
1595 
1596                this.outputParamWasNull = rs.wasNull();
1597 
1598                return retValue;
1599        }
1600 
1601        /**
1602         * @see java.sql.CallableStatement#getURL(java.lang.String)
1603         */
1604        public synchronized URL getURL(String parameterName) throws SQLException {
1605                ResultSet rs = getOutputParameters(0); // definitely not going to be
1606                // from ?=
1607 
1608                URL retValue = rs.getURL(fixParameterName(parameterName));
1609 
1610                this.outputParamWasNull = rs.wasNull();
1611 
1612                return retValue;
1613        }
1614 
1615        private int mapOutputParameterIndexToRsIndex(int paramIndex)
1616                        throws SQLException {
1617 
1618                if (this.returnValueParam != null && paramIndex == 1) {
1619                        return 1;
1620                }
1621 
1622                checkParameterIndexBounds(paramIndex);
1623 
1624                int localParamIndex = paramIndex - 1;
1625 
1626                if (this.placeholderToParameterIndexMap != null) {
1627                        localParamIndex = this.placeholderToParameterIndexMap[localParamIndex];
1628                }
1629 
1630                int rsIndex = this.parameterIndexToRsIndex[localParamIndex];
1631 
1632                if (rsIndex == NOT_OUTPUT_PARAMETER_INDICATOR) {
1633                        throw SQLError.createSQLException(
1634                                        Messages.getString("CallableStatement.21") + paramIndex //$NON-NLS-1$
1635                                                        + Messages.getString("CallableStatement.22"), //$NON-NLS-1$
1636                                        SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
1637                }
1638 
1639                return rsIndex + 1;
1640        }
1641 
1642        /**
1643         * @see java.sql.CallableStatement#registerOutParameter(int, int)
1644         */
1645        public void registerOutParameter(int parameterIndex, int sqlType)
1646                        throws SQLException {
1647                CallableStatementParam paramDescriptor = checkIsOutputParam(parameterIndex);
1648                paramDescriptor.desiredJdbcType = sqlType;
1649        }
1650 
1651        /**
1652         * @see java.sql.CallableStatement#registerOutParameter(int, int, int)
1653         */
1654        public void registerOutParameter(int parameterIndex, int sqlType, int scale)
1655                        throws SQLException {
1656                registerOutParameter(parameterIndex, sqlType);
1657        }
1658 
1659        /**
1660         * @see java.sql.CallableStatement#registerOutParameter(int, int,
1661         *      java.lang.String)
1662         */
1663        public void registerOutParameter(int parameterIndex, int sqlType,
1664                        String typeName) throws SQLException {
1665                checkIsOutputParam(parameterIndex);
1666        }
1667 
1668        /**
1669         * @see java.sql.CallableStatement#registerOutParameter(java.lang.String,
1670         *      int)
1671         */
1672        public synchronized void registerOutParameter(String parameterName,
1673                        int sqlType) throws SQLException {
1674                registerOutParameter(getNamedParamIndex(parameterName, true), sqlType);
1675        }
1676 
1677        /**
1678         * @see java.sql.CallableStatement#registerOutParameter(java.lang.String,
1679         *      int, int)
1680         */
1681        public void registerOutParameter(String parameterName, int sqlType,
1682                        int scale) throws SQLException {
1683                registerOutParameter(getNamedParamIndex(parameterName, true), sqlType);
1684        }
1685 
1686        /**
1687         * @see java.sql.CallableStatement#registerOutParameter(java.lang.String,
1688         *      int, java.lang.String)
1689         */
1690        public void registerOutParameter(String parameterName, int sqlType,
1691                        String typeName) throws SQLException {
1692                registerOutParameter(getNamedParamIndex(parameterName, true), sqlType,
1693                                typeName);
1694        }
1695 
1696        /**
1697         * Issues a second query to retrieve all output parameters.
1698         * 
1699         * @throws SQLException
1700         *             if an error occurs.
1701         */
1702        private void retrieveOutParams() throws SQLException {
1703                int numParameters = this.paramInfo.numberOfParameters();
1704 
1705                this.parameterIndexToRsIndex = new int[numParameters];
1706 
1707                for (int i = 0; i < numParameters; i++) {
1708                        this.parameterIndexToRsIndex[i] = NOT_OUTPUT_PARAMETER_INDICATOR;
1709                }
1710 
1711                int localParamIndex = 0;
1712 
1713                if (numParameters > 0) {
1714                        StringBuffer outParameterQuery = new StringBuffer("SELECT "); //$NON-NLS-1$
1715 
1716                        boolean firstParam = true;
1717                        boolean hadOutputParams = false;
1718 
1719                        for (Iterator paramIter = this.paramInfo.iterator(); paramIter
1720                                        .hasNext();) {
1721                                CallableStatementParam retrParamInfo = (CallableStatementParam) paramIter
1722                                                .next();
1723 
1724                                if (retrParamInfo.isOut) {
1725                                        hadOutputParams = true;
1726 
1727                                        this.parameterIndexToRsIndex[retrParamInfo.index] = localParamIndex++;
1728 
1729                                        String outParameterName = mangleParameterName(retrParamInfo.paramName);
1730 
1731                                        if (!firstParam) {
1732                                                outParameterQuery.append(","); //$NON-NLS-1$
1733                                        } else {
1734                                                firstParam = false;
1735                                        }
1736 
1737                                        if (!outParameterName.startsWith("@")) { //$NON-NLS-1$
1738                                                outParameterQuery.append('@');
1739                                        }
1740 
1741                                        outParameterQuery.append(outParameterName);
1742                                }
1743                        }
1744 
1745                        if (hadOutputParams) {
1746                                // We can't use 'ourself' to execute this query, or any
1747                                // pending result sets would be overwritten
1748                                java.sql.Statement outParameterStmt = null;
1749                                java.sql.ResultSet outParamRs = null;
1750 
1751                                try {
1752                                        outParameterStmt = this.connection.createStatement();
1753                                        outParamRs = outParameterStmt
1754                                                        .executeQuery(outParameterQuery.toString());
1755                                        this.outputParameterResults = ((com.mysql.jdbc.ResultSet) outParamRs)
1756                                                        .copy();
1757 
1758                                        if (!this.outputParameterResults.next()) {
1759                                                this.outputParameterResults.close();
1760                                                this.outputParameterResults = null;
1761                                        }
1762                                } finally {
1763                                        if (outParameterStmt != null) {
1764                                                outParameterStmt.close();
1765                                        }
1766                                }
1767                        } else {
1768                                this.outputParameterResults = null;
1769                        }
1770                } else {
1771                        this.outputParameterResults = null;
1772                }
1773        }
1774 
1775        /**
1776         * @see java.sql.CallableStatement#setAsciiStream(java.lang.String,
1777         *      java.io.InputStream, int)
1778         */
1779        public void setAsciiStream(String parameterName, InputStream x, int length)
1780                        throws SQLException {
1781                setAsciiStream(getNamedParamIndex(parameterName, false), x, length);
1782        }
1783 
1784        /**
1785         * @see java.sql.CallableStatement#setBigDecimal(java.lang.String,
1786         *      java.math.BigDecimal)
1787         */
1788        public void setBigDecimal(String parameterName, BigDecimal x)
1789                        throws SQLException {
1790                setBigDecimal(getNamedParamIndex(parameterName, false), x);
1791        }
1792 
1793        /**
1794         * @see java.sql.CallableStatement#setBinaryStream(java.lang.String,
1795         *      java.io.InputStream, int)
1796         */
1797        public void setBinaryStream(String parameterName, InputStream x, int length)
1798                        throws SQLException {
1799                setBinaryStream(getNamedParamIndex(parameterName, false), x, length);
1800        }
1801 
1802        /**
1803         * @see java.sql.CallableStatement#setBoolean(java.lang.String, boolean)
1804         */
1805        public void setBoolean(String parameterName, boolean x) throws SQLException {
1806                setBoolean(getNamedParamIndex(parameterName, false), x);
1807        }
1808 
1809        /**
1810         * @see java.sql.CallableStatement#setByte(java.lang.String, byte)
1811         */
1812        public void setByte(String parameterName, byte x) throws SQLException {
1813                setByte(getNamedParamIndex(parameterName, false), x);
1814        }
1815 
1816        /**
1817         * @see java.sql.CallableStatement#setBytes(java.lang.String, byte[])
1818         */
1819        public void setBytes(String parameterName, byte[] x) throws SQLException {
1820                setBytes(getNamedParamIndex(parameterName, false), x);
1821        }
1822 
1823        /**
1824         * @see java.sql.CallableStatement#setCharacterStream(java.lang.String,
1825         *      java.io.Reader, int)
1826         */
1827        public void setCharacterStream(String parameterName, Reader reader,
1828                        int length) throws SQLException {
1829                setCharacterStream(getNamedParamIndex(parameterName, false), reader,
1830                                length);
1831        }
1832 
1833        /**
1834         * @see java.sql.CallableStatement#setDate(java.lang.String, java.sql.Date)
1835         */
1836        public void setDate(String parameterName, Date x) throws SQLException {
1837                setDate(getNamedParamIndex(parameterName, false), x);
1838        }
1839 
1840        /**
1841         * @see java.sql.CallableStatement#setDate(java.lang.String, java.sql.Date,
1842         *      java.util.Calendar)
1843         */
1844        public void setDate(String parameterName, Date x, Calendar cal)
1845                        throws SQLException {
1846                setDate(getNamedParamIndex(parameterName, false), x, cal);
1847        }
1848 
1849        /**
1850         * @see java.sql.CallableStatement#setDouble(java.lang.String, double)
1851         */
1852        public void setDouble(String parameterName, double x) throws SQLException {
1853                setDouble(getNamedParamIndex(parameterName, false), x);
1854        }
1855 
1856        /**
1857         * @see java.sql.CallableStatement#setFloat(java.lang.String, float)
1858         */
1859        public void setFloat(String parameterName, float x) throws SQLException {
1860                setFloat(getNamedParamIndex(parameterName, false), x);
1861        }
1862 
1863        /**
1864         * 
1865         */
1866        private void setInOutParamsOnServer() throws SQLException {
1867                if (this.paramInfo.numParameters > 0) {
1868                        int parameterIndex = 0;
1869 
1870                        for (Iterator paramIter = this.paramInfo.iterator(); paramIter
1871                                        .hasNext();) {
1872 
1873                                CallableStatementParam inParamInfo = (CallableStatementParam) paramIter
1874                                                .next();
1875 
1876                                if (inParamInfo.isOut && inParamInfo.isIn) {
1877                                        String inOutParameterName = mangleParameterName(inParamInfo.paramName);
1878                                        StringBuffer queryBuf = new StringBuffer(
1879                                                        4 + inOutParameterName.length() + 1 + 1);
1880                                        queryBuf.append("SET "); //$NON-NLS-1$
1881                                        queryBuf.append(inOutParameterName);
1882                                        queryBuf.append("=?"); //$NON-NLS-1$
1883 
1884                                        PreparedStatement setPstmt = null;
1885 
1886                                        try {
1887                                                setPstmt = this.connection
1888                                                                .clientPrepareStatement(queryBuf.toString());
1889 
1890                                                byte[] parameterAsBytes = this
1891                                                                .getBytesRepresentation(inParamInfo.index);
1892 
1893                                                if (parameterAsBytes != null) {
1894                                                        if (parameterAsBytes.length > 8
1895                                                                        && parameterAsBytes[0] == '_'
1896                                                                        && parameterAsBytes[1] == 'b'
1897                                                                        && parameterAsBytes[2] == 'i'
1898                                                                        && parameterAsBytes[3] == 'n'
1899                                                                        && parameterAsBytes[4] == 'a'
1900                                                                        && parameterAsBytes[5] == 'r'
1901                                                                        && parameterAsBytes[6] == 'y'
1902                                                                        && parameterAsBytes[7] == '\'') {
1903                                                                setPstmt.setBytesNoEscapeNoQuotes(1,
1904                                                                                parameterAsBytes);
1905                                                        } else {
1906                                                                setPstmt.setBytes(1, parameterAsBytes);
1907                                                        }
1908                                                } else {
1909                                                        setPstmt.setNull(1, Types.NULL);
1910                                                }
1911 
1912                                                setPstmt.executeUpdate();
1913                                        } finally {
1914                                                if (setPstmt != null) {
1915                                                        setPstmt.close();
1916                                                }
1917                                        }
1918                                }
1919 
1920                                parameterIndex++;
1921                        }
1922                }
1923        }
1924 
1925        /**
1926         * @see java.sql.CallableStatement#setInt(java.lang.String, int)
1927         */
1928        public void setInt(String parameterName, int x) throws SQLException {
1929                setInt(getNamedParamIndex(parameterName, false), x);
1930        }
1931 
1932        /**
1933         * @see java.sql.CallableStatement#setLong(java.lang.String, long)
1934         */
1935        public void setLong(String parameterName, long x) throws SQLException {
1936                setLong(getNamedParamIndex(parameterName, false), x);
1937        }
1938 
1939        /**
1940         * @see java.sql.CallableStatement#setNull(java.lang.String, int)
1941         */
1942        public void setNull(String parameterName, int sqlType) throws SQLException {
1943                setNull(getNamedParamIndex(parameterName, false), sqlType);
1944        }
1945 
1946        /**
1947         * @see java.sql.CallableStatement#setNull(java.lang.String, int,
1948         *      java.lang.String)
1949         */
1950        public void setNull(String parameterName, int sqlType, String typeName)
1951                        throws SQLException {
1952                setNull(getNamedParamIndex(parameterName, false), sqlType, typeName);
1953        }
1954 
1955        /**
1956         * @see java.sql.CallableStatement#setObject(java.lang.String,
1957         *      java.lang.Object)
1958         */
1959        public void setObject(String parameterName, Object x) throws SQLException {
1960                setObject(getNamedParamIndex(parameterName, false), x);
1961        }
1962 
1963        /**
1964         * @see java.sql.CallableStatement#setObject(java.lang.String,
1965         *      java.lang.Object, int)
1966         */
1967        public void setObject(String parameterName, Object x, int targetSqlType)
1968                        throws SQLException {
1969                setObject(getNamedParamIndex(parameterName, false), x, targetSqlType);
1970        }
1971 
1972        /**
1973         * @see java.sql.CallableStatement#setObject(java.lang.String,
1974         *      java.lang.Object, int, int)
1975         */
1976        public void setObject(String parameterName, Object x, int targetSqlType,
1977                        int scale) throws SQLException {
1978        }
1979 
1980        private void setOutParams() throws SQLException {
1981                if (this.paramInfo.numParameters > 0) {
1982                        for (Iterator paramIter = this.paramInfo.iterator(); paramIter
1983                                        .hasNext();) {
1984                                CallableStatementParam outParamInfo = (CallableStatementParam) paramIter
1985                                                .next();
1986 
1987                                if (outParamInfo.isOut) {
1988                                        String outParameterName = mangleParameterName(outParamInfo.paramName);
1989 
1990                                        int outParamIndex;
1991                                        
1992                                        if (this.placeholderToParameterIndexMap == null) { 
1993                                                        outParamIndex = outParamInfo.index + 1;
1994                                        } else {
1995                                                        outParamIndex = this.placeholderToParameterIndexMap[outParamInfo.index - 1 /* JDBC is 1-based */];
1996                                        }
1997                                        
1998                                        this.setBytesNoEscapeNoQuotes(outParamIndex,
1999                                                        StringUtils.getBytes(outParameterName,
2000                                                                        this.charConverter, this.charEncoding,
2001                                                                        this.connection
2002                                                                                        .getServerCharacterEncoding(),
2003                                                                        this.connection.parserKnowsUnicode()));
2004                                }
2005                        }
2006                }
2007        }
2008 
2009        /**
2010         * @see java.sql.CallableStatement#setShort(java.lang.String, short)
2011         */
2012        public void setShort(String parameterName, short x) throws SQLException {
2013                setShort(getNamedParamIndex(parameterName, false), x);
2014        }
2015 
2016        /**
2017         * @see java.sql.CallableStatement#setString(java.lang.String,
2018         *      java.lang.String)
2019         */
2020        public void setString(String parameterName, String x) throws SQLException {
2021                setString(getNamedParamIndex(parameterName, false), x);
2022        }
2023 
2024        /**
2025         * @see java.sql.CallableStatement#setTime(java.lang.String, java.sql.Time)
2026         */
2027        public void setTime(String parameterName, Time x) throws SQLException {
2028                setTime(getNamedParamIndex(parameterName, false), x);
2029        }
2030 
2031        /**
2032         * @see java.sql.CallableStatement#setTime(java.lang.String, java.sql.Time,
2033         *      java.util.Calendar)
2034         */
2035        public void setTime(String parameterName, Time x, Calendar cal)
2036                        throws SQLException {
2037                setTime(getNamedParamIndex(parameterName, false), x, cal);
2038        }
2039 
2040        /**
2041         * @see java.sql.CallableStatement#setTimestamp(java.lang.String,
2042         *      java.sql.Timestamp)
2043         */
2044        public void setTimestamp(String parameterName, Timestamp x)
2045                        throws SQLException {
2046                setTimestamp(getNamedParamIndex(parameterName, false), x);
2047        }
2048 
2049        /**
2050         * @see java.sql.CallableStatement#setTimestamp(java.lang.String,
2051         *      java.sql.Timestamp, java.util.Calendar)
2052         */
2053        public void setTimestamp(String parameterName, Timestamp x, Calendar cal)
2054                        throws SQLException {
2055                setTimestamp(getNamedParamIndex(parameterName, false), x, cal);
2056        }
2057 
2058        /**
2059         * @see java.sql.CallableStatement#setURL(java.lang.String, java.net.URL)
2060         */
2061        public void setURL(String parameterName, URL val) throws SQLException {
2062                setURL(getNamedParamIndex(parameterName, false), val);
2063        }
2064 
2065        /**
2066         * @see java.sql.CallableStatement#wasNull()
2067         */
2068        public synchronized boolean wasNull() throws SQLException {
2069                return this.outputParamWasNull;
2070        }
2071 
2072        public int[] executeBatch() throws SQLException {
2073                if (this.hasOutputParams) {
2074                        throw SQLError.createSQLException("Can't call executeBatch() on CallableStatement with OUTPUT parameters",
2075                                        SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
2076                }
2077                
2078                return super.executeBatch();
2079        }
2080}

[all classes][com.mysql.jdbc]
EMMA 2.0.4217 (C) Vladimir Roubtsov