FileDocCategorySizeDatePackage
RowSetMetaDataImpl.javaAPI DocJava SE 5 API42049Fri Aug 26 14:57:52 BST 2005javax.sql.rowset

RowSetMetaDataImpl

public class RowSetMetaDataImpl extends Object implements Serializable, RowSetMetaData
Provides implementations for the methods that set and get metadata information about a RowSet object's columns. A RowSetMetaDataImpl object keeps track of the number of columns in the rowset and maintains an internal array of column attributes for each column.

A RowSet object creates a RowSetMetaDataImpl object internally in order to set and retrieve information about its columns.

NOTE: All metadata in a RowSetMetaDataImpl object should be considered as unavailable until the RowSet object that it describes is populated. Therefore, any RowSetMetaDataImpl method that retrieves information is defined as having unspecified behavior when it is called before the RowSet object contains data.

Fields Summary
private int
colCount
The number of columns in the RowSet object that created this RowSetMetaDataImpl object.
private ColInfo[]
colInfo
An array of ColInfo objects used to store information about each column in the RowSet object for which this RowSetMetaDataImpl object was created. The first ColInfo object in this array contains information about the first column in the RowSet object, the second element contains information about the second column, and so on.
static final long
serialVersionUID
Constructors Summary
Methods Summary
private voidcheckColRange(int col)
Checks to see that the designated column is a valid column number for the RowSet object for which this RowSetMetaDataImpl was created. To be valid, a column number must be greater than 0 and less than or equal to the number of columns in a row.

throws
SQLException with the message "Invalid column index" if the given column number is out of the range of valid column numbers for the RowSet object

        if (col <= 0 || col > colCount) {
            throw new SQLException("Invalid column index :"+col);
        }
    
private voidcheckColType(int SQLType)
Checks to see that the given SQL type is a valid column type and throws an SQLException object if it is not. To be valid, a SQL type must be one of the constant values in the java.sql.Types class.

param
SQLType an int defined in the class java.sql.Types
throws
SQLException if the given int is not a constant defined in the class java.sql.Types

        try {
            Class c = java.sql.Types.class;
            Field[] publicFields = c.getFields();        
            int fieldValue = 0;
            for (int i = 0; i < publicFields.length; i++) {              
                fieldValue = publicFields[i].getInt(c);                
                if (fieldValue == SQLType) {                    
                    return;                    
                 }
            }
        } catch (Exception e) {
            throw new SQLException(e.getMessage());
        }
        throw new SQLException("Invalid SQL type for column");
    
public java.lang.StringgetCatalogName(int columnIndex)
Retrieves the catalog name of the table from which the value in the designated column was derived.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
return
the catalog name of the column's table or an empty String if no catalog name is available
throws
SQLException if a database access error occurs or the given column number is out of bounds

        checkColRange(columnIndex);
        String str ="";
        if(colInfo[columnIndex].catName == null){
        } else {
           str = colInfo[columnIndex].catName;
        }
        return str;
    
public java.lang.StringgetColumnClassName(int columnIndex)
Retrieves the fully-qualified name of the class in the Java programming language to which a value in the designated column will be mapped. For example, if the value is an int, the class name returned by this method will be java.lang.Integer.

