Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/sql/rowset/RowSetMetaDataImpl.java
38918 views
/*1* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.sql.rowset;2627import java.sql.*;28import javax.sql.*;29import java.io.*;3031import java.lang.reflect.*;3233/**34* Provides implementations for the methods that set and get35* metadata information about a <code>RowSet</code> object's columns.36* A <code>RowSetMetaDataImpl</code> object keeps track of the37* number of columns in the rowset and maintains an internal array38* of column attributes for each column.39* <P>40* A <code>RowSet</code> object creates a <code>RowSetMetaDataImpl</code>41* object internally in order to set and retrieve information about42* its columns.43* <P>44* NOTE: All metadata in a <code>RowSetMetaDataImpl</code> object45* should be considered as unavailable until the <code>RowSet</code> object46* that it describes is populated.47* Therefore, any <code>RowSetMetaDataImpl</code> method that retrieves information48* is defined as having unspecified behavior when it is called49* before the <code>RowSet</code> object contains data.50*51* @since 1.552*/53public class RowSetMetaDataImpl implements RowSetMetaData, Serializable {5455/**56* The number of columns in the <code>RowSet</code> object that created57* this <code>RowSetMetaDataImpl</code> object.58* @serial59*/60private int colCount;6162/**63* An array of <code>ColInfo</code> objects used to store information64* about each column in the <code>RowSet</code> object for which65* this <code>RowSetMetaDataImpl</code> object was created. The first66* <code>ColInfo</code> object in this array contains information about67* the first column in the <code>RowSet</code> object, the second element68* contains information about the second column, and so on.69* @serial70*/71private ColInfo[] colInfo;7273/**74* Checks to see that the designated column is a valid column number for75* the <code>RowSet</code> object for which this <code>RowSetMetaDataImpl</code>76* was created. To be valid, a column number must be greater than77* <code>0</code> and less than or equal to the number of columns in a row.78* @throws <code>SQLException</code> with the message "Invalid column index"79* if the given column number is out of the range of valid column80* numbers for the <code>RowSet</code> object81*/82private void checkColRange(int col) throws SQLException {83if (col <= 0 || col > colCount) {84throw new SQLException("Invalid column index :"+col);85}86}8788/**89* Checks to see that the given SQL type is a valid column type and throws an90* <code>SQLException</code> object if it is not.91* To be valid, a SQL type must be one of the constant values92* in the <code><a href="../../sql/Types.html">java.sql.Types</a></code>93* class.94*95* @param SQLType an <code>int</code> defined in the class <code>java.sql.Types</code>96* @throws SQLException if the given <code>int</code> is not a constant defined in the97* class <code>java.sql.Types</code>98*/99private void checkColType(int SQLType) throws SQLException {100try {101Class<?> c = java.sql.Types.class;102Field[] publicFields = c.getFields();103int fieldValue = 0;104for (int i = 0; i < publicFields.length; i++) {105fieldValue = publicFields[i].getInt(c);106if (fieldValue == SQLType) {107return;108}109}110} catch (Exception e) {111throw new SQLException(e.getMessage());112}113throw new SQLException("Invalid SQL type for column");114}115116/**117* Sets to the given number the number of columns in the <code>RowSet</code>118* object for which this <code>RowSetMetaDataImpl</code> object was created.119*120* @param columnCount an <code>int</code> giving the number of columns in the121* <code>RowSet</code> object122* @throws SQLException if the given number is equal to or less than zero123*/124public void setColumnCount(int columnCount) throws SQLException {125126if (columnCount <= 0) {127throw new SQLException("Invalid column count. Cannot be less " +128"or equal to zero");129}130131colCount = columnCount;132133// If the colCount is Integer.MAX_VALUE,134// we do not initialize the colInfo object.135// even if we try to initialize the colCount with136// colCount = Integer.MAx_VALUE-1, the colInfo137// initialization fails throwing an ERROR138// OutOfMemory Exception. So we do not initialize139// colInfo at Integer.MAX_VALUE. This is to pass TCK.140141if(!(colCount == Integer.MAX_VALUE)) {142colInfo = new ColInfo[colCount + 1];143144for (int i=1; i <= colCount; i++) {145colInfo[i] = new ColInfo();146}147}148149150}151152/**153* Sets whether the designated column is automatically154* numbered, thus read-only, to the given <code>boolean</code>155* value.156*157* @param columnIndex the first column is 1, the second is 2, and so on;158* must be between <code>1</code> and the number of columns159* in the rowset, inclusive160* @param property <code>true</code> if the given column is161* automatically incremented; <code>false</code>162* otherwise163* @throws SQLException if a database access error occurs or164* the given index is out of bounds165*/166public void setAutoIncrement(int columnIndex, boolean property) throws SQLException {167checkColRange(columnIndex);168colInfo[columnIndex].autoIncrement = property;169}170171/**172* Sets whether the name of the designated column is case sensitive to173* the given <code>boolean</code>.174*175* @param columnIndex the first column is 1, the second is 2, and so on;176* must be between <code>1</code> and the number of columns177* in the rowset, inclusive178* @param property <code>true</code> to indicate that the column179* name is case sensitive; <code>false</code> otherwise180* @throws SQLException if a database access error occurs or181* the given column number is out of bounds182*/183public void setCaseSensitive(int columnIndex, boolean property) throws SQLException {184checkColRange(columnIndex);185colInfo[columnIndex].caseSensitive = property;186}187188/**189* Sets whether a value stored in the designated column can be used190* in a <code>WHERE</code> clause to the given <code>boolean</code> value.191*192* @param columnIndex the first column is 1, the second is 2, and so on;193* must be between <code>1</code> and the number194* of columns in the rowset, inclusive195* @param property <code>true</code> to indicate that a column196* value can be used in a <code>WHERE</code> clause;197* <code>false</code> otherwise198*199* @throws SQLException if a database access error occurs or200* the given column number is out of bounds201*/202public void setSearchable(int columnIndex, boolean property)203throws SQLException {204checkColRange(columnIndex);205colInfo[columnIndex].searchable = property;206}207208/**209* Sets whether a value stored in the designated column is a cash210* value to the given <code>boolean</code>.211*212* @param columnIndex the first column is 1, the second is 2, and so on;213* must be between <code>1</code> and the number of columns,214* inclusive between <code>1</code> and the number of columns, inclusive215* @param property true if the value is a cash value; false otherwise.216* @throws SQLException if a database access error occurs217* or the given column number is out of bounds218*/219public void setCurrency(int columnIndex, boolean property)220throws SQLException {221checkColRange(columnIndex);222colInfo[columnIndex].currency = property;223}224225/**226* Sets whether a value stored in the designated column can be set227* to <code>NULL</code> to the given constant from the interface228* <code>ResultSetMetaData</code>.229*230* @param columnIndex the first column is 1, the second is 2, and so on;231* must be between <code>1</code> and the number of columns, inclusive232* @param property one of the following <code>ResultSetMetaData</code> constants:233* <code>columnNoNulls</code>,234* <code>columnNullable</code>, or235* <code>columnNullableUnknown</code>236*237* @throws SQLException if a database access error occurs,238* the given column number is out of bounds, or the value supplied239* for the <i>property</i> parameter is not one of the following240* constants:241* <code>ResultSetMetaData.columnNoNulls</code>,242* <code>ResultSetMetaData.columnNullable</code>, or243* <code>ResultSetMetaData.columnNullableUnknown</code>244*/245public void setNullable(int columnIndex, int property) throws SQLException {246if ((property < ResultSetMetaData.columnNoNulls) ||247property > ResultSetMetaData.columnNullableUnknown) {248throw new SQLException("Invalid nullable constant set. Must be " +249"either columnNoNulls, columnNullable or columnNullableUnknown");250}251checkColRange(columnIndex);252colInfo[columnIndex].nullable = property;253}254255/**256* Sets whether a value stored in the designated column is a signed257* number to the given <code>boolean</code>.258*259* @param columnIndex the first column is 1, the second is 2, and so on;260* must be between <code>1</code> and the number of columns, inclusive261* @param property <code>true</code> to indicate that a column262* value is a signed number;263* <code>false</code> to indicate that it is not264* @throws SQLException if a database access error occurs265* or the given column number is out of bounds266*/267public void setSigned(int columnIndex, boolean property) throws SQLException {268checkColRange(columnIndex);269colInfo[columnIndex].signed = property;270}271272/**273* Sets the normal maximum number of chars in the designated column274* to the given number.275*276* @param columnIndex the first column is 1, the second is 2, and so on;277* must be between <code>1</code> and the number of columns, inclusive278* @param size the maximum size of the column in chars; must be279* <code>0</code> or more280* @throws SQLException if a database access error occurs,281* the given column number is out of bounds, or <i>size</i> is282* less than <code>0</code>283*/284public void setColumnDisplaySize(int columnIndex, int size) throws SQLException {285if (size < 0) {286throw new SQLException("Invalid column display size. Cannot be less " +287"than zero");288}289checkColRange(columnIndex);290colInfo[columnIndex].columnDisplaySize = size;291}292293/**294* Sets the suggested column label for use in printouts and295* displays, if any, to <i>label</i>. If <i>label</i> is296* <code>null</code>, the column label is set to an empty string297* ("").298*299* @param columnIndex the first column is 1, the second is 2, and so on;300* must be between <code>1</code> and the number of columns, inclusive301* @param label the column label to be used in printouts and displays; if the302* column label is <code>null</code>, an empty <code>String</code> is303* set304* @throws SQLException if a database access error occurs305* or the given column index is out of bounds306*/307public void setColumnLabel(int columnIndex, String label) throws SQLException {308checkColRange(columnIndex);309if (label != null) {310colInfo[columnIndex].columnLabel = label;311} else {312colInfo[columnIndex].columnLabel = "";313}314}315316/**317* Sets the column name of the designated column to the given name.318*319* @param columnIndex the first column is 1, the second is 2, and so on;320* must be between <code>1</code> and the number of columns, inclusive321* @param columnName a <code>String</code> object indicating the column name;322* if the given name is <code>null</code>, an empty <code>String</code>323* is set324* @throws SQLException if a database access error occurs or the given column325* index is out of bounds326*/327public void setColumnName(int columnIndex, String columnName) throws SQLException {328checkColRange(columnIndex);329if (columnName != null) {330colInfo[columnIndex].columnName = columnName;331} else {332colInfo[columnIndex].columnName = "";333}334}335336/**337* Sets the designated column's table's schema name, if any, to338* <i>schemaName</i>. If <i>schemaName</i> is <code>null</code>,339* the schema name is set to an empty string ("").340*341* @param columnIndex the first column is 1, the second is 2, and so on;342* must be between <code>1</code> and the number of columns, inclusive343* @param schemaName the schema name for the table from which a value in the344* designated column was derived; may be an empty <code>String</code>345* or <code>null</code>346* @throws SQLException if a database access error occurs347* or the given column number is out of bounds348*/349public void setSchemaName(int columnIndex, String schemaName) throws SQLException {350checkColRange(columnIndex);351if (schemaName != null ) {352colInfo[columnIndex].schemaName = schemaName;353} else {354colInfo[columnIndex].schemaName = "";355}356}357358/**359* Sets the total number of decimal digits in a value stored in the360* designated column to the given number.361*362* @param columnIndex the first column is 1, the second is 2, and so on;363* must be between <code>1</code> and the number of columns, inclusive364* @param precision the total number of decimal digits; must be <code>0</code>365* or more366* @throws SQLException if a database access error occurs,367* <i>columnIndex</i> is out of bounds, or <i>precision</i>368* is less than <code>0</code>369*/370public void setPrecision(int columnIndex, int precision) throws SQLException {371372if (precision < 0) {373throw new SQLException("Invalid precision value. Cannot be less " +374"than zero");375}376checkColRange(columnIndex);377colInfo[columnIndex].colPrecision = precision;378}379380/**381* Sets the number of digits to the right of the decimal point in a value382* stored in the designated column to the given number.383*384* @param columnIndex the first column is 1, the second is 2, and so on;385* must be between <code>1</code> and the number of columns, inclusive386* @param scale the number of digits to the right of the decimal point; must be387* zero or greater388* @throws SQLException if a database access error occurs,389* <i>columnIndex</i> is out of bounds, or <i>scale</i>390* is less than <code>0</code>391*/392public void setScale(int columnIndex, int scale) throws SQLException {393if (scale < 0) {394throw new SQLException("Invalid scale size. Cannot be less " +395"than zero");396}397checkColRange(columnIndex);398colInfo[columnIndex].colScale = scale;399}400401/**402* Sets the name of the table from which the designated column403* was derived to the given table name.404*405* @param columnIndex the first column is 1, the second is 2, and so on;406* must be between <code>1</code> and the number of columns, inclusive407* @param tableName the column's table name; may be <code>null</code> or an408* empty string409* @throws SQLException if a database access error occurs410* or the given column number is out of bounds411*/412public void setTableName(int columnIndex, String tableName) throws SQLException {413checkColRange(columnIndex);414if (tableName != null) {415colInfo[columnIndex].tableName = tableName;416} else {417colInfo[columnIndex].tableName = "";418}419}420421/**422* Sets the catalog name of the table from which the designated423* column was derived to <i>catalogName</i>. If <i>catalogName</i>424* is <code>null</code>, the catalog name is set to an empty string.425*426* @param columnIndex the first column is 1, the second is 2, and so on;427* must be between <code>1</code> and the number of columns, inclusive428* @param catalogName the column's table's catalog name; if the catalogName429* is <code>null</code>, an empty <code>String</code> is set430* @throws SQLException if a database access error occurs431* or the given column number is out of bounds432*/433public void setCatalogName(int columnIndex, String catalogName) throws SQLException {434checkColRange(columnIndex);435if (catalogName != null)436colInfo[columnIndex].catName = catalogName;437else438colInfo[columnIndex].catName = "";439}440441/**442* Sets the SQL type code for values stored in the designated column443* to the given type code from the class <code>java.sql.Types</code>.444*445* @param columnIndex the first column is 1, the second is 2, and so on;446* must be between <code>1</code> and the number of columns, inclusive447* @param SQLType the designated column's SQL type, which must be one of the448* constants in the class <code>java.sql.Types</code>449* @throws SQLException if a database access error occurs,450* the given column number is out of bounds, or the column type451* specified is not one of the constants in452* <code>java.sql.Types</code>453* @see java.sql.Types454*/455public void setColumnType(int columnIndex, int SQLType) throws SQLException {456// examine java.sql.Type reflectively, loop on the fields and check457// this. Separate out into a private method458checkColType(SQLType);459checkColRange(columnIndex);460colInfo[columnIndex].colType = SQLType;461}462463/**464* Sets the type name used by the data source for values stored in the465* designated column to the given type name.466*467* @param columnIndex the first column is 1, the second is 2, and so on;468* must be between <code>1</code> and the number of columns, inclusive469* @param typeName the data source-specific type name; if <i>typeName</i> is470* <code>null</code>, an empty <code>String</code> is set471* @throws SQLException if a database access error occurs472* or the given column number is out of bounds473*/474public void setColumnTypeName(int columnIndex, String typeName)475throws SQLException {476checkColRange(columnIndex);477if (typeName != null) {478colInfo[columnIndex].colTypeName = typeName;479} else {480colInfo[columnIndex].colTypeName = "";481}482}483484/**485* Retrieves the number of columns in the <code>RowSet</code> object486* for which this <code>RowSetMetaDataImpl</code> object was created.487*488* @return the number of columns489* @throws SQLException if an error occurs determining the column count490*/491public int getColumnCount() throws SQLException {492return colCount;493}494495/**496* Retrieves whether a value stored in the designated column is497* automatically numbered, and thus readonly.498*499* @param columnIndex the first column is 1, the second is 2, and so on;500* must be between <code>1</code> and the number of columns, inclusive501* @return <code>true</code> if the column is automatically numbered;502* <code>false</code> otherwise503* @throws SQLException if a database access error occurs504* or the given column number is out of bounds505*/506public boolean isAutoIncrement(int columnIndex) throws SQLException {507checkColRange(columnIndex);508return colInfo[columnIndex].autoIncrement;509}510511/**512* Indicates whether the case of the designated column's name513* matters.514*515* @param columnIndex the first column is 1, the second is 2, and so on;516* must be between <code>1</code> and the number of columns, inclusive517* @return <code>true</code> if the column name is case sensitive;518* <code>false</code> otherwise519* @throws SQLException if a database access error occurs520* or the given column number is out of bounds521*/522public boolean isCaseSensitive(int columnIndex) throws SQLException {523checkColRange(columnIndex);524return colInfo[columnIndex].caseSensitive;525}526527/**528* Indicates whether a value stored in the designated column529* can be used in a <code>WHERE</code> clause.530*531* @param columnIndex the first column is 1, the second is 2, and so on;532* must be between <code>1</code> and the number of columns, inclusive533* @return <code>true</code> if a value in the designated column can be used in a534* <code>WHERE</code> clause; <code>false</code> otherwise535* @throws SQLException if a database access error occurs536* or the given column number is out of bounds537*/538public boolean isSearchable(int columnIndex) throws SQLException {539checkColRange(columnIndex);540return colInfo[columnIndex].searchable;541}542543/**544* Indicates whether a value stored in the designated column545* is a cash value.546*547* @param columnIndex the first column is 1, the second is 2, and so on;548* must be between <code>1</code> and the number of columns, inclusive549* @return <code>true</code> if a value in the designated column is a cash value;550* <code>false</code> otherwise551* @throws SQLException if a database access error occurs552* or the given column number is out of bounds553*/554public boolean isCurrency(int columnIndex) throws SQLException {555checkColRange(columnIndex);556return colInfo[columnIndex].currency;557}558559/**560* Retrieves a constant indicating whether it is possible561* to store a <code>NULL</code> value in the designated column.562*563* @param columnIndex the first column is 1, the second is 2, and so on;564* must be between <code>1</code> and the number of columns, inclusive565* @return a constant from the <code>ResultSetMetaData</code> interface;566* either <code>columnNoNulls</code>,567* <code>columnNullable</code>, or568* <code>columnNullableUnknown</code>569* @throws SQLException if a database access error occurs570* or the given column number is out of bounds571*/572public int isNullable(int columnIndex) throws SQLException {573checkColRange(columnIndex);574return colInfo[columnIndex].nullable;575}576577/**578* Indicates whether a value stored in the designated column is579* a signed number.580*581* @param columnIndex the first column is 1, the second is 2, and so on;582* must be between <code>1</code> and the number of columns, inclusive583* @return <code>true</code> if a value in the designated column is a signed584* number; <code>false</code> otherwise585* @throws SQLException if a database access error occurs586* or the given column number is out of bounds587*/588public boolean isSigned(int columnIndex) throws SQLException {589checkColRange(columnIndex);590return colInfo[columnIndex].signed;591}592593/**594* Retrieves the normal maximum width in chars of the designated column.595*596* @param columnIndex the first column is 1, the second is 2, and so on;597* must be between <code>1</code> and the number of columns, inclusive598* @return the maximum number of chars that can be displayed in the designated599* column600* @throws SQLException if a database access error occurs601* or the given column number is out of bounds602*/603public int getColumnDisplaySize(int columnIndex) throws SQLException {604checkColRange(columnIndex);605return colInfo[columnIndex].columnDisplaySize;606}607608/**609* Retrieves the suggested column title for the designated610* column for use in printouts and displays.611*612* @param columnIndex the first column is 1, the second is 2, and so on;613* must be between <code>1</code> and the number of columns, inclusive614* @return the suggested column name to use in printouts and displays615* @throws SQLException if a database access error occurs616* or the given column number is out of bounds617*/618public String getColumnLabel(int columnIndex) throws SQLException {619checkColRange(columnIndex);620return colInfo[columnIndex].columnLabel;621}622623/**624* Retrieves the name of the designated column.625*626* @param columnIndex the first column is 1, the second is 2, and so on;627* must be between <code>1</code> and the number of columns, inclusive628* @return the column name of the designated column629* @throws SQLException if a database access error occurs630* or the given column number is out of bounds631*/632public String getColumnName(int columnIndex) throws SQLException {633checkColRange(columnIndex);634return colInfo[columnIndex].columnName;635}636637/**638* Retrieves the schema name of the table from which the value639* in the designated column was derived.640*641* @param columnIndex the first column is 1, the second is 2, and so on;642* must be between <code>1</code> and the number of columns,643* inclusive644* @return the schema name or an empty <code>String</code> if no schema645* name is available646* @throws SQLException if a database access error occurs647* or the given column number is out of bounds648*/649public String getSchemaName(int columnIndex) throws SQLException {650checkColRange(columnIndex);651String str ="";652if(colInfo[columnIndex].schemaName == null){653} else {654str = colInfo[columnIndex].schemaName;655}656return str;657}658659/**660* Retrieves the total number of digits for values stored in661* the designated column.662*663* @param columnIndex the first column is 1, the second is 2, and so on;664* must be between <code>1</code> and the number of columns, inclusive665* @return the precision for values stored in the designated column666* @throws SQLException if a database access error occurs667* or the given column number is out of bounds668*/669public int getPrecision(int columnIndex) throws SQLException {670checkColRange(columnIndex);671return colInfo[columnIndex].colPrecision;672}673674/**675* Retrieves the number of digits to the right of the decimal point676* for values stored in the designated column.677*678* @param columnIndex the first column is 1, the second is 2, and so on;679* must be between <code>1</code> and the number of columns, inclusive680* @return the scale for values stored in the designated column681* @throws SQLException if a database access error occurs682* or the given column number is out of bounds683*/684public int getScale(int columnIndex) throws SQLException {685checkColRange(columnIndex);686return colInfo[columnIndex].colScale;687}688689/**690* Retrieves the name of the table from which the value691* in the designated column was derived.692*693* @param columnIndex the first column is 1, the second is 2, and so on;694* must be between <code>1</code> and the number of columns, inclusive695* @return the table name or an empty <code>String</code> if no table name696* is available697* @throws SQLException if a database access error occurs698* or the given column number is out of bounds699*/700public String getTableName(int columnIndex) throws SQLException {701checkColRange(columnIndex);702return colInfo[columnIndex].tableName;703}704705/**706* Retrieves the catalog name of the table from which the value707* in the designated column was derived.708*709* @param columnIndex the first column is 1, the second is 2, and so on;710* must be between <code>1</code> and the number of columns, inclusive711* @return the catalog name of the column's table or an empty712* <code>String</code> if no catalog name is available713* @throws SQLException if a database access error occurs714* or the given column number is out of bounds715*/716public String getCatalogName(int columnIndex) throws SQLException {717checkColRange(columnIndex);718String str ="";719if(colInfo[columnIndex].catName == null){720} else {721str = colInfo[columnIndex].catName;722}723return str;724}725726/**727* Retrieves the type code (one of the <code>java.sql.Types</code>728* constants) for the SQL type of the value stored in the729* designated column.730*731* @param columnIndex the first column is 1, the second is 2, and so on;732* must be between <code>1</code> and the number of columns, inclusive733* @return an <code>int</code> representing the SQL type of values734* stored in the designated column735* @throws SQLException if a database access error occurs736* or the given column number is out of bounds737* @see java.sql.Types738*/739public int getColumnType(int columnIndex) throws SQLException {740checkColRange(columnIndex);741return colInfo[columnIndex].colType;742}743744/**745* Retrieves the DBMS-specific type name for values stored in the746* designated column.747*748* @param columnIndex the first column is 1, the second is 2, and so on;749* must be between <code>1</code> and the number of columns, inclusive750* @return the type name used by the data source751* @throws SQLException if a database access error occurs752* or the given column number is out of bounds753*/754public String getColumnTypeName(int columnIndex) throws SQLException {755checkColRange(columnIndex);756return colInfo[columnIndex].colTypeName;757}758759760/**761* Indicates whether the designated column is definitely762* not writable, thus readonly.763*764* @param columnIndex the first column is 1, the second is 2, and so on;765* must be between <code>1</code> and the number of columns, inclusive766* @return <code>true</code> if this <code>RowSet</code> object is read-Only767* and thus not updatable; <code>false</code> otherwise768* @throws SQLException if a database access error occurs769* or the given column number is out of bounds770*/771public boolean isReadOnly(int columnIndex) throws SQLException {772checkColRange(columnIndex);773return colInfo[columnIndex].readOnly;774}775776/**777* Indicates whether it is possible for a write operation on778* the designated column to succeed. A return value of779* <code>true</code> means that a write operation may or may780* not succeed.781*782* @param columnIndex the first column is 1, the second is 2, and so on;783* must be between <code>1</code> and the number of columns, inclusive784* @return <code>true</code> if a write operation on the designated column may785* will succeed; <code>false</code> otherwise786* @throws SQLException if a database access error occurs787* or the given column number is out of bounds788*/789public boolean isWritable(int columnIndex) throws SQLException {790checkColRange(columnIndex);791return colInfo[columnIndex].writable;792}793794/**795* Indicates whether a write operation on the designated column796* will definitely succeed.797*798* @param columnIndex the first column is 1, the second is 2, and so on;799* must be between <code>1</code> and the number of columns, inclusive800* @return <code>true</code> if a write operation on the designated column will801* definitely succeed; <code>false</code> otherwise802* @throws SQLException if a database access error occurs803* or the given column number is out of bounds804*/805public boolean isDefinitelyWritable(int columnIndex) throws SQLException {806checkColRange(columnIndex);807return true;808}809810/**811* Retrieves the fully-qualified name of the class in the Java812* programming language to which a value in the designated column813* will be mapped. For example, if the value is an <code>int</code>,814* the class name returned by this method will be815* <code>java.lang.Integer</code>.816* <P>817* If the value in the designated column has a custom mapping,818* this method returns the name of the class that implements819* <code>SQLData</code>. When the method <code>ResultSet.getObject</code>820* is called to retrieve a value from the designated column, it will821* create an instance of this class or one of its subclasses.822*823* @param columnIndex the first column is 1, the second is 2, and so on;824* must be between <code>1</code> and the number of columns, inclusive825* @return the fully-qualified name of the class in the Java programming826* language that would be used by the method <code>RowSet.getObject</code> to827* retrieve the value in the specified column. This is the class828* name used for custom mapping when there is a custom mapping.829* @throws SQLException if a database access error occurs830* or the given column number is out of bounds831*/832public String getColumnClassName(int columnIndex) throws SQLException {833String className = String.class.getName();834835int sqlType = getColumnType(columnIndex);836837switch (sqlType) {838839case Types.NUMERIC:840case Types.DECIMAL:841className = java.math.BigDecimal.class.getName();842break;843844case Types.BIT:845className = java.lang.Boolean.class.getName();846break;847848case Types.TINYINT:849className = java.lang.Byte.class.getName();850break;851852case Types.SMALLINT:853className = java.lang.Short.class.getName();854break;855856case Types.INTEGER:857className = java.lang.Integer.class.getName();858break;859860case Types.BIGINT:861className = java.lang.Long.class.getName();862break;863864case Types.REAL:865className = java.lang.Float.class.getName();866break;867868case Types.FLOAT:869case Types.DOUBLE:870className = java.lang.Double.class.getName();871break;872873case Types.BINARY:874case Types.VARBINARY:875case Types.LONGVARBINARY:876className = "byte[]";877break;878879case Types.DATE:880className = java.sql.Date.class.getName();881break;882883case Types.TIME:884className = java.sql.Time.class.getName();885break;886887case Types.TIMESTAMP:888className = java.sql.Timestamp.class.getName();889break;890891case Types.BLOB:892className = java.sql.Blob.class.getName();893break;894895case Types.CLOB:896className = java.sql.Clob.class.getName();897break;898}899900return className;901}902903/**904* Returns an object that implements the given interface to allow access to non-standard methods,905* or standard methods not exposed by the proxy.906* The result may be either the object found to implement the interface or a proxy for that object.907* If the receiver implements the interface then that is the object. If the receiver is a wrapper908* and the wrapped object implements the interface then that is the object. Otherwise the object is909* the result of calling <code>unwrap</code> recursively on the wrapped object. If the receiver is not a910* wrapper and does not implement the interface, then an <code>SQLException</code> is thrown.911*912* @param iface A Class defining an interface that the result must implement.913* @return an object that implements the interface. May be a proxy for the actual implementing object.914* @throws java.sql.SQLException If no object found that implements the interface915* @since 1.6916*/917public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException {918919if(isWrapperFor(iface)) {920return iface.cast(this);921} else {922throw new SQLException("unwrap failed for:"+ iface);923}924}925926/**927* Returns true if this either implements the interface argument or is directly or indirectly a wrapper928* for an object that does. Returns false otherwise. If this implements the interface then return true,929* else if this is a wrapper then return the result of recursively calling <code>isWrapperFor</code> on the wrapped930* object. If this does not implement the interface and is not a wrapper, return false.931* This method should be implemented as a low-cost operation compared to <code>unwrap</code> so that932* callers can use this method to avoid expensive <code>unwrap</code> calls that may fail. If this method933* returns true then calling <code>unwrap</code> with the same argument should succeed.934*935* @param interfaces a Class defining an interface.936* @return true if this implements the interface or directly or indirectly wraps an object that does.937* @throws java.sql.SQLException if an error occurs while determining whether this is a wrapper938* for an object with the given interface.939* @since 1.6940*/941public boolean isWrapperFor(Class<?> interfaces) throws SQLException {942return interfaces.isInstance(this);943}944945static final long serialVersionUID = 6893806403181801867L;946947private class ColInfo implements Serializable {948/**949* The field that indicates whether the value in this column is a number950* that is incremented automatically, which makes the value read-only.951* <code>true</code> means that the value in this column952* is automatically numbered; <code>false</code> means that it is not.953*954* @serial955*/956public boolean autoIncrement;957958/**959* The field that indicates whether the value in this column is case sensitive.960* <code>true</code> means that it is; <code>false</code> that it is not.961*962* @serial963*/964public boolean caseSensitive;965966/**967* The field that indicates whether the value in this column is a cash value968* <code>true</code> means that it is; <code>false</code> that it is not.969*970* @serial971*/972public boolean currency;973974/**975* The field that indicates whether the value in this column is nullable.976* The possible values are the <code>ResultSet</code> constants977* <code>columnNoNulls</code>, <code>columnNullable</code>, and978* <code>columnNullableUnknown</code>.979*980* @serial981*/982public int nullable;983984/**985* The field that indicates whether the value in this column is a signed number.986* <code>true</code> means that it is; <code>false</code> that it is not.987*988* @serial989*/990public boolean signed;991992/**993* The field that indicates whether the value in this column can be used in994* a <code>WHERE</code> clause.995* <code>true</code> means that it can; <code>false</code> that it cannot.996*997* @serial998*/999public boolean searchable;10001001/**1002* The field that indicates the normal maximum width in characters for1003* this column.1004*1005* @serial1006*/1007public int columnDisplaySize;10081009/**1010* The field that holds the suggested column title for this column, to be1011* used in printing and displays.1012*1013* @serial1014*/1015public String columnLabel;10161017/**1018* The field that holds the name of this column.1019*1020* @serial1021*/1022public String columnName;10231024/**1025* The field that holds the schema name for the table from which this column1026* was derived.1027*1028* @serial1029*/1030public String schemaName;10311032/**1033* The field that holds the precision of the value in this column. For number1034* types, the precision is the total number of decimal digits; for character types,1035* it is the maximum number of characters; for binary types, it is the maximum1036* length in bytes.1037*1038* @serial1039*/1040public int colPrecision;10411042/**1043* The field that holds the scale (number of digits to the right of the decimal1044* point) of the value in this column.1045*1046* @serial1047*/1048public int colScale;10491050/**1051* The field that holds the name of the table from which this column1052* was derived. This value may be the empty string if there is no1053* table name, such as when this column is produced by a join.1054*1055* @serial1056*/1057public String tableName ="";10581059/**1060* The field that holds the catalog name for the table from which this column1061* was derived. If the DBMS does not support catalogs, the value may be the1062* empty string.1063*1064* @serial1065*/1066public String catName;10671068/**1069* The field that holds the type code from the class <code>java.sql.Types</code>1070* indicating the type of the value in this column.1071*1072* @serial1073*/1074public int colType;10751076/**1077* The field that holds the type name used by this particular data source1078* for the value stored in this column.1079*1080* @serial1081*/1082public String colTypeName;10831084/**1085* The field that holds the updatability boolean per column of a RowSet1086*1087* @serial1088*/1089public boolean readOnly = false;10901091/**1092* The field that hold the writable boolean per column of a RowSet1093*1094*@serial1095*/1096public boolean writable = true;10971098static final long serialVersionUID = 5490834817919311283L;1099}1100}110111021103