001: /*
002: Copyright (C) 2003 Together
003:
004: This library is free software; you can redistribute it and/or
005: modify it under the terms of the GNU Lesser General Public
006: License as published by the Free Software Foundation; either
007: version 2.1 of the License, or (at your option) any later version.
008:
009: This library is distributed in the hope that it will be useful,
010: but WITHOUT ANY WARRANTY; without even the implied warranty of
011: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: Lesser General Public License for more details.
013:
014: You should have received a copy of the GNU Lesser General Public
015: License along with this library; if not, write to the Free Software
016: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package org.webdocwf.util.xml;
020:
021: import java.sql.ResultSetMetaData;
022: import java.sql.SQLException;
023: import java.sql.Types;
024:
025: /**
026: * Class implements the JDBC ResultSetMetaData interface for the XmlJdbc driver.
027: *
028: * @author Zoran Milakovic
029: */
030: public class XmlResultSetMetaData implements ResultSetMetaData {
031: /** Default value for getColumnDisplaySize */
032: final static int DISPLAY_SIZE = 20;
033: /** Names of columns */
034: protected String[] columnNames;
035: /** Name of table */
036: protected String tableName;
037:
038: /**Constructor for the XmlResultSetMetaData object
039: *
040: * @param tableName Name of table
041: * @param columnNames Names of columns in table
042: */
043: XmlResultSetMetaData(String tableName, String[] columnNames) {
044: this .tableName = tableName;
045: this .columnNames = columnNames;
046: }
047:
048: /**Returns the name of the class for the specified column. Always returns
049: * String.
050: *
051: * @param column The column number
052: * @return The name of the class for the requested column
053: * @exception SQLException Thrown if there was a problem
054: */
055: public String getColumnClassName(int column) throws SQLException {
056: return String.class.getName();
057: }
058:
059: /** Returns the number of columns in the table.
060: *
061: * @return The number of columns in the table
062: * @exception SQLException Thrown if there is a a problem
063: */
064: public int getColumnCount() throws SQLException {
065: return columnNames.length;
066: }
067:
068: /** Returns the name of the catalog for the specified column. Returns "".
069: *
070: * @param column The column to get the catalog for
071: * @return The catalog name (always "")
072: * @exception SQLException Thrown if there is a problem
073: */
074: public String getCatalogName(int column) throws SQLException {
075: return "";
076: }
077:
078: /**Returns the display column size for the specified column. Always returns 20.
079: *
080: * @param column The column to get the size of
081: * @return The size of the requested column
082: * @exception SQLException Thrown if there is a problem.
083: */
084: public int getColumnDisplaySize(int column) throws SQLException {
085: return DISPLAY_SIZE;
086: }
087:
088: /**Gets the auto increment falg for the specfied column.
089: *
090: * @param column The column to get the flag for
091: * @return The autoIncrement flag (always false)
092: * @exception SQLException Thrown if there is a problem
093: */
094: public boolean isAutoIncrement(int column) throws SQLException {
095: return false;
096: }
097:
098: /**Returns the case sensitivity flag for the specfied column
099: *
100: * @param column The column to return the flag for
101: * @return The caseSensitive flag (always false)
102: * @exception SQLException Thrown if there is a problem
103: */
104: public boolean isCaseSensitive(int column) throws SQLException {
105: //all columns are uppercase
106: return false;
107: }
108:
109: /** Returns the searchable flag for the specified column
110: *
111: * @param column the column to return the flag form
112: * @return The searchable flag (always false)
113: * @exception SQLException Thrown if there is a problem
114: */
115: public boolean isSearchable(int column) throws SQLException {
116: // the implementation doesn't support the where clause
117: return true;
118: }
119:
120: /**Returns the currency flag for the specified column
121: *
122: * @param column The column to get the flag for
123: * @return The currency flag (always false)
124: * @exception SQLException Thrown if there is a problem
125: */
126: public boolean isCurrency(int column) throws SQLException {
127: return false;
128: }
129:
130: /** Returns the nullable flag for the specfied column
131: *
132: * @param column The column to return the flag for
133: * @return The nullable flag (always unknown)
134: * @exception SQLException Thrown if there is a problem
135: */
136: public int isNullable(int column) throws SQLException {
137: return ResultSetMetaData.columnNullableUnknown;
138: }
139:
140: /**Returns the signed flag for the specfied column
141: *
142: * @param column The column to return the flag for
143: * @return The signed flag (always false)
144: * @exception SQLException Thrown if there is a problem
145: */
146: public boolean isSigned(int column) throws SQLException {
147: return false;
148: }
149:
150: /** Returns the label for the specified column
151: *
152: * @param column The column to get the label for
153: * @return the label for the specified column
154: * @exception SQLException Thrown if there is a problem
155: */
156: public String getColumnLabel(int column) throws SQLException {
157: // SQL column numbers start at 1
158: return columnNames[column - 1];
159: }
160:
161: /**Returns the name of the specified column
162: *
163: * @param column The column to get the name of
164: * @return The name of the column
165: * @exception SQLException Thrown if there is a problem
166: */
167: public String getColumnName(int column) throws SQLException {
168: // SQL column numbers start at 1
169: return columnNames[column - 1];
170: }
171:
172: /**
173: * @param column is number of column
174: * @throws SQLException
175: * @return emty string
176: */
177: public String getSchemaName(int column) throws SQLException {
178: return "";
179: }
180:
181: /**
182: * @param column is number of column
183: * @throws SQLException
184: * @return 0
185: */
186: public int getPrecision(int column) throws SQLException {
187: // All the fields are text, should this throw an SQLException?
188: return 0;
189: }
190:
191: /**
192: * @param column is number of column
193: * @throws SQLException
194: * @return 0
195: */
196: public int getScale(int column) throws SQLException {
197: // All the fields are text, should this throw an SQLException?
198: return 0;
199: }
200:
201: /**
202: * @param column is number of column
203: * @throws SQLException
204: * @return table name
205: */
206: public String getTableName(int column) throws SQLException {
207: return tableName;
208: }
209:
210: /**
211: * @param column is number of column
212: * @throws SQLException
213: * @return VARCHAR (type of data)
214: */
215: public int getColumnType(int column) throws SQLException {
216: return Types.VARCHAR;
217: }
218:
219: /**
220: * @param column is number of column
221: * @throws SQLException
222: * @return name of the class
223: */
224: public String getColumnTypeName(int column) throws SQLException {
225: return "VARCHAR";
226: }
227:
228: /**
229: * @param column is number of column
230: * @throws SQLException
231: * @return true
232: */
233: public boolean isReadOnly(int column) throws SQLException {
234: return true;
235: }
236:
237: /**
238: * @param column is number of column
239: * @throws SQLException
240: * @return false
241: */
242: public boolean isWritable(int column) throws SQLException {
243: return false;
244: }
245:
246: /**
247: * @param column is number of column
248: * @throws SQLException
249: * @return false
250: */
251: public boolean isDefinitelyWritable(int column) throws SQLException {
252: return false;
253: }
254:
255: public boolean isWrapperFor(Class<?> iface) throws SQLException {
256: // TODO Auto-generated method stub
257: return false;
258: }
259:
260: public <T> T unwrap(Class<T> iface) throws SQLException {
261: // TODO Auto-generated method stub
262: return null;
263: }
264:
265: }
|