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;
}
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;
}
Aggregations