001: /*
002:
003: Derby - Class org.apache.derby.client.am.ParameterMetaData
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to You under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.client.am;
023:
024: import java.sql.SQLException;
025:
026: // Parameter meta data as used internally by the driver is always a column meta data instance.
027: // We will only create instances of this class when getParameterMetaData() is called.
028: // This class simply wraps a column meta data instance.
029: //
030: // Once we go to JDK 1.4 as runtime pre-req, we can extend ColumnMetaData and new up ParameterMetaData instances directly,
031: // and we won't have to wrap column meta data instances directly.
032:
033: public class ParameterMetaData implements java.sql.ParameterMetaData {
034: ColumnMetaData columnMetaData_;
035:
036: // This is false unless for parameterMetaData for a call statement with return clause
037: boolean escapedProcedureCallWithResult_ = false;
038:
039: public ParameterMetaData(ColumnMetaData columnMetaData) {
040: columnMetaData_ = columnMetaData;
041: }
042:
043: public int getParameterCount() throws SQLException {
044: if (escapedProcedureCallWithResult_) {
045: return columnMetaData_.columns_++;
046: }
047: return columnMetaData_.columns_;
048: }
049:
050: public int getParameterType(int param) throws SQLException {
051: if (escapedProcedureCallWithResult_) {
052: param--;
053: if (param == 0) {
054: return java.sql.Types.INTEGER;
055: }
056: }
057: return columnMetaData_.getColumnType(param);
058: }
059:
060: public String getParameterTypeName(int param) throws SQLException {
061: if (escapedProcedureCallWithResult_) {
062: param--;
063: if (param == 0) {
064: return "INTEGER";
065: }
066: }
067: return columnMetaData_.getColumnTypeName(param);
068: }
069:
070: public String getParameterClassName(int param) throws SQLException {
071: if (escapedProcedureCallWithResult_) {
072: param--;
073: if (param == 0) {
074: return "java.lang.Integer";
075: }
076: }
077: return columnMetaData_.getColumnClassName(param);
078: }
079:
080: public int getParameterMode(int param) throws SQLException {
081: try {
082: if (escapedProcedureCallWithResult_) {
083: param--;
084: if (param == 0) {
085: return java.sql.ParameterMetaData.parameterModeOut;
086: }
087: }
088: columnMetaData_.checkForValidColumnIndex(param);
089: if (columnMetaData_.sqlxParmmode_[param - 1] == java.sql.ParameterMetaData.parameterModeUnknown) {
090: return java.sql.ParameterMetaData.parameterModeUnknown;
091: } else if (columnMetaData_.sqlxParmmode_[param - 1] == java.sql.ParameterMetaData.parameterModeIn) {
092: return java.sql.ParameterMetaData.parameterModeIn;
093: } else if (columnMetaData_.sqlxParmmode_[param - 1] == java.sql.ParameterMetaData.parameterModeOut) {
094: return java.sql.ParameterMetaData.parameterModeOut;
095: } else {
096: return java.sql.ParameterMetaData.parameterModeInOut;
097: }
098: } catch (SqlException se) {
099: throw se.getSQLException();
100: }
101: }
102:
103: public int isNullable(int param) throws SQLException {
104: if (escapedProcedureCallWithResult_) {
105: param--;
106: if (param == 0) {
107: return java.sql.ResultSetMetaData.columnNoNulls;
108: }
109: }
110: return columnMetaData_.isNullable(param);
111: }
112:
113: public boolean isSigned(int param) throws SQLException {
114: if (escapedProcedureCallWithResult_) {
115: param--;
116: if (param == 0) {
117: return true;
118: }
119: }
120: return columnMetaData_.isSigned(param);
121: }
122:
123: public int getPrecision(int param) throws SQLException {
124: if (escapedProcedureCallWithResult_) {
125: param--;
126: if (param == 0) {
127: return 10;
128: }
129: }
130: return columnMetaData_.getPrecision(param);
131: }
132:
133: public int getScale(int param) throws SQLException {
134: if (escapedProcedureCallWithResult_) {
135: param--;
136: if (param == 0) {
137: return 0;
138: }
139: }
140: return columnMetaData_.getScale(param);
141: }
142:
143: }
|