KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > in > co > daffodil > db > jdbc > DaffodilDBParameterMetaData


1 package in.co.daffodil.db.jdbc;
2
3 import java.sql.*;
4 import com.daffodilwoods.database.general.*;
5 import com.daffodilwoods.database.resource.*;
6 import com.daffodilwoods.daffodildb.server.sql99.common.ParameterInfo;
7 import com.daffodilwoods.database.general.ParameterMetaData;
8
9 /**
10  * An object that can be used to get information about the types
11  * and properties of the parameters in a <code>PreparedStatement</code> object.
12  *
13  * @since 1.4
14  */

15
16 public class DaffodilDBParameterMetaData
17     implements java.sql.ParameterMetaData JavaDoc {
18
19   final static int PARAMETER_OFFSET = 1;
20   DaffodilDBConnection connection;
21   _ParameterMetaData serverParameterMetaData;
22   int parameterCount;
23   private boolean isUDFParameterMetaData ;
24
25   /** Last on first position and then all except last and set a flag for udf also . */
26
27   public DaffodilDBParameterMetaData(DaffodilDBConnection con,
28                                      _ParameterMetaData parameterMetaData , Boolean JavaDoc isUDF) throws
29       SQLException {
30     connection = con;
31     serverParameterMetaData = parameterMetaData;
32     isUDFParameterMetaData = isUDF.booleanValue();
33     try {
34       if (isUDFParameterMetaData)
35            populateParameterMataDataForUDF();
36       parameterCount = serverParameterMetaData.getParameterCount();
37     }
38     catch (DException ex) {
39       throw ex.getSqlException(connection.getLocale());
40     }
41 }
42
43   /**
44    * Retrieves the number of parameters in the <code>PreparedStatement</code>
45    * object for which this <code>ParameterMetaData</code> object contains
46    * information.
47    *
48    * @return the number of parameters
49    * @exception SQLException if a database access error occurs
50    * @since 1.4
51    */

52   public int getParameterCount() throws SQLException {
53     return parameterCount;
54   }
55
56   /**
57    * Retrieves whether null values are allowed in the designated parameter.
58    *
59    * @param param the first parameter is 1, the second is 2, ...
60    * @return the nullability status of the given parameter; one of
61    * <code>ParameterMetaData.parameterNoNulls</code>,
62    * <code>ParameterMetaData.parameterNullable</code>, or
63    * <code>ParameterMetaData.parameterNullableUnknown</code>
64    * @exception SQLException if a database access error occurs
65    * @since 1.4
66    */

67   public int isNullable(int param) throws SQLException {
68     checkParameterIndex(param);
69     return parameterNullableUnknown;
70   }
71
72   /**
73    * The constant indicating that a
74    * parameter will not allow <code>NULL</code> values.
75    */

76
77   /**
78    * The constant indicating that a
79    * parameter will allow <code>NULL</code> values.
80    */

81
82   /**
83    * The constant indicating that the
84    * nullability of a parameter is unknown.
85    */

86
87   /**
88    * Retrieves whether values for the designated parameter can be signed numbers.
89    *
90    * @param param the first parameter is 1, the second is 2, ...
91    * @return <code>true</code> if so; <code>false</code> otherwise
92    * @exception SQLException if a database access error occurs
93    * @since 1.4
94    */

95   public boolean isSigned(int param) throws SQLException{
96     checkParameterIndex(param);
97     return false;
98   }
99
100   /**
101    * Retrieves the designated parameter's number of decimal digits.
102    *
103    * @param param the first parameter is 1, the second is 2, ...
104    * @return precision
105    * @exception SQLException if a database access error occurs
106    * @since 1.4
107    */

108   public int getPrecision(int param) throws SQLException {
109     checkParameterIndex(param);
110     return -1;
111   }
112
113   /**
114    * Retrieves the designated parameter's number of digits to right of the decimal point.
115    *
116    * @param param the first parameter is 1, the second is 2, ...
117    * @return scale
118    * @exception SQLException if a database access error occurs
119    * @since 1.4
120    */

121   public int getScale(int param) throws SQLException {
122     checkParameterIndex(param);
123     return -1;
124   }
125
126   /**
127    * Retrieves the designated parameter's SQL type.
128    *
129    * @param param the first parameter is 1, the second is 2, ...
130    * @return SQL type from <code>java.sql.Types</code>
131    * @exception SQLException if a database access error occurs
132    * @since 1.4
133    * @see Types
134    */

135   public int getParameterType(int param) throws SQLException {
136     checkParameterIndex(param);
137     try {
138
139       int dbType = serverParameterMetaData.getParameterDataType(param-PARAMETER_OFFSET);
140       return Utilities.getCorrespondingSqlTypeOfDatabaseType(dbType);
141     }
142     catch (DException ex) {
143       throw ex.getSqlException(connection.getLocale());
144     }
145   }
146
147   /**
148    * Retrieves the designated parameter's database-specific type name.
149    *
150    * @param param the first parameter is 1, the second is 2, ...
151    * @return type the name used by the database. If the parameter type is
152    * a user-defined type, then a fully-qualified type name is returned.
153    * @exception SQLException if a database access error occurs
154    * @since 1.4
155    */

156   public String JavaDoc getParameterTypeName(int param) throws SQLException {
157     checkParameterIndex(param);
158     try {
159
160       int dbType = serverParameterMetaData.getParameterDataType(param-PARAMETER_OFFSET);
161       return Utilities.getDataBaseTypeName(dbType);
162     }
163     catch (DException ex) {
164       throw ex.getSqlException(connection.getLocale());
165     }
166   }
167
168   /**
169    * Retrieves the fully-qualified name of the Java class whose instances
170    * should be passed to the method <code>PreparedStatement.setObject</code>.
171    *
172    * @param param the first parameter is 1, the second is 2, ...
173    * @return the fully-qualified name of the class in the Java programming
174    * language that would be used by the method
175    * <code>PreparedStatement.setObject</code> to set the value
176    * in the specified parameter. This is the class name used
177    * for custom mapping.
178    * @exception SQLException if a database access error occurs
179    * @since 1.4
180    */

181   public String JavaDoc getParameterClassName(int param) throws SQLException {
182       return Utilities.getCorrespondingJavaClassesOfSqlTypes(
183           getParameterType(param));
184   }
185
186   /**
187    * The constant indicating that the mode of the parameter is unknown.
188    */

189
190   /**
191    * The constant indicating that the parameter's mode is IN.
192    */

193
194   /**
195    * The constant indicating that the parameter's mode is INOUT.
196    */

197
198   /**
199    * The constant indicating that the parameter's mode is OUT.
200    */

201
202   /**
203    * Retrieves the designated parameter's mode.
204    *
205    * @param param the first parameter is 1, the second is 2, ...
206    * @return mode of the parameter; one of
207    * <code>ParameterMetaData.parameterModeIn</code>,
208    * <code>ParameterMetaData.parameterModeOut</code>, or
209    * <code>ParameterMetaData.parameterModeInOut</code>
210    * <code>ParameterMetaData.parameterModeUnknown</code>.
211    * @exception SQLException if a database access error occurs
212    * @since 1.4
213    */

214
215   public int getParameterMode(int param) throws SQLException {
216      try {
217
218         ParameterInfo[] pi = serverParameterMetaData.getParameterInfo();
219          String JavaDoc mode = pi[param - 1].getParameterMode();
220          if (mode != null) {
221            if (mode.equalsIgnoreCase("in"))
222              return parameterModeIn;
223            if (mode.equalsIgnoreCase("out"))
224              return parameterModeOut;
225            if (mode.equalsIgnoreCase("inout"))
226              return parameterModeInOut;
227          }
228
229      } catch (DException ex) {
230         throw ex.getSqlException(connection.getLocale());
231      }
232      return parameterModeUnknown;
233   }
234
235   /** -----------------------------
236    * Daffodil DB specific Methods
237    * -----------------------------
238    */

239
240   private void checkParameterIndex(int paramIndex) throws SQLException {
241     if(paramIndex < 1 || paramIndex > parameterCount ) {
242       DException dex = new DException("DSE479", new Object JavaDoc[]{new Integer JavaDoc(paramIndex), new Integer JavaDoc(parameterCount)});
243       throw dex.getSqlException(connection.getLocale());
244     }
245   }
246   /**
247    * Description : Work done in regard to UDF support.
248    * @author : Manoj Kr. Sheoran
249    * */

250   private void populateParameterMataDataForUDF() throws DException{
251           ParameterInfo udfParamInfo[] = serverParameterMetaData.getParameterInfo();
252           if(udfParamInfo.length == 1){
253                    return ;
254           }
255           ParameterInfo []paramInfo = new ParameterInfo[udfParamInfo.length];
256           System.arraycopy(udfParamInfo,udfParamInfo.length,paramInfo,0,1); // Done Last paraminfo at first place
257
System.arraycopy(udfParamInfo,0,paramInfo,1,udfParamInfo.length -1 );// Then copy all except last one.
258
serverParameterMetaData = new com.daffodilwoods.database.general.ParameterMetaData(serverParameterMetaData.getQuery(),paramInfo);
259    }
260     }
261
Popular Tags