001: package org.mandarax.jdbc.server;
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.SQLException;
022: import java.sql.Types;
023:
024: import org.mandarax.jdbc.*;
025: import org.mandarax.jdbc.JDBCUtils;
026: import org.mandarax.kernel.Predicate;
027:
028: /**
029: * Class providing meta information about the result set.
030: * @author <A HREF="mailto:mandarax@jbdietrich.com">Jens Dietrich</A>
031: * @version 3.3.2 <29 December 2004>
032: * @since 3.0
033: */
034: public class ResultSetMetaDataImpl extends
035: AbstractResultSetMetaDataImpl {
036: private java.sql.ResultSet sqlResult = null;
037: private org.mandarax.kernel.ResultSet mandaraxResult = null;
038: private Predicate predicate = null;
039: private int[] types = null;
040:
041: /**
042: * Constructor.
043: * @param sqlResult the jdbc result set
044: * @param mandaraxResult the mandarax result set
045: * @param predicate a predicate
046: */
047: ResultSetMetaDataImpl(java.sql.ResultSet sqlResult,
048: org.mandarax.kernel.ResultSet mandaraxResult,
049: Predicate predicate) {
050: super ();
051: this .sqlResult = sqlResult;
052: this .mandaraxResult = mandaraxResult;
053: this .predicate = predicate;
054: }
055:
056: /**
057: * Get the number of columns.
058: * @return an integer
059: */
060:
061: public int getColumnCount() throws SQLException {
062: return predicate.getStructure().length
063: + PseudoColumns.PSEUDO_COLUMNS.length;
064: }
065:
066: /**
067: * Indicates the designated column's normal maximum width in characters.
068: * @return the display size - difficult to guess the right value !
069: */
070: public int getColumnDisplaySize(int column) throws SQLException {
071: return 255;
072: }
073:
074: /**
075: * Gets the designated column's suggested title for use in printouts and displays.
076: * @return a column label
077: */
078: public String getColumnLabel(int column) throws SQLException {
079: return getColumnName(column);
080: }
081:
082: /**
083: * Get the designated column's name.
084: * @return a column name
085: */
086: public String getColumnName(int column) throws SQLException {
087: int realCols = predicate.getStructure().length;
088: if (column <= realCols)
089: return JDBC2KBUtils.getSlotName(predicate, column - 1);
090: else
091: return PseudoColumns.PSEUDO_COLUMNS[column - (realCols + 1)];
092: }
093:
094: /**
095: * Gets the designated column's table name.
096: * @see java.sql.ResultSetMetaData#getTableName(int)
097: */
098: public String getTableName(int column) throws SQLException {
099: return predicate.getName();
100: }
101:
102: /**
103: * Gets the designated column's table's catalog name.
104: * @see java.sql.ResultSetMetaData#getCatalogName(int)
105: */
106: public String getCatalogName(int column) throws SQLException {
107: return DatabaseMetaDataImpl.DEFAULT_CATALOG;
108: }
109:
110: /**
111: * Retrieves the designated column's SQL type.
112: * @see java.sql.Types
113: * @see java.sql.ResultSetMetaData#getColumnType(int)
114: * @return SQL type from java.sql.Types
115: */
116: public int getColumnType(int column) throws SQLException {
117: int realCols = predicate.getStructure().length;
118: if (types == null) {
119: types = new int[realCols];
120: for (int i = 0; i < types.length; i++) {
121: Class jtype = predicate.getStructure()[i];
122: types[i] = JDBCUtils.getTypeMapping(jtype);
123: }
124: }
125: if (column <= realCols)
126: return types[column - 1];
127: else
128: return Types.JAVA_OBJECT;
129: }
130:
131: /**
132: * Return the type name used by the database.
133: * @retun the type name
134: */
135: public String getColumnTypeName(int column) throws SQLException {
136: return getColumnClassName(column);
137: }
138:
139: /**
140: * Returns the fully-qualified name of the Java class whose instances are manufactured
141: * if the method ResultSet.getObject is called to retrieve a value from the column.
142: * ResultSet.getObject may return a subclass of the class returned by this method.
143: */
144: public String getColumnClassName(int column) throws SQLException {
145: int realCols = predicate.getStructure().length;
146: if (column <= realCols)
147: return predicate.getStructure()[column - 1].getName();
148: else
149: return PseudoColumns.PSEUDO_COLUMN_TYPES[column
150: - (realCols + 1)].getName();
151: }
152:
153: }
|