KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > client > am > ParameterMetaData


1 /*
2
3    Derby - Class org.apache.derby.client.am.ParameterMetaData
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20 */

21
22 package org.apache.derby.client.am;
23
24 import java.sql.SQLException JavaDoc;
25
26 // Parameter meta data as used internally by the driver is always a column meta data instance.
27
// We will only create instances of this class when getParameterMetaData() is called.
28
// This class simply wraps a column meta data instance.
29
//
30
// Once we go to JDK 1.4 as runtime pre-req, we can extend ColumnMetaData and new up ParameterMetaData instances directly,
31
// and we won't have to wrap column meta data instances directly.
32

33 public class ParameterMetaData implements java.sql.ParameterMetaData JavaDoc {
34     ColumnMetaData columnMetaData_;
35
36     // This is false unless for parameterMetaData for a call statement with return clause
37
boolean escapedProcedureCallWithResult_ = false;
38
39     public ParameterMetaData(ColumnMetaData columnMetaData) {
40         columnMetaData_ = columnMetaData;
41     }
42
43     public int getParameterCount() throws SQLException JavaDoc {
44         if (escapedProcedureCallWithResult_) {
45             return columnMetaData_.columns_++;
46         }
47         return columnMetaData_.columns_;
48     }
49
50     public int getParameterType(int param) throws SQLException JavaDoc {
51         if (escapedProcedureCallWithResult_) {
52             param--;
53             if (param == 0) {
54                 return java.sql.Types.INTEGER;
55             }
56         }
57         return columnMetaData_.getColumnType(param);
58     }
59
60     public String JavaDoc getParameterTypeName(int param) throws SQLException JavaDoc {
61         if (escapedProcedureCallWithResult_) {
62             param--;
63             if (param == 0) {
64                 return "INTEGER";
65             }
66         }
67         return columnMetaData_.getColumnTypeName(param);
68     }
69
70     public String JavaDoc getParameterClassName(int param) throws SQLException JavaDoc {
71         if (escapedProcedureCallWithResult_) {
72             param--;
73             if (param == 0) {
74                 return "java.lang.Integer";
75             }
76         }
77         return columnMetaData_.getColumnClassName(param);
78     }
79
80     public int getParameterMode(int param) throws SQLException JavaDoc {
81         try
82         {
83             if (escapedProcedureCallWithResult_) {
84                 param--;
85                 if (param == 0) {
86                     return java.sql.ParameterMetaData.parameterModeOut;
87                 }
88             }
89             columnMetaData_.checkForValidColumnIndex(param);
90             if (columnMetaData_.sqlxParmmode_[param - 1] == java.sql.ParameterMetaData.parameterModeUnknown) {
91                 return java.sql.ParameterMetaData.parameterModeUnknown;
92             } else if (columnMetaData_.sqlxParmmode_[param - 1] == java.sql.ParameterMetaData.parameterModeIn) {
93                 return java.sql.ParameterMetaData.parameterModeIn;
94             } else if (columnMetaData_.sqlxParmmode_[param - 1] == java.sql.ParameterMetaData.parameterModeOut) {
95                 return java.sql.ParameterMetaData.parameterModeOut;
96             } else {
97                 return java.sql.ParameterMetaData.parameterModeInOut;
98             }
99         }
100         catch ( SqlException se )
101         {
102             throw se.getSQLException();
103         }
104     }
105
106     public int isNullable(int param) throws SQLException JavaDoc {
107         if (escapedProcedureCallWithResult_) {
108             param--;
109             if (param == 0) {
110                 return java.sql.ResultSetMetaData.columnNoNulls;
111             }
112         }
113         return columnMetaData_.isNullable(param);
114     }
115
116     public boolean isSigned(int param) throws SQLException JavaDoc {
117         if (escapedProcedureCallWithResult_) {
118             param--;
119             if (param == 0) {
120                 return true;
121             }
122         }
123         return columnMetaData_.isSigned(param);
124     }
125
126     public int getPrecision(int param) throws SQLException JavaDoc {
127         if (escapedProcedureCallWithResult_) {
128             param--;
129             if (param == 0) {
130                 return 10;
131             }
132         }
133         return columnMetaData_.getPrecision(param);
134     }
135
136     public int getScale(int param) throws SQLException JavaDoc {
137         if (escapedProcedureCallWithResult_) {
138             param--;
139             if (param == 0) {
140                 return 0;
141             }
142         }
143         return columnMetaData_.getScale(param);
144     }
145
146 }
147
148
149
Popular Tags