001: package org.mandarax.jdbc.client;
002:
003: /*
004: * Copyright (C) 1999-2004 <a href="mailto:mandarax@jbdietrich.com">Jens Dietrich</a>
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: */
020:
021: import java.sql.ResultSetMetaData;
022: import java.sql.SQLException;
023: import org.mandarax.jdbc.*;
024: import org.mandarax.jdbc.server.*;
025:
026: /**
027: * Class providing meta information about the result set.
028: * This object is a clone of a server side result set meta data object
029: * @author <A HREF="mailto:mandarax@jbdietrich.com">Jens Dietrich</A>
030: * @version 3.3.2 <29 December 2004>
031: * @since 3.0
032: */
033: public class ResultSetMetaDataImpl extends
034: AbstractResultSetMetaDataImpl {
035: private String[] catalogNames = null;
036: private String[] columnClassNames = null;
037: private int columnCount = 0;
038: private int[] columnDisplaySizes = null;
039: private String[] columnLabels = null;
040: private String[] columnNames = null;
041: private int[] columnTypes = null;
042: private String[] columnTypeNames = null;
043: private String[] tableNames = null;
044:
045: /**
046: * Constructor.
047: */
048: public ResultSetMetaDataImpl() throws SQLException {
049: super ();
050: }
051:
052: /**
053: * Constructor.
054: * @param metaData the (server side) result set meta data
055: */
056: public ResultSetMetaDataImpl(ResultSetMetaData metaData)
057: throws SQLException {
058: super ();
059:
060: int s = metaData.getColumnCount();
061: // do not include pseudo columns - serialization of derivation is stil problematic
062: if (metaData instanceof org.mandarax.jdbc.server.ResultSetMetaDataImpl)
063: s = s - PseudoColumns.PSEUDO_COLUMNS.length;
064:
065: catalogNames = new String[s];
066:
067: for (int i = 0; i < s; i++)
068: catalogNames[i] = metaData.getCatalogName(i + 1);
069: columnClassNames = new String[s];
070:
071: for (int i = 0; i < s; i++)
072: columnClassNames[i] = metaData.getColumnClassName(i + 1);
073:
074: columnCount = s;
075:
076: columnDisplaySizes = new int[s];
077: for (int i = 0; i < s; i++)
078: columnDisplaySizes[i] = metaData
079: .getColumnDisplaySize(i + 1);
080:
081: columnLabels = new String[s];
082: for (int i = 0; i < s; i++)
083: columnLabels[i] = metaData.getColumnLabel(i + 1);
084:
085: columnNames = new String[s];
086: for (int i = 0; i < s; i++)
087: columnNames[i] = metaData.getColumnName(i + 1);
088:
089: columnTypes = new int[s];
090: for (int i = 0; i < s; i++)
091: columnTypes[i] = metaData.getColumnType(i + 1);
092:
093: columnTypeNames = new String[s];
094: for (int i = 0; i < s; i++)
095: columnTypeNames[i] = metaData.getColumnTypeName(i + 1);
096:
097: tableNames = new String[s];
098: for (int i = 0; i < s; i++)
099: tableNames[i] = metaData.getTableName(i + 1);
100: }
101:
102: /**
103: * Get the number of columns.
104: * @return an integer
105: */
106:
107: public int getColumnCount() throws SQLException {
108: return this .columnCount;
109: }
110:
111: /**
112: * Indicates the designated column's normal maximum width in characters.
113: * @return the display size - difficult to guess the right value !
114: */
115: public int getColumnDisplaySize(int column) throws SQLException {
116: return this .columnDisplaySizes[column - 1];
117: }
118:
119: /**
120: * Gets the designated column's suggested title for use in printouts and displays.
121: * @return a column label
122: */
123: public String getColumnLabel(int column) throws SQLException {
124: return this .columnLabels[column - 1];
125: }
126:
127: /**
128: * Get the designated column's name.
129: * @return a column name
130: */
131: public String getColumnName(int column) throws SQLException {
132: return this .columnNames[column - 1];
133: }
134:
135: /**
136: * Gets the designated column's table name.
137: * @see java.sql.ResultSetMetaData#getTableName(int)
138: */
139: public String getTableName(int column) throws SQLException {
140: return this .tableNames[column - 1];
141: }
142:
143: /**
144: * Gets the designated column's table's catalog name.
145: * @see java.sql.ResultSetMetaData#getCatalogName(int)
146: */
147: public String getCatalogName(int column) throws SQLException {
148: return this .catalogNames[column - 1];
149: }
150:
151: /**
152: * Retrieves the designated column's SQL type.
153: * @see java.sql.Types
154: * @see java.sql.ResultSetMetaData#getColumnType(int)
155: * @return SQL type from java.sql.Types
156: */
157: public int getColumnType(int column) throws SQLException {
158: return this .columnTypes[column - 1];
159: }
160:
161: /**
162: * Return the type name used by the database.
163: * @retun the type name
164: */
165: public String getColumnTypeName(int column) throws SQLException {
166: return this .columnTypeNames[column - 1];
167: }
168:
169: /**
170: * Returns the fully-qualified name of the Java class whose instances are manufactured
171: * if the method ResultSet.getObject is called to retrieve a value from the column.
172: * ResultSet.getObject may return a subclass of the class returned by this method.
173: */
174: public String getColumnClassName(int column) throws SQLException {
175: return this .columnClassNames[column - 1];
176: }
177:
178: /**
179: * @return
180: */
181: public String[] getCatalogNames() {
182: return catalogNames;
183: }
184:
185: /**
186: * @param catalogNames
187: */
188: public void setCatalogNames(String[] catalogNames) {
189: this .catalogNames = catalogNames;
190: }
191:
192: /**
193: * @return
194: */
195: public String[] getColumnClassNames() {
196: return columnClassNames;
197: }
198:
199: /**
200: * @param columnClassNames
201: */
202: public void setColumnClassNames(String[] columnClassNames) {
203: this .columnClassNames = columnClassNames;
204: }
205:
206: /**
207: * @return
208: */
209: public int[] getColumnDisplaySizes() {
210: return columnDisplaySizes;
211: }
212:
213: /**
214: * @param columnDisplaySizes
215: */
216: public void setColumnDisplaySizes(int[] columnDisplaySizes) {
217: this .columnDisplaySizes = columnDisplaySizes;
218: }
219:
220: /**
221: * @return
222: */
223: public String[] getColumnLabels() {
224: return columnLabels;
225: }
226:
227: /**
228: * @param columnLabels
229: */
230: public void setColumnLabels(String[] columnLabels) {
231: this .columnLabels = columnLabels;
232: }
233:
234: /**
235: * @return
236: */
237: public String[] getColumnNames() {
238: return columnNames;
239: }
240:
241: /**
242: * @param columnNames
243: */
244: public void setColumnNames(String[] columnNames) {
245: this .columnNames = columnNames;
246: }
247:
248: /**
249: * @return
250: */
251: public String[] getColumnTypeNames() {
252: return columnTypeNames;
253: }
254:
255: /**
256: * @param columnTypeNames
257: */
258: public void setColumnTypeNames(String[] columnTypeNames) {
259: this .columnTypeNames = columnTypeNames;
260: }
261:
262: /**
263: * @return
264: */
265: public int[] getColumnTypes() {
266: return columnTypes;
267: }
268:
269: /**
270: * @param columnTypes
271: */
272: public void setColumnTypes(int[] columnTypes) {
273: this .columnTypes = columnTypes;
274: }
275:
276: /**
277: * @return
278: */
279: public String[] getTableNames() {
280: return tableNames;
281: }
282:
283: /**
284: * @param tableNames
285: */
286: public void setTableNames(String[] tableNames) {
287: this .tableNames = tableNames;
288: }
289:
290: /**
291: * @param columnCount
292: */
293: public void setColumnCount(int columnCount) {
294: this.columnCount = columnCount;
295: }
296:
297: }
|