Quadcap Embeddable Database

com/quadcap/jdbc/ResultSetMetaData.java

Go to the documentation of this file.
00001 package com.quadcap.jdbc; 00002 00003 /* Copyright 1999 - 2003 Quadcap Software. All rights reserved. 00004 * 00005 * This software is distributed under the Quadcap Free Software License. 00006 * This software may be used or modified for any purpose, personal or 00007 * commercial. Open Source redistributions are permitted. Commercial 00008 * redistribution of larger works derived from, or works which bundle 00009 * this software requires a "Commercial Redistribution License"; see 00010 * http://www.quadcap.com/purchase. 00011 * 00012 * Redistributions qualify as "Open Source" under one of the following terms: 00013 * 00014 * Redistributions are made at no charge beyond the reasonable cost of 00015 * materials and delivery. 00016 * 00017 * Redistributions are accompanied by a copy of the Source Code or by an 00018 * irrevocable offer to provide a copy of the Source Code for up to three 00019 * years at the cost of materials and delivery. Such redistributions 00020 * must allow further use, modification, and redistribution of the Source 00021 * Code under substantially the same terms as this license. 00022 * 00023 * Redistributions of source code must retain the copyright notices as they 00024 * appear in each source code file, these license terms, and the 00025 * disclaimer/limitation of liability set forth as paragraph 6 below. 00026 * 00027 * Redistributions in binary form must reproduce this Copyright Notice, 00028 * these license terms, and the disclaimer/limitation of liability set 00029 * forth as paragraph 6 below, in the documentation and/or other materials 00030 * provided with the distribution. 00031 * 00032 * The Software is provided on an "AS IS" basis. No warranty is 00033 * provided that the Software is free of defects, or fit for a 00034 * particular purpose. 00035 * 00036 * Limitation of Liability. Quadcap Software shall not be liable 00037 * for any damages suffered by the Licensee or any third party resulting 00038 * from use of the Software. 00039 */ 00040 00041 import java.sql.SQLException; 00042 00043 import com.quadcap.sql.Column; 00044 import com.quadcap.sql.Cursor; 00045 import com.quadcap.sql.Tuple; 00046 00047 import com.quadcap.sql.types.Type; 00048 00049 import com.quadcap.util.Debug; 00050 00051 /** 00052 * This class implements the <code>java.sql.ResultSetMetaData</code> 00053 * interface, which provides a mechanism to obtain information about 00054 * the columns in a <code>ResultSet</code> object. 00055 * 00056 * @author Stan Bailes 00057 */ 00058 public class ResultSetMetaData implements java.sql.ResultSetMetaData { 00059 Cursor cursor; 00060 00061 /** 00062 * @deprecated 00063 */ 00064 public ResultSetMetaData(Cursor cursor) { 00065 this.cursor = cursor; 00066 } 00067 00068 /** 00069 * QED doesn't support catalogs. 00070 */ 00071 public String getCatalogName(int column) throws SQLException { 00072 return ""; 00073 } 00074 00075 /** 00076 * Return the fully qualified class name of the Java class to which 00077 * the specified column will be mapped 00078 * 00079 * @param column the column number 00080 * @return the column's class name 00081 * @exception SQLException may be thrown 00082 */ 00083 public String getColumnClassName(int column) throws SQLException { 00084 return getType(column).getJDBCClassName(); 00085 } 00086 00087 /** 00088 * Return the number of columns in the <code>ResultSet</code>. 00089 * 00090 * @return the number of columns in the <code>ResultSet</code>. 00091 * @exception SQLException may be thrown 00092 */ 00093 public int getColumnCount() throws SQLException { 00094 return cursor.getColumnCount(); 00095 } 00096 00097 /** 00098 * Return the normal maximum width in characters of the values in 00099 * the specified column 00100 * 00101 * @param column the column number 00102 * @return the maximum display size of a value in this column 00103 * @exception SQLException may be thrown 00104 */ 00105 public int getColumnDisplaySize(int column) throws SQLException { 00106 Column col = cursor.getColumn(column); 00107 int w2; 00108 if (col.getType() != null) { 00109 w2 = col.getType().getDisplayWidth(); 00110 } else { 00111 w2 = col.getShortName().length(); 00112 } 00113 return w2; 00114 } 00115 00116 /** 00117 * Return the shortest possible name for this column, such that the 00118 * name is unique within this <code>ResultSet</code> object. 00119 * 00120 * @param column the column number 00121 * @return the column label 00122 * @exception SQLException may be thrown 00123 */ 00124 public String getColumnLabel(int column) throws SQLException { 00125 return cursor.getColumn(column).getShortName(); 00126 } 00127 00128 /** 00129 * Return the shortest possible name for this column, such that the 00130 * name is unique within this <code>ResultSet</code> object. 00131 * 00132 * @param column the column number 00133 * @return the column name 00134 * @exception SQLException may be thrown 00135 */ 00136 public String getColumnName(int column) throws SQLException { 00137 return cursor.getColumn(column).getShortName(); 00138 } 00139 00140 /** 00141 * Return the JDBC type of this column 00142 * 00143 * @param column the column number 00144 * @return the column's JDBC type 00145 * @exception SQLException may be thrown 00146 */ 00147 public int getColumnType(int column) throws SQLException { 00148 return getType(column).getJDBCType(); 00149 } 00150 00151 /** 00152 * Return the SQL type name of this column 00153 * 00154 * @param column the column number 00155 * @return the column's SQL type 00156 * @exception SQLException may be thrown 00157 */ 00158 public String getColumnTypeName(int column) throws SQLException { 00159 return getType(column).getTypeName(); 00160 } 00161 00162 /** 00163 * Return the maximum precision of this column, or -1 if this column 00164 * is not a numeric type. 00165 * 00166 * @param column the column number 00167 * @return the column's maximum precision 00168 * @exception SQLException may be thrown 00169 */ 00170 public int getPrecision(int column) throws SQLException { 00171 return getType(column).getPrecision(); 00172 } 00173 00174 /** 00175 * Return the scale of this column, or -1 if this column is not 00176 * a numeric type 00177 * 00178 * @param column the column number 00179 * @return the column's scale 00180 * @exception SQLException may be thrown 00181 */ 00182 public int getScale(int column) throws SQLException { 00183 return getType(column).getScale(); 00184 } 00185 00186 /** 00187 * Return the schema name for the table from which this column 00188 * is derived. This function works for normal columns, but 00189 * returns the empty string for computed columns. 00190 * 00191 * @param column the column number 00192 * @return the column's table's schema's name 00193 * @exception SQLException may be thrown 00194 */ 00195 public String getSchemaName(int column) throws SQLException { 00196 String s = cursor.getColumn(column).getName(); 00197 int idx = s.indexOf('.'); 00198 if (idx >= 0) { 00199 return s.substring(0, idx); 00200 } else { 00201 return ""; 00202 } 00203 } 00204 00205 /** 00206 * Return name of the table from which this column is derived. 00207 * 00208 * @param column the column number 00209 * @return the column's table's name 00210 * @exception SQLException may be thrown 00211 */ 00212 public String getTableName(int column) throws SQLException { 00213 String ret = ""; 00214 Tuple table = cursor.getColumn(column).getRelation(); 00215 if (table != null) ret = table.getName(); 00216 return ret; 00217 } 00218 00219 /** 00220 * Return <code>true</code> if this is an auto-increment type. 00221 * 00222 * @param column the column number 00223 * @return false 00224 * @exception SQLException may be thrown 00225 */ 00226 public boolean isAutoIncrement(int column) throws SQLException { 00227 Column col = cursor.getColumn(column); 00228 return cursor.getColumn(column).isAutoIncrement(); 00229 } 00230 00231 /** 00232 * Return <code>true</code> if this column is case-sensitive. 00233 * QED always returns <code>false</code>. 00234 * 00235 * @param column the column number 00236 * @return false 00237 * @exception SQLException may be thrown 00238 */ 00239 public boolean isCaseSensitive(int column) throws SQLException { 00240 return getType(column).isCaseSensitive(); 00241 } 00242 00243 /** 00244 * Return <code>true</code> if this column is a cash value. 00245 * QED always returns <code>false</code>. 00246 * 00247 * @param column the column number 00248 * @return false 00249 * @exception SQLException may be thrown 00250 */ 00251 public boolean isCurrency(int column) throws SQLException { 00252 return getType(column).isCurrency(); 00253 } 00254 00255 /** 00256 * Return <code>true</code> if this column is definitely 00257 * writable 00258 * 00259 * @param column the column number 00260 * @return true if this column is writable 00261 * @exception SQLException may be thrown 00262 */ 00263 public boolean isDefinitelyWritable(int column) throws SQLException { 00264 return cursor.isWritable(column); 00265 } 00266 00267 /** 00268 * Return the JDBC 'nullability' state for this column 00269 * 00270 * @param column the column number 00271 * @return if this column can contain <code>NULL</code>s 00272 * @exception SQLException may be thrown 00273 */ 00274 public int isNullable(int column) throws SQLException { 00275 return cursor.getColumn(column).getNullable(); 00276 } 00277 00278 /** 00279 * Return <code>true</code> if this column is not writable 00280 * 00281 * @param column the column number 00282 * @return true if this column is read-only 00283 * @exception SQLException may be thrown 00284 */ 00285 public boolean isReadOnly(int column) throws SQLException { 00286 return !cursor.isWritable(column); 00287 } 00288 00289 /** 00290 * Return true if the column can be used in a <code>WHERE</code> 00291 * clause. QED always returns <code>true</code> 00292 * 00293 * @param column the column number 00294 * @return true 00295 * @exception SQLException may be thrown 00296 */ 00297 public boolean isSearchable(int column) throws SQLException { 00298 return true; 00299 } 00300 00301 /** 00302 * Return true if this column contains a signed number. In QED, this 00303 * is true for all numeric types and for intervals. 00304 * 00305 * @param column the column number 00306 * @return true if this column contains a signed number 00307 * @exception SQLException may be thrown 00308 */ 00309 public boolean isSigned(int column) throws SQLException { 00310 return getType(column).isSigned(); 00311 } 00312 00313 /** 00314 * Return <code>true</code> if this column is writable. 00315 * 00316 * @param column the column number 00317 * @return true if this column is writable. 00318 * @exception SQLException may be thrown 00319 */ 00320 public boolean isWritable(int column) throws SQLException { 00321 return cursor.isWritable(column); 00322 } 00323 00324 private Type getType(int column) throws SQLException { 00325 Type t = cursor.getColumn(column).getType(); 00326 return t; 00327 } 00328 00329 }