use of henplus.sqlmodel.Column 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;
}
use of henplus.sqlmodel.Column in project henplus by neurolabs.
the class TableDiffCommand method getMockResult.
/* leave this for testing */
private TableDiffResult getMockResult() {
final TableDiffResult result = new TableDiffResult();
final Column added = new Column("colname");
added.setDefault("nix");
added.setNullable(true);
added.setPosition(23);
added.setSize(666);
added.setType("myType");
result.addAddedColumn(added);
final Column removed = new Column("wech");
removed.setDefault("nix");
removed.setNullable(true);
removed.setPosition(23);
removed.setSize(666);
removed.setType("myType");
result.addRemovedColumn(removed);
final Column modOrg = new Column("orischinall");
modOrg.setDefault("orgding");
modOrg.setNullable(true);
modOrg.setPosition(23);
modOrg.setSize(666);
modOrg.setType("myType");
final Column modNew = new Column("moddifaied");
modNew.setDefault("modding");
modNew.setNullable(false);
modNew.setPosition(42);
modNew.setSize(999);
modNew.setType("myType");
result.putModifiedColumns(modOrg, modNew);
return result;
}
use of henplus.sqlmodel.Column in project henplus by neurolabs.
the class TableDiffer method diffTables.
/**
* Compares two tables by their columns.
*
* @param referenceTable
* @param diffTable
* @param colNameIgnoreCase
* specifies if column names shall be compared in a case insensitive way.
* @return An instance of <code>TableDiffResult</code> if their are differences between the tables, otherwise <code>null</code>.
*/
public static TableDiffResult diffTables(final Table referenceTable, final Table diffTable, final boolean colNameIgnoreCase) {
TableDiffResult result = null;
if (referenceTable != null && diffTable != null) {
result = new TableDiffResult();
// first check for all columns of the reference table
final Iterator<Column> refIter = referenceTable.getColumnIterator();
if (refIter != null) {
while (refIter.hasNext()) {
final Column col = refIter.next();
Logger.debug("[TableDiffer.diffTables] querying table for '%s'", col.getName());
final Column diff = diffTable.getColumnByName(col.getName(), colNameIgnoreCase);
Logger.debug("[TableDiffer.diffTables] got: '%s'", diff);
if (diff == null) {
Logger.debug("missing col: '%s'", col.getName());
result.addRemovedColumn(col);
} else if (!col.equals(diff, colNameIgnoreCase)) {
Logger.debug("modified col: '%s'", col.getName());
result.putModifiedColumns(col, diff);
}
}
}
// now check for columns which were added to the second table
final Iterator<Column> diffIter = diffTable.getColumnIterator();
if (diffIter != null) {
while (diffIter.hasNext()) {
final Column col = diffIter.next();
final Column ref = referenceTable.getColumnByName(col.getName(), colNameIgnoreCase);
if (ref == null) {
Logger.debug("added col: '%s'", col.getName());
result.addAddedColumn(col);
}
}
}
result = result.hasDiffs() ? result : null;
}
return result;
}
Aggregations