Search in sources :

Example 1 with PrimaryKey

use of henplus.sqlmodel.PrimaryKey in project henplus by neurolabs.

the class SQLMetaDataBuilder method getPrimaryKey.

private PrimaryKey getPrimaryKey(final DatabaseMetaData meta, final String tabName) throws SQLException {
    PrimaryKey result = null;
    final ResultSet rset = meta.getPrimaryKeys(null, null, tabName);
    if (rset != null) {
        result = new PrimaryKey();
        String pkname = null;
        while (rset.next()) {
            final String col = rset.getString(PK_DESC_COLUMN_NAME);
            pkname = rset.getString(PK_DESC_PK_NAME);
            final int pkseq = rset.getInt(PK_DESC_KEY_SEQ);
            result.addColumn(col, pkname, pkseq);
        }
        rset.close();
    }
    return result;
}
Also used : ResultSet(java.sql.ResultSet) PrimaryKey(henplus.sqlmodel.PrimaryKey)

Example 2 with PrimaryKey

use of henplus.sqlmodel.PrimaryKey in project henplus by neurolabs.

the class SQLMetaDataBuilder method buildTable.

private Table buildTable(final String catalog, final DatabaseMetaData meta, final String tableName, final ResultSet rset) throws SQLException {
    Table table = null;
    if (rset != null) {
        table = new Table(tableName);
        final PrimaryKey pk = getPrimaryKey(meta, tableName);
        final Map<String, ColumnFkInfo> fks = getForeignKeys(meta, tableName);
        // rset = meta.getColumns(catalog, null, tableName, null);
        while (!_interrupted && rset.next()) {
            final String colname = rset.getString(COLUMN_NAME);
            final Column column = new Column(colname);
            column.setType(rset.getString(TYPE_NAME));
            column.setSize(rset.getInt(COLUMN_SIZE));
            final boolean nullable = rset.getInt(NULLABLE) == DatabaseMetaData.columnNullable ? true : false;
            column.setNullable(nullable);
            final String defaultVal = rset.getString(COLUMN_DEF);
            column.setDefault(defaultVal != null ? defaultVal.trim() : null);
            column.setPosition(rset.getInt(ORDINAL_POSITION));
            column.setPkInfo(pk.getColumnPkInfo(colname));
            column.setFkInfo(fks.get(colname));
            table.addColumn(column);
        }
        rset.close();
    }
    return table;
}
Also used : Table(henplus.sqlmodel.Table) Column(henplus.sqlmodel.Column) ColumnFkInfo(henplus.sqlmodel.ColumnFkInfo) PrimaryKey(henplus.sqlmodel.PrimaryKey)

Aggregations

PrimaryKey (henplus.sqlmodel.PrimaryKey)2 Column (henplus.sqlmodel.Column)1 ColumnFkInfo (henplus.sqlmodel.ColumnFkInfo)1 Table (henplus.sqlmodel.Table)1 ResultSet (java.sql.ResultSet)1