KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > jdbc > JdbcParameterMetaData


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.jdbc;
6
7 import java.sql.*;
8
9 import org.h2.command.CommandInterface;
10 import org.h2.engine.SessionInterface;
11 import org.h2.message.Message;
12 import org.h2.message.TraceObject;
13
14 /**
15  * Information about the parameters of a prepared statement.
16  */

17 public class JdbcParameterMetaData extends TraceObject
18 //#ifdef JDK14
19
implements ParameterMetaData
20 //#endif
21
{
22
23     private JdbcPreparedStatement prep;
24     private int paramCount;
25
26     /**
27      * Returns the number of parameters.
28      *
29      * @return the number
30      */

31     public int getParameterCount() throws SQLException {
32         try {
33             debugCodeCall("getParameterCount");
34             checkClosed();
35             return paramCount;
36         } catch(Throwable JavaDoc e) {
37             throw logAndConvert(e);
38         }
39     }
40
41     /**
42      * Returns the parameter mode.
43      * Always returns parameterModeIn
44      *
45      * @return parameterModeIn
46      */

47 //#ifdef JDK14
48
public int getParameterMode(int param) throws SQLException {
49         try {
50             debugCodeCall("getParameterMode", param);
51             checkParameterIndex(param);
52             return parameterModeIn;
53         } catch(Throwable JavaDoc e) {
54             throw logAndConvert(e);
55         }
56     }
57 //#endif
58

59     /**
60      * Returns the parameter type.
61      * Always returns Types.VARCHAR everything can be passed as a VARCHAR.
62      *
63      * @return Types.VARCHAR
64      */

65     public int getParameterType(int param) throws SQLException {
66         try {
67             debugCodeCall("getParameterType", param);
68             checkParameterIndex(param);
69             return Types.VARCHAR;
70         } catch(Throwable JavaDoc e) {
71             throw logAndConvert(e);
72         }
73     }
74
75     /**
76      * Returns the parameter precision.
77      * Always returns 0.
78      *
79      * @return 0
80      */

81     public int getPrecision(int param) throws SQLException {
82         try {
83             debugCodeCall("getPrecision", param);
84             checkParameterIndex(param);
85             return 0;
86         } catch(Throwable JavaDoc e) {
87             throw logAndConvert(e);
88         }
89     }
90
91     /**
92      * Returns the parameter precision.
93      * Always returns 0.
94      *
95      * @return 0
96      */

97     public int getScale(int param) throws SQLException {
98         try {
99             debugCodeCall("getScale", param);
100             checkParameterIndex(param);
101             return 0;
102         } catch(Throwable JavaDoc e) {
103             throw logAndConvert(e);
104         }
105     }
106
107     /**
108      * Checks if this is nullable parameter.
109      * Returns ResultSetMetaData.columnNullableUnknown..
110      *
111      * @return ResultSetMetaData.columnNullableUnknown
112      */

113     public int isNullable(int param) throws SQLException {
114         try {
115             debugCodeCall("isNullable", param);
116             checkParameterIndex(param);
117             return ResultSetMetaData.columnNullableUnknown;
118         } catch(Throwable JavaDoc e) {
119             throw logAndConvert(e);
120         }
121     }
122
123     /**
124      * Checks if this parameter is signed.
125      * It always returns true.
126      *
127      * @return true
128      */

129     public boolean isSigned(int param) throws SQLException {
130         try {
131             debugCodeCall("isSigned", param);
132             checkParameterIndex(param);
133             return true;
134         } catch(Throwable JavaDoc e) {
135             throw logAndConvert(e);
136         }
137     }
138
139     /**
140      * Returns the parameter class name.
141      * Always returns java.lang.String.
142      *
143      * @return "java.lang.String"
144      */

145     public String JavaDoc getParameterClassName(int param) throws SQLException {
146         try {
147             debugCodeCall("getParameterClassName", param);
148             checkParameterIndex(param);
149             return String JavaDoc.class.getName();
150         } catch(Throwable JavaDoc e) {
151             throw logAndConvert(e);
152         }
153     }
154
155     /**
156      * Returns the parameter type name.
157      * Always returns VARCHAR.
158      *
159      * @return "VARCHAR"
160      */

161     public String JavaDoc getParameterTypeName(int param) throws SQLException {
162         try {
163             debugCodeCall("getParameterTypeName", param);
164             checkParameterIndex(param);
165             return "VARCHAR";
166         } catch(Throwable JavaDoc e) {
167             throw logAndConvert(e);
168         }
169     }
170
171     JdbcParameterMetaData(SessionInterface session, JdbcPreparedStatement prep, CommandInterface command, int id) {
172         setTrace(session.getTrace(), TraceObject.PARAMETER_META_DATA, id);
173         this.prep = prep;
174         this.paramCount = command.getParameters().size();
175     }
176
177     void checkParameterIndex(int param) throws SQLException {
178         checkClosed();
179         if (param < 1 || param > paramCount) {
180             throw Message.getInvalidValueException("" + param, "param");
181         }
182     }
183
184     void checkClosed() throws SQLException {
185         prep.checkClosed();
186     }
187
188     /**
189      * Return an object of this class if possible.
190      * @throws SQLException Unsupported Feature (SQL State 0A000)
191      */

192     //#ifdef JDK16
193
/*
194     public <T> T unwrap(Class<T> iface) throws SQLException {
195         debugCodeCall("unwrap");
196         throw Message.getUnsupportedException();
197     }
198 */

199     //#endif
200

201     /**
202      * Checks if unwrap can return an object of this class.
203      * @throws SQLException Unsupported Feature (SQL State 0A000)
204      */

205     //#ifdef JDK16
206
/*
207     public boolean isWrapperFor(Class<?> iface) throws SQLException {
208         debugCodeCall("isWrapperFor");
209         throw Message.getUnsupportedException();
210     }
211 */

212     //#endif
213

214 }
215
Popular Tags