Example usage for javax.sql.rowset RowSetMetaDataImpl setAutoIncrement

List of usage examples for javax.sql.rowset RowSetMetaDataImpl setAutoIncrement

Introduction

In this page you can find the example usage for javax.sql.rowset RowSetMetaDataImpl setAutoIncrement.

Prototype

public void setAutoIncrement(int columnIndex, boolean property) throws SQLException 

Source Link

Document

Sets whether the designated column is automatically numbered, thus read-only, to the given boolean value.

Usage

From source file:lasige.steeldb.jdbc.BFTRowSet.java

/**
 * Initializes the given <code>RowSetMetaData</code> object with the values
 * in the given <code>ResultSetMetaData</code> object.
 *
 * @param md the <code>RowSetMetaData</code> object for this
 *           <code>CachedRowSetImpl</code> object, which will be set with
 *           values from rsmd/*from   ww  w.  java  2  s. c o  m*/
 * @param rsmd the <code>ResultSetMetaData</code> object from which new
 *             values for md will be read
 * @throws SQLException if an error occurs
 */
private void initMetaData(RowSetMetaDataImpl md, ResultSetMetaData rsmd) throws SQLException {
    int numCols = rsmd.getColumnCount();

    md.setColumnCount(numCols);
    for (int col = 1; col <= numCols; col++) {
        md.setAutoIncrement(col, rsmd.isAutoIncrement(col));
        if (rsmd.isAutoIncrement(col))
            updateOnInsert = true;
        md.setCaseSensitive(col, false);
        md.setCurrency(col, false);
        md.setNullable(col, rsmd.isNullable(col));
        md.setSigned(col, rsmd.isSigned(col));
        md.setSearchable(col, false);
        /*
         * The PostgreSQL drivers sometimes return negative columnDisplaySize,
         * which causes an exception to be thrown.  Check for it.
         */
        int size = rsmd.getColumnDisplaySize(col);
        if (size < 0) {
            size = 0;
        }
        md.setColumnDisplaySize(col, 0);

        if (StringUtils.isNotBlank(rsmd.getColumnLabel(col))) {
            md.setColumnLabel(col, rsmd.getColumnLabel(col).toLowerCase());
        }

        if (StringUtils.isNotBlank(rsmd.getColumnName(col))) {
            md.setColumnName(col, rsmd.getColumnName(col).toLowerCase());
        }

        md.setSchemaName(col, null);
        /*
         * Drivers return some strange values for precision, for non-numeric data, including reports of
         * non-integer values; maybe we should check type, & set to 0 for non-numeric types.
         */
        int precision = rsmd.getPrecision(col);
        if (precision < 0) {
            precision = 0;
        }
        md.setPrecision(col, 0);

        /*
         * It seems, from a bug report, that a driver can sometimes return a negative
         * value for scale.  javax.sql.rowset.RowSetMetaDataImpl will throw an exception
         * if we attempt to set a negative value.  As such, we'll check for this case.
         */
        int scale = rsmd.getScale(col);
        if (scale < 0) {
            scale = 0;
        }
        md.setScale(col, 0);
        md.setTableName(col, null);
        md.setCatalogName(col, null);
        md.setColumnType(col, -1);
        md.setColumnTypeName(col, null);
    }

    if (conn != null) {
        // JDBC 4.0 mandates as does the Java EE spec that all DataBaseMetaData methods
        // must be implemented, therefore, the previous fix for 5055528 is being backed out
        dbmslocatorsUpdateCopy = conn.getMetaData().locatorsUpdateCopy();
    }
}