If the value in the designated column has a custom mapping, this method returns the name of the class that implements SQLData. When the method ResultSet.getObject is called to retrieve a value from the designated column, it will create an instance of this class or one of its subclasses.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
return
the fully-qualified name of the class in the Java programming language that would be used by the method RowSet.getObject to retrieve the value in the specified column. This is the class name used for custom mapping when there is a custom mapping.
throws
SQLException if a database access error occurs or the given column number is out of bounds

        String className = (new String()).getClass().getName();
        
        int sqlType = getColumnType(columnIndex);

        switch (sqlType) {

        case Types.NUMERIC:
        case Types.DECIMAL:
            className = (new java.math.BigDecimal(0)).getClass().getName ();
            break;

        case Types.BIT:			
            className = (new Boolean(false)).getClass().getName ();
            break;

        case Types.TINYINT:
            className = (new Byte("0")).getClass().getName ();
            break;

        case Types.SMALLINT:
            className = (new Short("0")).getClass().getName ();
            break;

        case Types.INTEGER:
            className = (new Integer(0)).getClass().getName ();
            break;

        case Types.BIGINT:
            className = (new Long(0)).getClass().getName ();
            break;

        case Types.REAL:
            className = (new Float(0)).getClass().getName ();
            break;

        case Types.FLOAT:
        case Types.DOUBLE:
            className = (new Double(0)).getClass().getName();
            break;
			
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
            byte[] b = {};
            className = (b.getClass()).getName();
            break;

        case Types.DATE:
            className = (new java.sql.Date(123456)).getClass().getName ();
            break;

        case Types.TIME:
            className = (new java.sql.Time(123456)).getClass().getName ();
            break;
            
        case Types.TIMESTAMP:
            className = (new java.sql.Timestamp(123456)).getClass().getName ();
            break;
            
        case Types.BLOB:
            byte[] blob = {};
            className = (blob.getClass()).getName();
            break;

        case Types.CLOB:
            char[] c = {};
            className = (c.getClass()).getName();
            break;
        }
        
        return className;
    
public intgetColumnCount()
Retrieves the number of columns in the RowSet object for which this RowSetMetaDataImpl object was created.

return
the number of columns
throws
SQLException if an error occurs determining the column count

 
        return colCount;
    
public intgetColumnDisplaySize(int columnIndex)
Retrieves the normal maximum width in chars of the designated column.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
return
the maximum number of chars that can be displayed in the designated column
throws
SQLException if a database access error occurs or the given column number is out of bounds

        checkColRange(columnIndex);
        return colInfo[columnIndex].columnDisplaySize;
    
public java.lang.StringgetColumnLabel(int columnIndex)
Retrieves the the suggested column title for the designated column for use in printouts and displays.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
return
the suggested column name to use in printouts and displays
throws
SQLException if a database access error occurs or the given column number is out of bounds

        checkColRange(columnIndex); 
        return colInfo[columnIndex].columnLabel;
    
public java.lang.StringgetColumnName(int columnIndex)
Retrieves the name of the designated column.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
return
the column name of the designated column
throws
SQLException if a database access error occurs or the given column number is out of bounds

        checkColRange(columnIndex);
        return colInfo[columnIndex].columnName;
    
public intgetColumnType(int columnIndex)
Retrieves the type code (one of the java.sql.Types constants) for the SQL type of the value stored in the designated column.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
return
an int representing the SQL type of values stored in the designated column
throws
SQLException if a database access error occurs or the given column number is out of bounds
see
java.sql.Types

        checkColRange(columnIndex);
        return colInfo[columnIndex].colType;
    
public java.lang.StringgetColumnTypeName(int columnIndex)
Retrieves the DBMS-specific type name for values stored in the designated column.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
return
the type name used by the data source
throws
SQLException if a database access error occurs or the given column number is out of bounds

        
        checkColRange(columnIndex);
        return colInfo[columnIndex].colTypeName;
    
public intgetPrecision(int columnIndex)
Retrieves the total number of digits for values stored in the designated column.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
return
the precision for values stored in the designated column
throws
SQLException if a database access error occurs or the given column number is out of bounds

        checkColRange(columnIndex);
        return colInfo[columnIndex].colPrecision;
    
public intgetScale(int columnIndex)
Retrieves the number of digits to the right of the decimal point for values stored in the designated column.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
return
the scale for values stored in the designated column
throws
SQLException if a database access error occurs or the given column number is out of bounds

        checkColRange(columnIndex);
        return colInfo[columnIndex].colScale;
    
public java.lang.StringgetSchemaName(int columnIndex)
Retrieves the schema name of the table from which the value in the designated column was derived.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
return
the schema name or an empty String if no schema name is available
throws
SQLException if a database access error occurs or the given column number is out of bounds

        checkColRange(columnIndex);
        String str ="";
        if(colInfo[columnIndex].schemaName == null){
        } else {
              str = colInfo[columnIndex].schemaName;
        }
        return str;
    
