001: package com.quadcap.jdbc;
002:
003: /* Copyright 1999 - 2003 Quadcap Software. All rights reserved.
004: *
005: * This software is distributed under the Quadcap Free Software License.
006: * This software may be used or modified for any purpose, personal or
007: * commercial. Open Source redistributions are permitted. Commercial
008: * redistribution of larger works derived from, or works which bundle
009: * this software requires a "Commercial Redistribution License"; see
010: * http://www.quadcap.com/purchase.
011: *
012: * Redistributions qualify as "Open Source" under one of the following terms:
013: *
014: * Redistributions are made at no charge beyond the reasonable cost of
015: * materials and delivery.
016: *
017: * Redistributions are accompanied by a copy of the Source Code or by an
018: * irrevocable offer to provide a copy of the Source Code for up to three
019: * years at the cost of materials and delivery. Such redistributions
020: * must allow further use, modification, and redistribution of the Source
021: * Code under substantially the same terms as this license.
022: *
023: * Redistributions of source code must retain the copyright notices as they
024: * appear in each source code file, these license terms, and the
025: * disclaimer/limitation of liability set forth as paragraph 6 below.
026: *
027: * Redistributions in binary form must reproduce this Copyright Notice,
028: * these license terms, and the disclaimer/limitation of liability set
029: * forth as paragraph 6 below, in the documentation and/or other materials
030: * provided with the distribution.
031: *
032: * The Software is provided on an "AS IS" basis. No warranty is
033: * provided that the Software is free of defects, or fit for a
034: * particular purpose.
035: *
036: * Limitation of Liability. Quadcap Software shall not be liable
037: * for any damages suffered by the Licensee or any third party resulting
038: * from use of the Software.
039: */
040:
041: import java.sql.SQLException;
042:
043: import com.quadcap.sql.Column;
044: import com.quadcap.sql.Cursor;
045: import com.quadcap.sql.Tuple;
046:
047: import com.quadcap.sql.types.Type;
048:
049: import com.quadcap.util.Debug;
050:
051: /**
052: * This class implements the <code>java.sql.ResultSetMetaData</code>
053: * interface, which provides a mechanism to obtain information about
054: * the columns in a <code>ResultSet</code> object.
055: *
056: * @author Stan Bailes
057: */
058: public class ResultSetMetaData implements java.sql.ResultSetMetaData {
059: Cursor cursor;
060:
061: /**
062: * @deprecated
063: */
064: public ResultSetMetaData(Cursor cursor) {
065: this .cursor = cursor;
066: }
067:
068: /**
069: * QED doesn't support catalogs.
070: */
071: public String getCatalogName(int column) throws SQLException {
072: return "";
073: }
074:
075: /**
076: * Return the fully qualified class name of the Java class to which
077: * the specified column will be mapped
078: *
079: * @param column the column number
080: * @return the column's class name
081: * @exception SQLException may be thrown
082: */
083: public String getColumnClassName(int column) throws SQLException {
084: return getType(column).getJDBCClassName();
085: }
086:
087: /**
088: * Return the number of columns in the <code>ResultSet</code>.
089: *
090: * @return the number of columns in the <code>ResultSet</code>.
091: * @exception SQLException may be thrown
092: */
093: public int getColumnCount() throws SQLException {
094: return cursor.getColumnCount();
095: }
096:
097: /**
098: * Return the normal maximum width in characters of the values in
099: * the specified column
100: *
101: * @param column the column number
102: * @return the maximum display size of a value in this column
103: * @exception SQLException may be thrown
104: */
105: public int getColumnDisplaySize(int column) throws SQLException {
106: Column col = cursor.getColumn(column);
107: int w2;
108: if (col.getType() != null) {
109: w2 = col.getType().getDisplayWidth();
110: } else {
111: w2 = col.getShortName().length();
112: }
113: return w2;
114: }
115:
116: /**
117: * Return the shortest possible name for this column, such that the
118: * name is unique within this <code>ResultSet</code> object.
119: *
120: * @param column the column number
121: * @return the column label
122: * @exception SQLException may be thrown
123: */
124: public String getColumnLabel(int column) throws SQLException {
125: return cursor.getColumn(column).getShortName();
126: }
127:
128: /**
129: * Return the shortest possible name for this column, such that the
130: * name is unique within this <code>ResultSet</code> object.
131: *
132: * @param column the column number
133: * @return the column name
134: * @exception SQLException may be thrown
135: */
136: public String getColumnName(int column) throws SQLException {
137: return cursor.getColumn(column).getShortName();
138: }
139:
140: /**
141: * Return the JDBC type of this column
142: *
143: * @param column the column number
144: * @return the column's JDBC type
145: * @exception SQLException may be thrown
146: */
147: public int getColumnType(int column) throws SQLException {
148: return getType(column).getJDBCType();
149: }
150:
151: /**
152: * Return the SQL type name of this column
153: *
154: * @param column the column number
155: * @return the column's SQL type
156: * @exception SQLException may be thrown
157: */
158: public String getColumnTypeName(int column) throws SQLException {
159: return getType(column).getTypeName();
160: }
161:
162: /**
163: * Return the maximum precision of this column, or -1 if this column
164: * is not a numeric type.
165: *
166: * @param column the column number
167: * @return the column's maximum precision
168: * @exception SQLException may be thrown
169: */
170: public int getPrecision(int column) throws SQLException {
171: return getType(column).getPrecision();
172: }
173:
174: /**
175: * Return the scale of this column, or -1 if this column is not
176: * a numeric type
177: *
178: * @param column the column number
179: * @return the column's scale
180: * @exception SQLException may be thrown
181: */
182: public int getScale(int column) throws SQLException {
183: return getType(column).getScale();
184: }
185:
186: /**
187: * Return the schema name for the table from which this column
188: * is derived. This function works for normal columns, but
189: * returns the empty string for computed columns.
190: *
191: * @param column the column number
192: * @return the column's table's schema's name
193: * @exception SQLException may be thrown
194: */
195: public String getSchemaName(int column) throws SQLException {
196: String s = cursor.getColumn(column).getName();
197: int idx = s.indexOf('.');
198: if (idx >= 0) {
199: return s.substring(0, idx);
200: } else {
201: return "";
202: }
203: }
204:
205: /**
206: * Return name of the table from which this column is derived.
207: *
208: * @param column the column number
209: * @return the column's table's name
210: * @exception SQLException may be thrown
211: */
212: public String getTableName(int column) throws SQLException {
213: String ret = "";
214: Tuple table = cursor.getColumn(column).getRelation();
215: if (table != null)
216: ret = table.getName();
217: return ret;
218: }
219:
220: /**
221: * Return <code>true</code> if this is an auto-increment type.
222: *
223: * @param column the column number
224: * @return false
225: * @exception SQLException may be thrown
226: */
227: public boolean isAutoIncrement(int column) throws SQLException {
228: Column col = cursor.getColumn(column);
229: return cursor.getColumn(column).isAutoIncrement();
230: }
231:
232: /**
233: * Return <code>true</code> if this column is case-sensitive.
234: * QED always returns <code>false</code>.
235: *
236: * @param column the column number
237: * @return false
238: * @exception SQLException may be thrown
239: */
240: public boolean isCaseSensitive(int column) throws SQLException {
241: return getType(column).isCaseSensitive();
242: }
243:
244: /**
245: * Return <code>true</code> if this column is a cash value.
246: * QED always returns <code>false</code>.
247: *
248: * @param column the column number
249: * @return false
250: * @exception SQLException may be thrown
251: */
252: public boolean isCurrency(int column) throws SQLException {
253: return getType(column).isCurrency();
254: }
255:
256: /**
257: * Return <code>true</code> if this column is definitely
258: * writable
259: *
260: * @param column the column number
261: * @return true if this column is writable
262: * @exception SQLException may be thrown
263: */
264: public boolean isDefinitelyWritable(int column) throws SQLException {
265: return cursor.isWritable(column);
266: }
267:
268: /**
269: * Return the JDBC 'nullability' state for this column
270: *
271: * @param column the column number
272: * @return if this column can contain <code>NULL</code>s
273: * @exception SQLException may be thrown
274: */
275: public int isNullable(int column) throws SQLException {
276: return cursor.getColumn(column).getNullable();
277: }
278:
279: /**
280: * Return <code>true</code> if this column is not writable
281: *
282: * @param column the column number
283: * @return true if this column is read-only
284: * @exception SQLException may be thrown
285: */
286: public boolean isReadOnly(int column) throws SQLException {
287: return !cursor.isWritable(column);
288: }
289:
290: /**
291: * Return true if the column can be used in a <code>WHERE</code>
292: * clause. QED always returns <code>true</code>
293: *
294: * @param column the column number
295: * @return true
296: * @exception SQLException may be thrown
297: */
298: public boolean isSearchable(int column) throws SQLException {
299: return true;
300: }
301:
302: /**
303: * Return true if this column contains a signed number. In QED, this
304: * is true for all numeric types and for intervals.
305: *
306: * @param column the column number
307: * @return true if this column contains a signed number
308: * @exception SQLException may be thrown
309: */
310: public boolean isSigned(int column) throws SQLException {
311: return getType(column).isSigned();
312: }
313:
314: /**
315: * Return <code>true</code> if this column is writable.
316: *
317: * @param column the column number
318: * @return true if this column is writable.
319: * @exception SQLException may be thrown
320: */
321: public boolean isWritable(int column) throws SQLException {
322: return cursor.isWritable(column);
323: }
324:
325: private Type getType(int column) throws SQLException {
326: Type t = cursor.getColumn(column).getType();
327: return t;
328: }
329:
330: }
|