Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 33244 invoked from network); 2 May 2005 06:33:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 2 May 2005 06:33:23 -0000 Received: (qmail 91513 invoked by uid 500); 2 May 2005 06:34:46 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 91466 invoked by uid 500); 2 May 2005 06:34:45 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 91434 invoked by uid 500); 2 May 2005 06:34:45 -0000 Delivered-To: apmail-incubator-derby-cvs@incubator.apache.org Received: (qmail 91425 invoked by uid 99); 2 May 2005 06:34:45 -0000 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Sun, 01 May 2005 23:34:42 -0700 Received: (qmail 31514 invoked by uid 65534); 2 May 2005 06:26:36 -0000 Message-ID: <20050502062636.31512.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: svn commit: r165585 [6/42] - in /incubator/derby/code/trunk/java/client/org/apache/derby: client/ client/am/ client/net/ client/resources/ jdbc/ Date: Mon, 02 May 2005 06:26:03 -0000 To: derby-cvs@incubator.apache.org From: jboynes@apache.org X-Mailer: svnmailer-1.0.0-dev X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Modified: incubator/derby/code/trunk/java/client/org/apache/derby/client/am= /ColumnMetaData.java URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/o= rg/apache/derby/client/am/ColumnMetaData.java?rev=3D165585&r1=3D165584&r2= =3D165585&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Colum= nMetaData.java (original) +++ incubator/derby/code/trunk/java/client/org/apache/derby/client/am/Colum= nMetaData.java Sun May 1 23:25:59 2005 @@ -22,918 +22,904 @@ =20 // Under JDBC 2, we must new up our parameter meta data as column meta dat= a instances // Once we move to JDK 1.4 pre-req, create a ResultSetMetaData class and m= ake this class abstract -public class ColumnMetaData implements java.sql.ResultSetMetaData -{ =20 - public int columns_; +public class ColumnMetaData implements java.sql.ResultSetMetaData { =20 - public boolean[] nullable_; + public int columns_; =20 - // Although this is describe information, it is tagged transient for now= becuase it is not currently used. - transient public int[] singleMixedByteOrDouble_; // 1 means single, 2 me= ans double, 3 means mixed-byte, 0 not applicable - - // All of the following state data comes from the SQLDA reply. - - //Data from SQLDHGRP - public short sqldHold_; - public short sqldReturn_; - public short sqldScroll_; - public short sqldSensitive_; - public short sqldFcode_; - public short sqldKeytype_; - public String sqldRdbnam_; // catalog name, not used by driver, placehol= der only - public String sqldSchema_; // schema name, not used by driver, placehold= er only - - //data comes from SQLDAGRP - public int[] sqlPrecision_; // adjusted sqllen; - public int[] sqlScale_; - public long[] sqlLength_; // This is maximum length for varchar fields - // These are the derby sql types, for use only by ResultSetMetaData, oth= er code should use jdbcTypes_. - // sqlTypes_ is currently not set for input column meta data. - public int[] sqlType_; - public int[] sqlCcsid_; - - // With the exception of sqlNames_ and sqlxParmmode_, the following memb= ers are only allocated when needed - - //Data from SQLDOPTGRP - public String[] sqlName_; // column name, pre-allocated - public String[] sqlLabel_; // column label - public short[] sqlUnnamed_; - public String[] sqlComment_; - - //Data from SQLDXGRP - public short[] sqlxKeymem_; - public short[] sqlxGenerated_; - public short[] sqlxParmmode_; // pre-allocated - public String[] sqlxCorname_; - public String[] sqlxName_; - public String[] sqlxBasename_; // table name - public int[] sqlxUpdatable_; - public String[] sqlxSchema_; // schema name - public String[] sqlxRdbnam_; // catalog name - - //-----------------------------transient state--------------------------= ------ - - // For performance only, not part of logical model. - public transient int[][] protocolTypesCache_ =3D null; - public transient java.util.Hashtable protocolTypeToOverrideLidMapping_ = =3D null; - public transient java.util.ArrayList mddOverrideArray_ =3D null; - - public transient int[] types_; - public transient int[] clientParamtertype_; - - public transient LogWriter logWriter_; - - // only set on execute replies, this is not describe information. - // only used for result set meta data.=20 - - public transient int resultSetConcurrency_; - - transient private java.util.Hashtable columnNameToIndexCache_ =3D null; - - transient private boolean statementClosed_ =3D false; - void markClosed() { - statementClosed_ =3D true; - nullDataForGC(); =20 - } - - void checkForClosedStatement() throws SqlException - { - // agent_.checkForDeferredExceptions();=20 - if (statementClosed_) throw new SqlException (logWriter_, "Statement c= losed"); - } - - - //---------------------navigational members-----------------------------= ------ - - //---------------------constructors/finalizer---------------------------= ------ - - // Called by NETColumnMetaData constructor before #columns is parsed out= yet. - public ColumnMetaData (LogWriter logWriter) - { - logWriter_ =3D logWriter; - } - - // For creating column meta data when describe input is not available. - // The upper bound that is passed in is determined by counting the numbe= r of parameter markers. - // Called by PreparedStatement.flowPrepareStatement() and flowDescribeIn= putOutput() - // only when describe input is not available. - public ColumnMetaData (LogWriter logWriter, int upperBound) - { - logWriter_ =3D logWriter; - initializeCache (upperBound); - } - - - public void initializeCache (int upperBound) - { - columns_ =3D upperBound; - nullable_ =3D new boolean[upperBound]; - types_ =3D new int[upperBound]; - clientParamtertype_ =3D new int[upperBound]; - singleMixedByteOrDouble_ =3D new int[upperBound]; // 1 means single, 2= means double, 3 means mixed-byte, 0 not applicable - - sqlPrecision_ =3D new int[upperBound]; - sqlScale_ =3D new int[upperBound]; - sqlLength_ =3D new long[upperBound]; - sqlType_ =3D new int[upperBound]; - sqlCcsid_ =3D new int[upperBound]; - - sqlName_ =3D new String[upperBound]; - sqlxParmmode_ =3D new short[upperBound]; - } - - protected void finalize () throws java.lang.Throwable - { - super.finalize(); - } - - //--------------------Abstract material layer call-down methods---------= -------- - - //------------------material layer event callback methods---------------= -------- - - // ---------------------------jdbc 1------------------------------------= ------ - - public int getColumnCount () throws SqlException - { - checkForClosedStatement(); - return columns_; - } - - public boolean isAutoIncrement (int column) throws SqlException - { - checkForClosedStatement(); - checkForValidColumnIndex (column); - return false; - } - - public boolean isCaseSensitive (int column) throws SqlException - { - checkForClosedStatement(); - checkForValidColumnIndex (column); - //return true if the SQLTYPE is CHAR, VARCHAR, LOGVARCHAR or CLOB - int type =3D types_[column-1]; - return - type =3D=3D Types.CHAR || - type =3D=3D Types.VARCHAR || - type =3D=3D Types.LONGVARCHAR || - type =3D=3D Types.CLOB; - } - - // all searchable except distinct - public boolean isSearchable (int column) throws SqlException - { - checkForClosedStatement(); - checkForValidColumnIndex (column); - return true; - } - - public boolean isCurrency (int column) throws SqlException - { - checkForClosedStatement(); - checkForValidColumnIndex (column); - return false; - } - - public int isNullable (int column) throws SqlException - { - checkForClosedStatement(); - checkForValidColumnIndex (column); - if (nullable_[column-1]) - return java.sql.ResultSetMetaData.columnNullable; - else - return java.sql.ResultSetMetaData.columnNoNulls; - } - - public boolean isSigned (int column) throws SqlException - { - checkForClosedStatement(); - checkForValidColumnIndex (column); - //return true only if the SQLType is SMALLINT, INT, BIGINT, FLOAT, REA= L, DOUBLE, NUMERIC OR DECIMAL - int type =3D types_[column-1]; - return - type =3D=3D Types.SMALLINT || - type =3D=3D Types.INTEGER || - type =3D=3D Types.BIGINT || - type =3D=3D java.sql.Types.FLOAT || - type =3D=3D Types.REAL || - type =3D=3D Types.DOUBLE || - type =3D=3D java.sql.Types.NUMERIC || - type =3D=3D Types.DECIMAL; - } - - public int getColumnDisplaySize (int column) throws SqlException - { - checkForClosedStatement(); - checkForValidColumnIndex (column); - int jdbcType =3D types_[column-1]; - switch (jdbcType){ - case Types.INTEGER: - return 11; - case Types.SMALLINT: - return 6; - case Types.BIGINT: - return 20; - case Types.REAL: - return 13; - case Types.DOUBLE: - case java.sql.Types.FLOAT: - return 22; - case Types.DECIMAL: - case java.sql.Types.NUMERIC: - return getPrecision(column) + 2; // add 1 for sign and 1 for decimal - case Types.CHAR: - case Types.VARCHAR: - case Types.LONGVARCHAR: - case Types.CLOB: - return (int) sqlLength_[column-1]; - case Types.DATE: - return 10; - case Types.TIME: - return 8; - case Types.TIMESTAMP: - return 26; - case Types.BINARY: - case Types.VARBINARY: - case Types.LONGVARBINARY: - case Types.BLOB: - return (int) (2*sqlLength_[column-1]); // eg. "FF" represents just= one byte - default: - throw new SqlException (logWriter_, "not supported"); - } - } - - public String getColumnLabel (int column) throws SqlException - { - checkForClosedStatement(); - checkForValidColumnIndex (column); - // return labels if label is turned on, otherwise, return column name - if (sqlLabel_ !=3D null && sqlLabel_[column-1] !=3D null) return sql= Label_[column-1]; - if (sqlName_ =3D=3D null || sqlName_[column-1] =3D=3D null) - assignColumnName (column); - return sqlName_[column-1]; - } - - public String getColumnName (int column) throws SqlException - { - checkForClosedStatement(); - checkForValidColumnIndex (column); - // The Javadoc and Jdbc book explicitly state that the empty string = ("") is returned if "not applicable" - // for the following methods: - // getSchemaName() - // getTableName() - // getCatalogName() - // Since the empty string is a valid string and is not really a prop= er table name, schema name, or catalog name, - // we're not sure why the empty string was chosen over null, except = possibly to be friendly to lazy jdbc apps - // that may not be checking for nulls, thereby minimizing potential = NPE's. - // By induction, it would make sense to return the empty string when= column name is not available/applicable. - // - // The JDBC specification contains blanket statements about SQL comp= liance levels, - // so elaboration within the JDBC specification is often bypassed. - // Personally, I would prefer to return Java null for all the not-ap= plicable cases, - // but it appears that we have precedent for the empty ("") string. - // - // We assume a straightforward induction from jdbc spec that the col= umn name be "" (empty) - // in preference to null or NULL for the not applicable case. - // - if (sqlName_ =3D=3D null || sqlName_[column-1] =3D=3D null) - assignColumnName (column); - return sqlName_[column-1]; - } - - public String getSchemaName (int column) throws SqlException - { - checkForClosedStatement(); - checkForValidColumnIndex (column); - if (sqlxSchema_ =3D=3D null || sqlxSchema_[column-1] =3D=3D null) retu= rn ""; // Per jdbc spec - return sqlxSchema_[column-1]; - } - - public int getPrecision (int column) throws SqlException - { - checkForClosedStatement(); - checkForValidColumnIndex (column); - int jdbcType =3D types_[column-1]; - - switch (jdbcType) { - case java.sql.Types.NUMERIC: - case Types.DECIMAL: - return sqlPrecision_[column-1]; - case Types.SMALLINT: - return 5; - case Types.INTEGER: - return 10; - case Types.BIGINT: - return 19; - case java.sql.Types.FLOAT: - return 15; - case Types.REAL: - return 7; // This is the number of signed digits for IEEE float with man= tissa 24, ie. 2^24 - case Types.DOUBLE: - return 15; // This is the number of signed digits for IEEE float with man= tissa 24, ie. 2^24 - case Types.CHAR: - case Types.VARCHAR: - case Types.LONGVARCHAR: - case Types.BINARY: - case Types.VARBINARY: - case Types.LONGVARBINARY: - case Types.CLOB: - case Types.BLOB: - return (int) sqlLength_[column-1]; - case Types.DATE: - return 10; - case Types.TIME: - return 8; - case Types.TIMESTAMP: - return 26; - default: - throw new SqlException (logWriter_, "Unregistered column type"); - } - } - - public int getScale (int column) throws SqlException - { - checkForClosedStatement(); - checkForValidColumnIndex (column); - - // We get the scale from the SQLDA as returned by DERBY, but DERBY doe= s not return the ANSI-defined - // value of scale 6 for TIMESTAMP. - // - // The JDBC drivers should hardcode this info as a short/near term s= olution. - // - if (types_[column-1] =3D=3D Types.TIMESTAMP) return 6; - - return sqlScale_[column-1]; - } - - public String getTableName (int column) throws SqlException - { - checkForClosedStatement(); - checkForValidColumnIndex (column); - if (sqlxBasename_ =3D=3D null || sqlxBasename_[column-1] =3D=3D null) = return ""; // Per jdbc spec - return sqlxBasename_[column-1]; - } + public boolean[] nullable_; + + // Although this is describe information, it is tagged transient for n= ow becuase it is not currently used. + transient public int[] singleMixedByteOrDouble_; // 1 means single, 2 = means double, 3 means mixed-byte, 0 not applicable + + // All of the following state data comes from the SQLDA reply. + + //Data from SQLDHGRP + public short sqldHold_; + public short sqldReturn_; + public short sqldScroll_; + public short sqldSensitive_; + public short sqldFcode_; + public short sqldKeytype_; + public String sqldRdbnam_; // catalog name, not used by driver, placeh= older only + public String sqldSchema_; // schema name, not used by driver, placeho= lder only + + //data comes from SQLDAGRP + public int[] sqlPrecision_; // adjusted sqllen; + public int[] sqlScale_; + public long[] sqlLength_; // This is maximum length for varchar fields + // These are the derby sql types, for use only by ResultSetMetaData, o= ther code should use jdbcTypes_. + // sqlTypes_ is currently not set for input column meta data. + public int[] sqlType_; + public int[] sqlCcsid_; + + // With the exception of sqlNames_ and sqlxParmmode_, the following me= mbers are only allocated when needed + + //Data from SQLDOPTGRP + public String[] sqlName_; // column name, pre-allocated + public String[] sqlLabel_; // column label + public short[] sqlUnnamed_; + public String[] sqlComment_; + + //Data from SQLDXGRP + public short[] sqlxKeymem_; + public short[] sqlxGenerated_; + public short[] sqlxParmmode_; // pre-allocated + public String[] sqlxCorname_; + public String[] sqlxName_; + public String[] sqlxBasename_; // table name + public int[] sqlxUpdatable_; + public String[] sqlxSchema_; // schema name + public String[] sqlxRdbnam_; // catalog name + + //-----------------------------transient state------------------------= -------- + + // For performance only, not part of logical model. + public transient int[][] protocolTypesCache_ =3D null; + public transient java.util.Hashtable protocolTypeToOverrideLidMapping_= =3D null; + public transient java.util.ArrayList mddOverrideArray_ =3D null; + + public transient int[] types_; + public transient int[] clientParamtertype_; + + public transient LogWriter logWriter_; + + // only set on execute replies, this is not describe information. + // only used for result set meta data. + + public transient int resultSetConcurrency_; + + transient private java.util.Hashtable columnNameToIndexCache_ =3D null; + + transient private boolean statementClosed_ =3D false; + + void markClosed() { + statementClosed_ =3D true; + nullDataForGC(); + } + + void checkForClosedStatement() throws SqlException { + // agent_.checkForDeferredExceptions(); + if (statementClosed_) { + throw new SqlException(logWriter_, "Statement closed"); + } + } + + + //---------------------navigational members---------------------------= -------- + + //---------------------constructors/finalizer-------------------------= -------- + + // Called by NETColumnMetaData constructor before #columns is parsed o= ut yet. + public ColumnMetaData(LogWriter logWriter) { + logWriter_ =3D logWriter; + } + + // For creating column meta data when describe input is not available. + // The upper bound that is passed in is determined by counting the num= ber of parameter markers. + // Called by PreparedStatement.flowPrepareStatement() and flowDescribe= InputOutput() + // only when describe input is not available. + public ColumnMetaData(LogWriter logWriter, int upperBound) { + logWriter_ =3D logWriter; + initializeCache(upperBound); + } + + + public void initializeCache(int upperBound) { + columns_ =3D upperBound; + nullable_ =3D new boolean[upperBound]; + types_ =3D new int[upperBound]; + clientParamtertype_ =3D new int[upperBound]; + singleMixedByteOrDouble_ =3D new int[upperBound]; // 1 means singl= e, 2 means double, 3 means mixed-byte, 0 not applicable + + sqlPrecision_ =3D new int[upperBound]; + sqlScale_ =3D new int[upperBound]; + sqlLength_ =3D new long[upperBound]; + sqlType_ =3D new int[upperBound]; + sqlCcsid_ =3D new int[upperBound]; + + sqlName_ =3D new String[upperBound]; + sqlxParmmode_ =3D new short[upperBound]; + } + + protected void finalize() throws java.lang.Throwable { + super.finalize(); + } + + //--------------------Abstract material layer call-down methods-------= ---------- + + //------------------material layer event callback methods-------------= ---------- + + // ---------------------------jdbc 1----------------------------------= -------- + + public int getColumnCount() throws SqlException { + checkForClosedStatement(); + return columns_; + } + + public boolean isAutoIncrement(int column) throws SqlException { + checkForClosedStatement(); + checkForValidColumnIndex(column); + return false; + } + + public boolean isCaseSensitive(int column) throws SqlException { + checkForClosedStatement(); + checkForValidColumnIndex(column); + //return true if the SQLTYPE is CHAR, VARCHAR, LOGVARCHAR or CLOB + int type =3D types_[column - 1]; + return + type =3D=3D Types.CHAR || + type =3D=3D Types.VARCHAR || + type =3D=3D Types.LONGVARCHAR || + type =3D=3D Types.CLOB; + } + + // all searchable except distinct + public boolean isSearchable(int column) throws SqlException { + checkForClosedStatement(); + checkForValidColumnIndex(column); + return true; + } + + public boolean isCurrency(int column) throws SqlException { + checkForClosedStatement(); + checkForValidColumnIndex(column); + return false; + } + + public int isNullable(int column) throws SqlException { + checkForClosedStatement(); + checkForValidColumnIndex(column); + if (nullable_[column - 1]) { + return java.sql.ResultSetMetaData.columnNullable; + } else { + return java.sql.ResultSetMetaData.columnNoNulls; + } + } + + public boolean isSigned(int column) throws SqlException { + checkForClosedStatement(); + checkForValidColumnIndex(column); + //return true only if the SQLType is SMALLINT, INT, BIGINT, FLOAT,= REAL, DOUBLE, NUMERIC OR DECIMAL + int type =3D types_[column - 1]; + return + type =3D=3D Types.SMALLINT || + type =3D=3D Types.INTEGER || + type =3D=3D Types.BIGINT || + type =3D=3D java.sql.Types.FLOAT || + type =3D=3D Types.REAL || + type =3D=3D Types.DOUBLE || + type =3D=3D java.sql.Types.NUMERIC || + type =3D=3D Types.DECIMAL; + } + + public int getColumnDisplaySize(int column) throws SqlException { + checkForClosedStatement(); + checkForValidColumnIndex(column); + int jdbcType =3D types_[column - 1]; + switch (jdbcType) { + case Types.INTEGER: + return 11; + case Types.SMALLINT: + return 6; + case Types.BIGINT: + return 20; + case Types.REAL: + return 13; + case Types.DOUBLE: + case java.sql.Types.FLOAT: + return 22; + case Types.DECIMAL: + case java.sql.Types.NUMERIC: + return getPrecision(column) + 2; // add 1 for sign and 1 for = decimal + case Types.CHAR: + case Types.VARCHAR: + case Types.LONGVARCHAR: + case Types.CLOB: + return (int) sqlLength_[column - 1]; + case Types.DATE: + return 10; + case Types.TIME: + return 8; + case Types.TIMESTAMP: + return 26; + case Types.BINARY: + case Types.VARBINARY: + case Types.LONGVARBINARY: + case Types.BLOB: + return (int) (2 * sqlLength_[column - 1]); // eg. "FF" represe= nts just one byte + default: + throw new SqlException(logWriter_, "not supported"); + } + } + + public String getColumnLabel(int column) throws SqlException { + checkForClosedStatement(); + checkForValidColumnIndex(column); + // return labels if label is turned on, otherwise, return column n= ame + if (sqlLabel_ !=3D null && sqlLabel_[column - 1] !=3D null) { + return sqlLabel_[column - 1]; + } + if (sqlName_ =3D=3D null || sqlName_[column - 1] =3D=3D null) { + assignColumnName(column); + } + return sqlName_[column - 1]; + } + + public String getColumnName(int column) throws SqlException { + checkForClosedStatement(); + checkForValidColumnIndex(column); + // The Javadoc and Jdbc book explicitly state that the empty strin= g ("") is returned if "not applicable" + // for the following methods: + // getSchemaName() + // getTableName() + // getCatalogName() + // Since the empty string is a valid string and is not really a pr= oper table name, schema name, or catalog name, + // we're not sure why the empty string was chosen over null, excep= t possibly to be friendly to lazy jdbc apps + // that may not be checking for nulls, thereby minimizing potentia= l NPE's. + // By induction, it would make sense to return the empty string wh= en column name is not available/applicable. + // + // The JDBC specification contains blanket statements about SQL co= mpliance levels, + // so elaboration within the JDBC specification is often bypassed. + // Personally, I would prefer to return Java null for all the not-= applicable cases, + // but it appears that we have precedent for the empty ("") string. + // + // We assume a straightforward induction from jdbc spec that the c= olumn name be "" (empty) + // in preference to null or NULL for the not applicable case. + // + if (sqlName_ =3D=3D null || sqlName_[column - 1] =3D=3D null) { + assignColumnName(column); + } + return sqlName_[column - 1]; + } + + public String getSchemaName(int column) throws SqlException { + checkForClosedStatement(); + checkForValidColumnIndex(column); + if (sqlxSchema_ =3D=3D null || sqlxSchema_[column - 1] =3D=3D null= ) { + return ""; // Per jdbc spec + } + return sqlxSchema_[column - 1]; + } + + public int getPrecision(int column) throws SqlException { + checkForClosedStatement(); + checkForValidColumnIndex(column); + int jdbcType =3D types_[column - 1]; + + switch (jdbcType) { + case java.sql.Types.NUMERIC: + case Types.DECIMAL: + return sqlPrecision_[column - 1]; + case Types.SMALLINT: + return 5; + case Types.INTEGER: + return 10; + case Types.BIGINT: + return 19; + case java.sql.Types.FLOAT: + return 15; + case Types.REAL: + return 7; // This is the number of signed digits for IEEE flo= at with mantissa 24, ie. 2^24 + case Types.DOUBLE: + return 15; // This is the number of signed digits for IEEE flo= at with mantissa 24, ie. 2^24 + case Types.CHAR: + case Types.VARCHAR: + case Types.LONGVARCHAR: + case Types.BINARY: + case Types.VARBINARY: + case Types.LONGVARBINARY: + case Types.CLOB: + case Types.BLOB: + return (int) sqlLength_[column - 1]; + case Types.DATE: + return 10; + case Types.TIME: + return 8; + case Types.TIMESTAMP: + return 26; + default: + throw new SqlException(logWriter_, "Unregistered column type"); + } + } + + public int getScale(int column) throws SqlException { + checkForClosedStatement(); + checkForValidColumnIndex(column); + + // We get the scale from the SQLDA as returned by DERBY, but DERBY= does not return the ANSI-defined + // value of scale 6 for TIMESTAMP. + // + // The JDBC drivers should hardcode this info as a short/near te= rm solution. + // + if (types_[column - 1] =3D=3D Types.TIMESTAMP) { + return 6; + } + + return sqlScale_[column - 1]; + } + + public String getTableName(int column) throws SqlException { + checkForClosedStatement(); + checkForValidColumnIndex(column); + if (sqlxBasename_ =3D=3D null || sqlxBasename_[column - 1] =3D=3D = null) { + return ""; // Per jdbc spec + } + return sqlxBasename_[column - 1]; + } =20 /** * What's a column's table's catalog name? * * @param column the first column is 1, the second is 2, ... + * * @return column name or "" if not applicable. - * @exception SQLException thrown on failure + * + * @throws SQLException thrown on failure */ - public String getCatalogName (int column) throws SqlException - { - checkForClosedStatement(); - checkForValidColumnIndex (column); - return ""; - } - - public int getColumnType (int column) throws SqlException - { - checkForClosedStatement(); - checkForValidColumnIndex (column); - - return types_[column-1]; - } - - public String getColumnTypeName (int column) throws SqlException - { - checkForClosedStatement(); - checkForValidColumnIndex (column); - - int jdbcType =3D types_[column-1]; - // So these all come back zero for downlevel servers in PROTOCOL. - // John is going to write some code to construct the sqlType_ array - // based on the protocol types from the query descriptor. - int sqlType =3D sqlType_[column-1]; - - switch (sqlType) { - case Types.DERBY_SQLTYPE_DATE: - case Types.DERBY_SQLTYPE_NDATE: - return "DATE"; - case Types.DERBY_SQLTYPE_TIME: - case Types.DERBY_SQLTYPE_NTIME: - return "TIME"; - case Types.DERBY_SQLTYPE_TIMESTAMP: - case Types.DERBY_SQLTYPE_NTIMESTAMP: - return "TIMESTAMP"; - case Types.DERBY_SQLTYPE_BLOB: - case Types.DERBY_SQLTYPE_NBLOB: - return "BLOB"; - case Types.DERBY_SQLTYPE_CLOB: - case Types.DERBY_SQLTYPE_NCLOB: - return "CLOB"; - case Types.DERBY_SQLTYPE_VARCHAR: - case Types.DERBY_SQLTYPE_NVARCHAR: - if (jdbcType =3D=3D Types.VARBINARY) - return "VARCHAR FOR BIT DATA"; - else - return "VARCHAR"; - case Types.DERBY_SQLTYPE_CHAR: - case Types.DERBY_SQLTYPE_NCHAR: - if(jdbcType =3D=3D Types.BINARY) - return "CHAR FOR BIT DATA"; - else - return "CHAR"; - case Types.DERBY_SQLTYPE_LONG: - case Types.DERBY_SQLTYPE_NLONG: - if(jdbcType =3D=3D Types.LONGVARBINARY) - return "LONG VARCHAR FOR BIT DATA"; - else - return "LONG VARCHAR"; - case Types.DERBY_SQLTYPE_CSTR: - case Types.DERBY_SQLTYPE_NCSTR: - return "SBCS"; - case Types.DERBY_SQLTYPE_FLOAT: - case Types.DERBY_SQLTYPE_NFLOAT: - if(jdbcType =3D=3D Types.DOUBLE) - return "DOUBLE"; - if(jdbcType =3D=3D Types.REAL) - return "REAL"; - case Types.DERBY_SQLTYPE_DECIMAL: - case Types.DERBY_SQLTYPE_NDECIMAL: - return "DECIMAL"; - case Types.DERBY_SQLTYPE_BIGINT: - case Types.DERBY_SQLTYPE_NBIGINT: - return "BIGINT"; - case Types.DERBY_SQLTYPE_INTEGER: - case Types.DERBY_SQLTYPE_NINTEGER: - return "INTEGER"; - case Types.DERBY_SQLTYPE_SMALL: - case Types.DERBY_SQLTYPE_NSMALL: - return "SMALLINT"; - case Types.DERBY_SQLTYPE_NUMERIC: - case Types.DERBY_SQLTYPE_NNUMERIC: - return "NUMERIC"; - default: - throw new SqlException (logWriter_, "Not supported"); - } - } - - public boolean isReadOnly (int column) throws SqlException - { - checkForClosedStatement(); - checkForValidColumnIndex (column); - if (sqlxUpdatable_ =3D=3D null) - return (resultSetConcurrency_ =3D=3D java.sql.ResultSet.CONCUR_READ_= ONLY); // If no extended describe, return resultSet's concurrecnty - return sqlxUpdatable_[column-1] =3D=3D 0; // PROTOCOL 0 means not upda= table, 1 means updatable - } - - public boolean isWritable (int column) throws SqlException - { - checkForClosedStatement(); - checkForValidColumnIndex (column); - if (sqlxUpdatable_ =3D=3D null) - return (resultSetConcurrency_ =3D=3D java.sql.ResultSet.CONCUR_UPDAT= ABLE); // If no extended describe, return resultSet's concurrency - return sqlxUpdatable_[column-1] =3D=3D 1; // PROTOCOL 0 means not upda= table, 1 means updatable - } - - public boolean isDefinitelyWritable (int column) throws SqlException - { - checkForClosedStatement(); - checkForValidColumnIndex (column); - if (sqlxUpdatable_ =3D=3D null) return false; - return sqlxUpdatable_[column-1] =3D=3D 1; // PROTOCOL 0 means not upda= table, 1 means updatable - } - - //--------------------------jdbc 2.0----------------------------------- - - public String getColumnClassName (int column) throws SqlException - { - checkForClosedStatement(); - checkForValidColumnIndex (column); - - int jdbcType =3D types_[column-1]; - switch (jdbcType) { - case java.sql.Types.BIT: - return "java.lang.Boolean"; - case java.sql.Types.TINYINT: - return "java.lang.Integer"; - case Types.SMALLINT: - return "java.lang.Integer"; - case Types.INTEGER: - return "java.lang.Integer"; - case Types.BIGINT: - return "java.lang.Long"; - case java.sql.Types.FLOAT: - return "java.lang.Double"; - case Types.REAL: - return "java.lang.Float"; - case Types.DOUBLE: - return "java.lang.Double"; - case java.sql.Types.NUMERIC: - case Types.DECIMAL: - return "java.math.BigDecimal"; - case Types.CHAR: - case Types.VARCHAR: - case Types.LONGVARCHAR: - return "java.lang.String"; - case Types.DATE: - return "java.sql.Date"; - case Types.TIME: - return "java.sql.Time"; - case Types.TIMESTAMP: - return "java.sql.Timestamp"; - case Types.BINARY: - case Types.VARBINARY: - case Types.LONGVARBINARY: - return "byte[]"; - case java.sql.Types.STRUCT: - return "java.sql.Struct"; - case java.sql.Types.ARRAY: - return "java.sql.Array"; - case Types.BLOB: - return "java.sql.Blob"; - case Types.CLOB: - return "java.sql.Clob"; - case java.sql.Types.REF: - return "java.sql.Ref"; - default: - throw new SqlException (logWriter_, "Not supported"); - } - } - - //----------------------------helper methods----------------------------= ------ - - - void checkForValidColumnIndex (int column) throws SqlException - { - if (column < 1 || column > columns_) - throw new SqlException (logWriter_, "Invalid argument: column index = " + - column + " is out of range."); - } - - // If the input parameter has been set, return true, else return false. - private boolean isParameterModeGuessedAsAnInput (int parameterIndex) - { - if (sqlxParmmode_[parameterIndex - 1] =3D=3D java.sql.ParameterMetaDat= a=2EparameterModeIn || - sqlxParmmode_[parameterIndex - 1] =3D=3D java.sql.ParameterMetaDat= a=2EparameterModeInOut) { - return true; - } - return false; - } - - // Does OUT parm registration rely on extended describe? - // If the output parameter has been registered, return true, else return= false. - public boolean isParameterModeGuessedAsOutput (int parameterIndex) - { - return sqlxParmmode_[parameterIndex - 1] >=3D java.sql.ParameterMetaDa= ta.parameterModeInOut; - } - - // Only called when column meta data is not described. Called by setXXX = methods. - public void guessInputParameterMetaData (int parameterIndex, - int jdbcType) throws SqlExcept= ion - { - guessInputParameterMetaData (parameterIndex, jdbcType, 0); - } - - private void setParmModeForInputParameter (int parameterIndex) - { - if (sqlxParmmode_[parameterIndex - 1] =3D=3D java.sql.ParameterMetaDat= a=2EparameterModeOut) - sqlxParmmode_[parameterIndex - 1] =3D java.sql.ParameterMetaData.par= ameterModeInOut; - else if (sqlxParmmode_[parameterIndex - 1] =3D=3D java.sql.ParameterMe= taData.parameterModeUnknown) - sqlxParmmode_[parameterIndex - 1] =3D java.sql.ParameterMetaData.par= ameterModeIn; - } - - // Only called when column meta data is not described. Called by setXXX = methods. - // Scale is only applied for Decimal or Numeric JDBC type. - public void guessInputParameterMetaData (int parameterIndex, - int jdbcType, - int scale) throws SqlException - { - setParmModeForInputParameter (parameterIndex); - int driverType =3D getInternalTypeForGuessedOrRegisteredJdbcType (jdbc= Type); - // if output parameter has been registered already - if (isParameterModeGuessedAsOutput (parameterIndex)) { - if (!isCompatibleDriverTypes (types_[parameterIndex-1], driverType))= { - throw new SqlException (logWriter_, "The jdbcType " + jdbcType + "= does not match between the setter method and " + - "the registerOutParameter method."); - } - else return; // don't bother guessing if the parameter was already r= egistered - } - guessParameterMetaDataBasedOnSupportedDriverType (parameterIndex, jdbc= Type=3D=3Djava.sql.Types.BIGINT, driverType, scale); - } - - private void setParmModeForOutputParameter (int parameterIndex) - { - if (sqlxParmmode_[parameterIndex - 1] =3D=3D java.sql.ParameterMetaDat= a=2EparameterModeIn) - sqlxParmmode_[parameterIndex - 1] =3D java.sql.ParameterMetaData.par= ameterModeInOut; - else if (sqlxParmmode_[parameterIndex - 1] =3D=3D java.sql.ParameterMe= taData.parameterModeUnknown) - sqlxParmmode_[parameterIndex - 1] =3D java.sql.ParameterMetaData.par= ameterModeOut; - } + public String getCatalogName(int column) throws SqlException { + checkForClosedStatement(); + checkForValidColumnIndex(column); + return ""; + } + + public int getColumnType(int column) throws SqlException { + checkForClosedStatement(); + checkForValidColumnIndex(column); =20 - // Only called when column meta data is not described, called by registe= rOutParameter methods. - public void guessOutputParameterMetaData (int parameterIndex, + return types_[column - 1]; + } + + public String getColumnTypeName(int column) throws SqlException { + checkForClosedStatement(); + checkForValidColumnIndex(column); + + int jdbcType =3D types_[column - 1]; + // So these all come back zero for downlevel servers in PROTOCOL. + // John is going to write some code to construct the sqlType_ array + // based on the protocol types from the query descriptor. + int sqlType =3D sqlType_[column - 1]; + + switch (sqlType) { + case Types.DERBY_SQLTYPE_DATE: + case Types.DERBY_SQLTYPE_NDATE: + return "DATE"; + case Types.DERBY_SQLTYPE_TIME: + case Types.DERBY_SQLTYPE_NTIME: + return "TIME"; + case Types.DERBY_SQLTYPE_TIMESTAMP: + case Types.DERBY_SQLTYPE_NTIMESTAMP: + return "TIMESTAMP"; + case Types.DERBY_SQLTYPE_BLOB: + case Types.DERBY_SQLTYPE_NBLOB: + return "BLOB"; + case Types.DERBY_SQLTYPE_CLOB: + case Types.DERBY_SQLTYPE_NCLOB: + return "CLOB"; + case Types.DERBY_SQLTYPE_VARCHAR: + case Types.DERBY_SQLTYPE_NVARCHAR: + if (jdbcType =3D=3D Types.VARBINARY) { + return "VARCHAR FOR BIT DATA"; + } else { + return "VARCHAR"; + } + case Types.DERBY_SQLTYPE_CHAR: + case Types.DERBY_SQLTYPE_NCHAR: + if (jdbcType =3D=3D Types.BINARY) { + return "CHAR FOR BIT DATA"; + } else { + return "CHAR"; + } + case Types.DERBY_SQLTYPE_LONG: + case Types.DERBY_SQLTYPE_NLONG: + if (jdbcType =3D=3D Types.LONGVARBINARY) { + return "LONG VARCHAR FOR BIT DATA"; + } else { + return "LONG VARCHAR"; + } + case Types.DERBY_SQLTYPE_CSTR: + case Types.DERBY_SQLTYPE_NCSTR: + return "SBCS"; + case Types.DERBY_SQLTYPE_FLOAT: + case Types.DERBY_SQLTYPE_NFLOAT: + if (jdbcType =3D=3D Types.DOUBLE) { + return "DOUBLE"; + } + if (jdbcType =3D=3D Types.REAL) { + return "REAL"; + } + case Types.DERBY_SQLTYPE_DECIMAL: + case Types.DERBY_SQLTYPE_NDECIMAL: + return "DECIMAL"; + case Types.DERBY_SQLTYPE_BIGINT: + case Types.DERBY_SQLTYPE_NBIGINT: + return "BIGINT"; + case Types.DERBY_SQLTYPE_INTEGER: + case Types.DERBY_SQLTYPE_NINTEGER: + return "INTEGER"; + case Types.DERBY_SQLTYPE_SMALL: + case Types.DERBY_SQLTYPE_NSMALL: + return "SMALLINT"; + case Types.DERBY_SQLTYPE_NUMERIC: + case Types.DERBY_SQLTYPE_NNUMERIC: + return "NUMERIC"; + default: + throw new SqlException(logWriter_, "Not supported"); + } + } + + public boolean isReadOnly(int column) throws SqlException { + checkForClosedStatement(); + checkForValidColumnIndex(column); + if (sqlxUpdatable_ =3D=3D null) { + return (resultSetConcurrency_ =3D=3D java.sql.ResultSet.CONCUR= _READ_ONLY); // If no extended describe, return resultSet's concurrecnty + } + return sqlxUpdatable_[column - 1] =3D=3D 0; // PROTOCOL 0 means no= t updatable, 1 means updatable + } + + public boolean isWritable(int column) throws SqlException { + checkForClosedStatement(); + checkForValidColumnIndex(column); + if (sqlxUpdatable_ =3D=3D null) { + return (resultSetConcurrency_ =3D=3D java.sql.ResultSet.CONCUR= _UPDATABLE); // If no extended describe, return resultSet's concurrency + } + return sqlxUpdatable_[column - 1] =3D=3D 1; // PROTOCOL 0 means no= t updatable, 1 means updatable + } + + public boolean isDefinitelyWritable(int column) throws SqlException { + checkForClosedStatement(); + checkForValidColumnIndex(column); + if (sqlxUpdatable_ =3D=3D null) { + return false; + } + return sqlxUpdatable_[column - 1] =3D=3D 1; // PROTOCOL 0 means no= t updatable, 1 means updatable + } + + //--------------------------jdbc 2.0----------------------------------- + + public String getColumnClassName(int column) throws SqlException { + checkForClosedStatement(); + checkForValidColumnIndex(column); + + int jdbcType =3D types_[column - 1]; + switch (jdbcType) { + case java.sql.Types.BIT: + return "java.lang.Boolean"; + case java.sql.Types.TINYINT: + return "java.lang.Integer"; + case Types.SMALLINT: + return "java.lang.Integer"; + case Types.INTEGER: + return "java.lang.Integer"; + case Types.BIGINT: + return "java.lang.Long"; + case java.sql.Types.FLOAT: + return "java.lang.Double"; + case Types.REAL: + return "java.lang.Float"; + case Types.DOUBLE: + return "java.lang.Double"; + case java.sql.Types.NUMERIC: + case Types.DECIMAL: + return "java.math.BigDecimal"; + case Types.CHAR: + case Types.VARCHAR: + case Types.LONGVARCHAR: + return "java.lang.String"; + case Types.DATE: + return "java.sql.Date"; + case Types.TIME: + return "java.sql.Time"; + case Types.TIMESTAMP: + return "java.sql.Timestamp"; + case Types.BINARY: + case Types.VARBINARY: + case Types.LONGVARBINARY: + return "byte[]"; + case java.sql.Types.STRUCT: + return "java.sql.Struct"; + case java.sql.Types.ARRAY: + return "java.sql.Array"; + case Types.BLOB: + return "java.sql.Blob"; + case Types.CLOB: + return "java.sql.Clob"; + case java.sql.Types.REF: + return "java.sql.Ref"; + default: + throw new SqlException(logWriter_, "Not supported"); + } + } + + //----------------------------helper methods--------------------------= -------- + + + void checkForValidColumnIndex(int column) throws SqlException { + if (column < 1 || column > columns_) { + throw new SqlException(logWriter_, "Invalid argument: column i= ndex " + + column + " is out of range."); + } + } + + // If the input parameter has been set, return true, else return false. + private boolean isParameterModeGuessedAsAnInput(int parameterIndex) { + if (sqlxParmmode_[parameterIndex - 1] =3D=3D java.sql.ParameterMet= aData.parameterModeIn || + sqlxParmmode_[parameterIndex - 1] =3D=3D java.sql.Paramete= rMetaData.parameterModeInOut) { + return true; + } + return false; + } + + // Does OUT parm registration rely on extended describe? + // If the output parameter has been registered, return true, else retu= rn false. + public boolean isParameterModeGuessedAsOutput(int parameterIndex) { + return sqlxParmmode_[parameterIndex - 1] >=3D java.sql.ParameterMe= taData.parameterModeInOut; + } + + // Only called when column meta data is not described. Called by setXX= X methods. + public void guessInputParameterMetaData(int parameterIndex, + int jdbcType) throws SqlExcept= ion { + guessInputParameterMetaData(parameterIndex, jdbcType, 0); + } + + private void setParmModeForInputParameter(int parameterIndex) { + if (sqlxParmmode_[parameterIndex - 1] =3D=3D java.sql.ParameterMet= aData.parameterModeOut) { + sqlxParmmode_[parameterIndex - 1] =3D java.sql.ParameterMetaDa= ta.parameterModeInOut; + } else if (sqlxParmmode_[parameterIndex - 1] =3D=3D java.sql.Param= eterMetaData.parameterModeUnknown) { + sqlxParmmode_[parameterIndex - 1] =3D java.sql.ParameterMetaDa= ta.parameterModeIn; + } + } + + // Only called when column meta data is not described. Called by setXX= X methods. + // Scale is only applied for Decimal or Numeric JDBC type. + public void guessInputParameterMetaData(int parameterIndex, int jdbcType, - int scale) throws SqlException - { - setParmModeForOutputParameter (parameterIndex); - int driverType =3D getInternalTypeForGuessedOrRegisteredJdbcType (jdbc= Type); - if (isParameterModeGuessedAsAnInput (parameterIndex)) { // if input pa= rameter has been set already - // Verify that "set" and "registered" types are compatible. - if (!isCompatibleDriverTypes (driverType, types_[parameterIndex -1])= ) { - throw new SqlException (logWriter_, "The jdbcType does not match = between the setter method and " + - "the registerOutParameter method."); - } - // the registered type will take precedence over any previously gues= sed input "set" type - } - guessParameterMetaDataBasedOnSupportedDriverType (parameterIndex, jdbc= Type=3D=3Djava.sql.Types.BIGINT, driverType, scale); - } - - private boolean isCompatibleDriverTypes (int registeredType, int guessed= InputType) - { - switch (registeredType) { - case Types.CHAR: - case Types.VARCHAR: - case Types.LONGVARCHAR: - return guessedInputType =3D=3D Types.CHAR || guessedInputType =3D=3D= Types.VARCHAR || guessedInputType =3D=3D Types.LONGVARCHAR; - case Types.BINARY: - case Types.VARBINARY: - case Types.LONGVARBINARY: - return guessedInputType =3D=3D Types.BINARY || guessedInputType =3D= =3D Types.VARBINARY || guessedInputType =3D=3D Types.LONGVARBINARY; - default: - return registeredType =3D=3D guessedInputType; - } - } - - // Only used when describe information is not available. - private int getInternalTypeForGuessedOrRegisteredJdbcType (int guessedOr= RegisteredJdbcType) throws SqlException - { - switch (guessedOrRegisteredJdbcType) { - case java.sql.Types.BIT: - case java.sql.Types.TINYINT: - case java.sql.Types.SMALLINT: - return Types.SMALLINT; - case java.sql.Types.INTEGER: - return Types.INTEGER; - case java.sql.Types.BIGINT: - return Types.BIGINT; - case java.sql.Types.REAL: - return Types.REAL; - case java.sql.Types.DOUBLE: - case java.sql.Types.FLOAT: - return Types.DOUBLE; - case java.sql.Types.DECIMAL: - case java.sql.Types.NUMERIC: - return Types.DECIMAL; - case java.sql.Types.DATE: - return Types.DATE; - case java.sql.Types.TIME: - return Types.TIME; - case java.sql.Types.TIMESTAMP: - return Types.TIMESTAMP; - case java.sql.Types.CHAR: - return Types.CHAR; - case java.sql.Types.VARCHAR: - return Types.VARCHAR; - case java.sql.Types.LONGVARCHAR: - return Types.LONGVARCHAR; - case java.sql.Types.BINARY: - return Types.BINARY; - case java.sql.Types.VARBINARY: - return Types.VARBINARY; - case java.sql.Types.LONGVARBINARY: - return Types.LONGVARBINARY; - case java.sql.Types.BLOB: - return Types.BLOB; - case java.sql.Types.CLOB: - return Types.CLOB; - case java.sql.Types.NULL: - case java.sql.Types.OTHER: - throw new SqlException (logWriter_, "Jdbc type " + guessedOrRegiste= redJdbcType + " not yet supported."); - default: - throw new SqlException (logWriter_, "Unrecognized jdbc type " + gues= sedOrRegisteredJdbcType); - } - } - - private void guessParameterMetaDataBasedOnSupportedDriverType (int param= eterIndex, - boolean i= sBigInt, - int drive= rType, - int scale= ) throws SqlException - { - switch (driverType) { - case Types.SMALLINT: - guessParameterMetaData (parameterIndex, driverType, 2, 0, 0); - break; - case Types.INTEGER: - guessParameterMetaData (parameterIndex, driverType, 4, 0, 0); - break; - case Types.BIGINT: - guessParameterMetaData (parameterIndex, driverType, 8, 0, 0); - break; - case Types.REAL: - guessParameterMetaData (parameterIndex, driverType, 4, 0, 0); - break; - case Types.DOUBLE: - guessParameterMetaData (parameterIndex, driverType, 8, 0, 0); - break; - case Types.DECIMAL: - if (isBigInt) - guessParameterMetaData (parameterIndex, driverType, 0, 19, 0); - else - guessParameterMetaData (parameterIndex, driverType, 0, 31, scale); - break; - case Types.DATE: - guessParameterMetaData (parameterIndex, driverType, 10, 0, 0); - break; - case Types.TIME: - guessParameterMetaData (parameterIndex, driverType, 8, 0, 0); - break; - case Types.TIMESTAMP: - guessParameterMetaData (parameterIndex, driverType, 26, 0, 0); - break; - case Types.CHAR: - case Types.VARCHAR: - guessParameterMetaData (parameterIndex, driverType, 32672, 0, 0); - break; - case Types.LONGVARCHAR: - guessParameterMetaData (parameterIndex, driverType, 32700, 0, 0); - break; - case Types.BINARY: - case Types.VARBINARY: - guessParameterMetaData (parameterIndex, driverType, 4000, 0, 0); - break; - case Types.LONGVARBINARY: - guessParameterMetaData (parameterIndex, driverType, 32700, 0, 0); - break; - case Types.BLOB: - // 32768 will cause 8004 for a null placeholder length (could hard c= ode in NET layer) - guessParameterMetaData (parameterIndex, driverType, 32768, 0, 0); - break; - case Types.CLOB: - // 32768 will cause 8004 for a null placeholder length (could hard c= ode in NET layer) - guessParameterMetaData (parameterIndex, driverType, 32768, 0, 0); - break; - default: - throw new SqlException (logWriter_, "Unrecognized driver type " + dr= iverType); - } - } - - // Only called when column meta data is not described - private void guessParameterMetaData (int parameterIndex, - int type, - int length, - int precision, - int scale) - { - // Always guess that the column is nullable - nullable_[parameterIndex-1] =3D true; - types_[parameterIndex-1] =3D type; - sqlLength_[parameterIndex-1] =3D length; - sqlPrecision_[parameterIndex-1] =3D precision; - sqlScale_[parameterIndex-1] =3D scale; - sqlType_[parameterIndex-1] =3D mapDriverToSqlType(type, true); - } - - int mapDriverToSqlType(int type, boolean nullable) - { - int sqlType =3D 0; - switch (type) - { - case java.sql.Types.SMALLINT: - sqlType =3D Types.DERBY_SQLTYPE_NSMALL; - break; - case java.sql.Types.INTEGER: - sqlType =3D Types.DERBY_SQLTYPE_NINTEGER; - break; - case java.sql.Types.BIGINT: - sqlType =3D Types.DERBY_SQLTYPE_NBIGINT; - break; - case java.sql.Types.REAL: - case java.sql.Types.DOUBLE: - case java.sql.Types.FLOAT: - sqlType =3D Types.DERBY_SQLTYPE_NFLOAT; - break; - case java.sql.Types.DATE: - sqlType =3D Types.DERBY_SQLTYPE_NDATE; - break; - case java.sql.Types.TIME: - sqlType =3D Types.DERBY_SQLTYPE_NTIME; - break; - case java.sql.Types.TIMESTAMP: - sqlType =3D Types.DERBY_SQLTYPE_NTIMESTAMP; - break; - case java.sql.Types.CHAR: - case java.sql.Types.VARCHAR: - sqlType =3D Types.DERBY_SQLTYPE_NVARCHAR; - break; - case java.sql.Types.LONGVARCHAR: - sqlType =3D Types.DERBY_SQLTYPE_NLONG; - break; - case java.sql.Types.BINARY: - case java.sql.Types.VARBINARY: - sqlType =3D Types.DERBY_SQLTYPE_NVARCHAR; - break; - case java.sql.Types.LONGVARBINARY: - sqlType =3D Types.DERBY_SQLTYPE_NLONG; - break; - case java.sql.Types.NUMERIC: - case java.sql.Types.DECIMAL: - sqlType =3D Types.DERBY_SQLTYPE_NDECIMAL; - break; - case java.sql.Types.BLOB: - sqlType =3D Types.DERBY_SQLTYPE_NBLOB; - break; - case java.sql.Types.CLOB: - sqlType =3D Types.DERBY_SQLTYPE_NCLOB; - break; - default: - break; // bug check - } - if (!nullable) - sqlType--; - return sqlType; - } - - - public void setLogWriter (LogWriter logWriter) - { - logWriter_ =3D logWriter; - } - - private void nullDataForGC() - { - columns_ =3D 0; - nullable_ =3D null; - types_ =3D null; - singleMixedByteOrDouble_ =3D null; - sqldRdbnam_ =3D null; - sqldSchema_ =3D null; - sqlPrecision_ =3D null; - sqlScale_ =3D null; - sqlLength_ =3D null; - sqlType_ =3D null; - sqlCcsid_ =3D null; - sqlName_ =3D null; - sqlLabel_ =3D null; - sqlUnnamed_ =3D null; - sqlComment_ =3D null; - sqlxKeymem_ =3D null; - sqlxGenerated_ =3D null; - sqlxParmmode_ =3D null; - sqlxCorname_ =3D null; - sqlxName_ =3D null; - sqlxBasename_ =3D null; - sqlxUpdatable_ =3D null; - sqlxSchema_ =3D null; - sqlxRdbnam_ =3D null; - clientParamtertype_ =3D null; - types_ =3D null; - } - - public boolean hasLobColumns () - { - for (int i=3D0; i1, ignore - } - } - } - - private static void loadResources () throws SqlException - { - try { - dncResources__ =3D (java.util.ResourceBundle) java.security.AccessCo= ntroller.doPrivileged ( - new org.apache.derby.client.am.GetResourceBundleAction (classNameF= orResources)); - } - catch (java.security.PrivilegedActionException e) { - throw new SqlException (null, - "[derby] " + - "PrivilegedActionException:" + - e.getException()); - } - catch (java.util.MissingResourceException e) { - // A null log writer is passed, because jdbc 1 sql exceptions are au= tomatically traced - throw new SqlException (null, - "[derby] " + - "Missing resource bundle:" + - " a resource bundle could not be found" + - " in the " + packageNameForDNC + " package f= or " + Configuration.dncDriverName); - } - } - - public static void checkForExceptionsFromLoadConfiguration (LogWriter dn= cLogWriter) throws SqlException - { - if (dncResources__ =3D=3D null) { - throw new SqlException (dncLogWriter, - "Missing resource bundle: a resource bundle = could not be found" + - " in the " + Configuration.packageNameForDNC= + " package for " + Configuration.dncDriverName); - } - } - - /** - * load product version information and accumulate exceptions - */ - private static void loadProductVersionHolder() throws SqlException - { - try { - dncProductVersionHolder__ =3D buildProductVersionHolder(); - } - catch (java.security.PrivilegedActionException e) { - throw new SqlException (null, - "[derby] " + - "PrivilegedActionException:" + - e.getException()); - } - catch (java.io.IOException ioe) { - throw new SqlException (null, - "[derby] " + - "IOException:" + - ioe); - } - } - - - // Create ProductVersionHolder in security block for Java 2 security. - private static ProductVersionHolder buildProductVersionHolder() throws - java.security.PrivilegedActionException, IOException - { - ProductVersionHolder myPVH=3D null; - myPVH =3D (ProductVersionHolder)=20 - AccessController.doPrivileged( - new PrivilegedExceptionAction() { - =20 - public Object run() throws IOException - { - InputStream versionStream =3D getClass().getResourceAsStream(Product= GenusNames.DNC_INFO); - =09 - return ProductVersionHolder.getProductVersionHolderFromMyEnv(version= Stream); - } - }); - =20 - return myPVH; - } + // -------------------------- metrics ---------------------- + // Not currently used by production builds. + // We can't really use this stuff with tracing enabled, the results ar= e not accurate. + + // -------------------------- compiled in properties -----------------= -------- + + public final static boolean enableNetConnectionPooling =3D true; + + final static boolean rangeCheckCrossConverters =3D true; + + // Define different levels of bug checking, for now turn all bits on. + final static int bugCheckLevel =3D 0xff; + + // --------------------------- connection defaults -------------------= -------- + + // This is the DERBY default and maps to DERBY's "Cursor Stability". + public final static int defaultIsolation =3D java.sql.Connection.TRANS= ACTION_READ_COMMITTED; + + // ---------------------------- statement defaults--------------------= -------- + + public static final int defaultFetchSize =3D 64; + + // Prepare attribute constants + public static final String cursorAttribute_SensitiveStatic =3D "SENSIT= IVE STATIC SCROLL "; + public static final String cursorAttribute_SensitiveStaticRowset =3D c= ursorAttribute_SensitiveStatic; + public static final String cursorAttribute_SensitiveDynamic =3D "SENSI= TIVE DYNAMIC SCROLL "; + public static final String cursorAttribute_SensitiveDynamicRowset =3D = "SENSITIVE DYNAMIC SCROLL WITH ROWSET POSITIONING "; + public static final String cursorAttribute_Insensitive =3D "INSENSITIV= E SCROLL "; + public static final String cursorAttribute_InsensitiveRowset =3D curso= rAttribute_Insensitive; + + // uncomment the following when we want to use multi-row fetch to supp= ort sensitive static and + // insensitve cursors whenever the server has support for it. + //public static final String cursorAttribute_SensitiveStaticRowset =3D= "SENSITIVE STATIC SCROLL WITH ROWSET POSITIONING "; + //public static final String cursorAttribute_InsensitiveRowset =3D "IN= SENSITIVE SCROLL WITH ROWSET POSITIONING "; + + public static final String cursorAttribute_ForUpdate =3D "FOR UPDATE "; + public static final String cursorAttribute_ForReadOnly =3D "FOR READ O= NLY "; + + public static final String cursorAttribute_WithHold =3D "WITH HOLD "; + + // -----------------------Load resource bundles for the driver asap---= -------- + + private static final String packageNameForDNC =3D "org.apache.derby.cl= ient"; + private static final String classNameForResources =3D "org.apache.derb= y=2Eclient.resources.Resources"; + + public static SqlException exceptionsOnLoadResources =3D null; // used= by ClientDriver to accumulate load exceptions + public static java.util.ResourceBundle dncResources__; + + static { + try { + loadProductVersionHolder(); + loadResources(); + } catch (SqlException e) { + exceptionsOnLoadResources =3D e; + } + try { + jreLevel =3D System.getProperty("java.version"); + } catch (SecurityException e) { + } // ignore it, assume 1.3.0 + java.util.StringTokenizer st =3D new java.util.StringTokenizer(jre= Level, "."); + int jreState =3D 0; + while (st.hasMoreTokens()) { + int i; + try { + i =3D java.lang.Integer.parseInt(st.nextToken()); // get i= nt value + } catch (NumberFormatException e) { + i =3D 0; + } + switch (jreState++) { + case 0: + jreLevelMajor =3D i; // state 0, this is the major version + break; + case 1: + jreLevelMinor =3D i; // state 1, this is the minor version + break; + default: + break; // state >1, ignore + } + } + } + + private static void loadResources() throws SqlException { + try { + dncResources__ =3D (java.util.ResourceBundle) java.security.Ac= cessController.doPrivileged(new org.apache.derby.client.am.GetResourceBundl= eAction(classNameForResources)); + } catch (java.security.PrivilegedActionException e) { + throw new SqlException(null, + "[derby] " + + "PrivilegedActionException:" + + e.getException()); + } catch (java.util.MissingResourceException e) { + // A null log writer is passed, because jdbc 1 sql exceptions = are automatically traced + throw new SqlException(null, + "[derby] " + + "Missing resource bundle:" + + " a resource bundle could not be found" + + " in the " + packageNameForDNC + " package for " + Con= figuration.dncDriverName); + } + } + + public static void checkForExceptionsFromLoadConfiguration(LogWriter d= ncLogWriter) throws SqlException { + if (dncResources__ =3D=3D null) { + throw new SqlException(dncLogWriter, + "Missing resource bundle: a resource bundle could not = be found" + + " in the " + Configuration.packageNameForDNC + " packa= ge for " + Configuration.dncDriverName); + } + } + + /** + * load product version information and accumulate exceptions + */ + private static void loadProductVersionHolder() throws SqlException { + try { + dncProductVersionHolder__ =3D buildProductVersionHolder(); + } catch (java.security.PrivilegedActionException e) { + throw new SqlException(null, + "[derby] " + + "PrivilegedActionException:" + + e.getException()); + } catch (java.io.IOException ioe) { + throw new SqlException(null, + "[derby] " + + "IOException:" + + ioe); + } + } + + + // Create ProductVersionHolder in security block for Java 2 security. + private static ProductVersionHolder buildProductVersionHolder() throws + java.security.PrivilegedActionException, IOException { + ProductVersionHolder myPVH =3D null; + myPVH =3D (ProductVersionHolder) + AccessController.doPrivileged(new PrivilegedExceptionActio= n() { + + public Object run() throws IOException { + InputStream versionStream =3D getClass().getResour= ceAsStream(ProductGenusNames.DNC_INFO); + + return ProductVersionHolder.getProductVersionHolde= rFromMyEnv(versionStream); + } + }); + + return myPVH; + } =20 }