public java.lang.StringgetTableName(int columnIndex)
Retrieves the name of the table from which the value in the designated column was derived.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
return
the table name or an empty String if no table name is available
throws
SQLException if a database access error occurs or the given column number is out of bounds

        checkColRange(columnIndex);
        return colInfo[columnIndex].tableName;
    
public booleanisAutoIncrement(int columnIndex)
Retrieves whether a value stored in the designated column is automatically numbered, and thus readonly.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
return
true if the column is automatically numbered; false otherwise
throws
SQLException if a database access error occurs or the given column number is out of bounds

        checkColRange(columnIndex);
        return colInfo[columnIndex].autoIncrement;
    
public booleanisCaseSensitive(int columnIndex)
Indicates whether the case of the designated column's name matters.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
return
true if the column name is case sensitive; false otherwise
throws
SQLException if a database access error occurs or the given column number is out of bounds

        checkColRange(columnIndex);
        return colInfo[columnIndex].caseSensitive;
    
public booleanisCurrency(int columnIndex)
Indicates whether a value stored in the designated column is a cash value.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
return
true if a value in the designated column is a cash value; false otherwise
throws
SQLException if a database access error occurs or the given column number is out of bounds

        checkColRange(columnIndex);
        return colInfo[columnIndex].currency;
    
public booleanisDefinitelyWritable(int columnIndex)
Indicates whether a write operation on the designated column will definitely succeed.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
return
true if a write operation on the designated column will definitely succeed; false otherwise
throws
SQLException if a database access error occurs or the given column number is out of bounds

 return true;
public intisNullable(int columnIndex)
Retrieves a constant indicating whether it is possible to store a NULL value in the designated column.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
return
a constant from the ResultSetMetaData interface; either columnNoNulls, columnNullable, or columnNullableUnknown
throws
SQLException if a database access error occurs or the given column number is out of bounds

        checkColRange(columnIndex); 
        return colInfo[columnIndex].nullable;
    
public booleanisReadOnly(int columnIndex)
Indicates whether the designated column is definitely not writable, thus readonly.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
return
true if this RowSet object is read-Only and thus not updatable; false otherwise
throws
SQLException if a database access error occurs or the given column number is out of bounds

        checkColRange(columnIndex);
        return colInfo[columnIndex].readOnly;         
    
public booleanisSearchable(int columnIndex)
Indicates whether a value stored in the designated column can be used in a WHERE clause.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
return
true if a value in the designated column can be used in a WHERE clause; false otherwise
throws
SQLException if a database access error occurs or the given column number is out of bounds

        checkColRange(columnIndex);
        return colInfo[columnIndex].searchable;
    
public booleanisSigned(int columnIndex)
Indicates whether a value stored in the designated column is a signed number.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
return
true if if a value in the designated column is a signed number; false otherwise
throws
SQLException if a database access error occurs or the given column number is out of bounds

        checkColRange(columnIndex);
        return colInfo[columnIndex].signed;
    
public booleanisWritable(int columnIndex)
Indicates whether it is possible for a write operation on the designated column to succeed. A return value of true means that a write operation may or may not succeed.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
return
true if a write operation on the designated column may will succeed; false otherwise
throws
SQLException if a database access error occurs or the given column number is out of bounds

        checkColRange(columnIndex);
        return colInfo[columnIndex].writable;        
    
public voidsetAutoIncrement(int columnIndex, boolean property)
Sets whether the designated column is automatically numbered, thus read-only, to the given boolean value.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns in the rowset, inclusive
param
property true if the given column is automatically incremented; false otherwise
throws
SQLException if a database access error occurs or the given index is out of bounds

        checkColRange(columnIndex);
        colInfo[columnIndex].autoIncrement = property;
    
public voidsetCaseSensitive(int columnIndex, boolean property)
Sets whether the name of the designated column is case sensitive to the given boolean.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns in the rowset, inclusive
param
property true to indicate that the column name is case sensitive; false otherwise
throws
SQLException if a database access error occurs or the given column number is out of bounds

        checkColRange(columnIndex);
        colInfo[columnIndex].caseSensitive = property;
    
public voidsetCatalogName(int columnIndex, java.lang.String catalogName)
Sets the catalog name of the table from which the designated column was derived to catalogName. If catalogName is null, the catalog name is set to an empty string.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
param
catalogName the column's table's catalog name; if the catalogName is null, an empty String is set
throws
SQLException if a database access error occurs or the given column number is out of bounds

        checkColRange(columnIndex);
	if (catalogName != null)
	    colInfo[columnIndex].catName = new String(catalogName);
	else
	    colInfo[columnIndex].catName = new String("");
    
public voidsetColumnCount(int columnCount)
Sets to the given number the number of columns in the RowSet object for which this RowSetMetaDataImpl object was created.

param
columnCount an int giving the number of columns in the RowSet object
throws
SQLException if the given number is equal to or less than zero


        if (columnCount <= 0) {
            throw new SQLException("Invalid column count. Cannot be less " +
                "or equal to zero");
	    }
        
       colCount = columnCount;
       
       // If the colCount is Integer.MAX_VALUE,
       // we do not initialize the colInfo object.
       // even if we try to initialize the colCount with 
       // colCount = Integer.MAx_VALUE-1, the colInfo
       // initialization fails throwing an ERROR
       // OutOfMemory Exception. So we do not initialize
       // colInfo at Integer.MAX_VALUE. This is to pass TCK.
          
       if(!(colCount == Integer.MAX_VALUE)) {
	    colInfo = new ColInfo[colCount + 1];
           
           for (int i=1; i <= colCount; i++) {
                 colInfo[i] = new ColInfo();
           }
       }
       
        
    
public voidsetColumnDisplaySize(int columnIndex, int size)
Sets the normal maximum number of chars in the designated column to the given number.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
param
size the maximum size of the column in chars; must be 0 or more
throws
SQLException if a database access error occurs, the given column number is out of bounds, or size is less than 0

        
        if (size < 0) {
            throw new SQLException("Invalid column display size. Cannot be less " +
                "than zero");
	}        
        checkColRange(columnIndex); 
        colInfo[columnIndex].columnDisplaySize = size;
    
public voidsetColumnLabel(int columnIndex, java.lang.String label)
Sets the suggested column label for use in printouts and displays, if any, to label. If label is null, the column label is set to an empty string ("").

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
param
label the column label to be used in printouts and displays; if the column label is null, an empty String is set
throws
SQLException if a database access error occurs or the given column index is out of bounds

        checkColRange(columnIndex);
	if (label != null) {
	    colInfo[columnIndex].columnLabel = new String(label);
        } else {
	    colInfo[columnIndex].columnLabel = new String("");
        }
    
public voidsetColumnName(int columnIndex, java.lang.String columnName)
Sets the column name of the designated column to the given name.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
param
columnName a String object indicating the column name; if the given name is null, an empty String is set
throws
SQLException if a database access error occurs or the given column index is out of bounds

        checkColRange(columnIndex);        
        if (columnName != null) {
            colInfo[columnIndex].columnName = new String(columnName);
        } else {
            colInfo[columnIndex].columnName = new String("");
        }
    
public voidsetColumnType(int columnIndex, int SQLType)
Sets the SQL type code for values stored in the designated column to the given type code from the class java.sql.Types.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
param
SQLType the designated column's SQL type, which must be one of the constants in the class java.sql.Types
throws
SQLException if a database access error occurs, the given column number is out of bounds, or the column type specified is not one of the constants in java.sql.Types
see
java.sql.Types

                
        // examine java.sql.Type reflectively, loop on the fields and check
        // this. Separate out into a private method        
        checkColType(SQLType);
        checkColRange(columnIndex);
        colInfo[columnIndex].colType = SQLType;
    
public voidsetColumnTypeName(int columnIndex, java.lang.String typeName)
Sets the type name used by the data source for values stored in the designated column to the given type name.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
param
typeName the data source-specific type name; if typeName is null, an empty String is set
throws
SQLException if a database access error occurs or the given column number is out of bounds

        
        checkColRange(columnIndex);
        if (typeName != null) {
            colInfo[columnIndex].colTypeName = new String(typeName);
        } else {
            colInfo[columnIndex].colTypeName = new String("");
        }
    
public voidsetCurrency(int columnIndex, boolean property)
Sets whether a value stored in the designated column is a cash value to the given boolean.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive between 1 and the number of columns, inclusive
param
property true if the value is a cash value; false otherwise.
throws
SQLException if a database access error occurs or the given column number is out of bounds

        checkColRange(columnIndex);
        colInfo[columnIndex].currency = property;
    
public voidsetNullable(int columnIndex, int property)
Sets whether a value stored in the designated column can be set to NULL to the given constant from the interface ResultSetMetaData.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
param
property one of the following ResultSetMetaData constants: columnNoNulls, columnNullable, or columnNullableUnknown
throws
SQLException if a database access error occurs, the given column number is out of bounds, or the value supplied for the property parameter is not one of the following constants: ResultSetMetaData.columnNoNulls, ResultSetMetaData.columnNullable, or ResultSetMetaData.columnNullableUnknown

        if ((property < ResultSetMetaData.columnNoNulls) ||
            property > ResultSetMetaData.columnNullableUnknown) {
                throw new SQLException("Invalid nullable constant set. Must be " +
                    "either columnNoNulls, columnNullable or columnNullableUnknown");
        }
        checkColRange(columnIndex);
        colInfo[columnIndex].nullable = property;
    
public voidsetPrecision(int columnIndex, int precision)
Sets the total number of decimal digits in a value stored in the designated column to the given number.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
param
precision the total number of decimal digits; must be 0 or more
throws
SQLException if a database access error occurs, columnIndex is out of bounds, or precision is less than 0

                
        
        if (precision < 0) {
            throw new SQLException("Invalid precision value. Cannot be less " +
                "than zero");
	}            
        checkColRange(columnIndex);
        colInfo[columnIndex].colPrecision = precision;
    
public voidsetScale(int columnIndex, int scale)
Sets the number of digits to the right of the decimal point in a value stored in the designated column to the given number.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
param
scale the number of digits to the right of the decimal point; must be zero or greater
throws
SQLException if a database access error occurs, columnIndex is out of bounds, or scale is less than 0

        if (scale < 0) {
            throw new SQLException("Invalid scale size. Cannot be less " +
                "than zero");
	}            
        checkColRange(columnIndex);
        colInfo[columnIndex].colScale = scale;
    
public voidsetSchemaName(int columnIndex, java.lang.String schemaName)
Sets the designated column's table's schema name, if any, to schemaName. If schemaName is null, the schema name is set to an empty string ("").

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
param
schemaName the schema name for the table from which a value in the designated column was derived; may be an empty String or null
throws
SQLException if a database access error occurs or the given column number is out of bounds

        checkColRange(columnIndex);
	if (schemaName != null ) {
	    colInfo[columnIndex].schemaName = new String(schemaName);
	} else {
	    colInfo[columnIndex].schemaName = new String("");
	}
    
public voidsetSearchable(int columnIndex, boolean property)
Sets whether a value stored in the designated column can be used in a WHERE clause to the given boolean value.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns in the rowset, inclusive
param
property true to indicate that a column value can be used in a WHERE clause; false otherwise
throws
SQLException if a database access error occurs or the given column number is out of bounds

        checkColRange(columnIndex);
        colInfo[columnIndex].searchable = property;
    
public voidsetSigned(int columnIndex, boolean property)
Sets whether a value stored in the designated column is a signed number to the given boolean.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
param
property true to indicate that a column value is a signed number; false to indicate that it is not
throws
SQLException if a database access error occurs or the given column number is out of bounds

        checkColRange(columnIndex);
        colInfo[columnIndex].signed = property;
    
public voidsetTableName(int columnIndex, java.lang.String tableName)
Sets the name of the table from which the designated column was derived to the given table name.

param
columnIndex the first column is 1, the second is 2, and so on; must be between 1 and the number of columns, inclusive
param
tableName the column's table name; may be null or an empty string
throws
SQLException if a database access error occurs or the given column number is out of bounds

        checkColRange(columnIndex);
        if (tableName != null) {
            colInfo[columnIndex].tableName = new String(tableName);
        } else {
            colInfo[columnIndex].tableName = new String("");
        }