use of henplus.view.Column in project henplus by neurolabs.
the class ResultSetRenderer method execute.
public int execute() throws SQLException {
int rows = 0;
_running = true;
try {
while (_running && _rset.next()) {
final Column[] currentRow = new Column[_columns];
for (int i = 0; i < _columns; ++i) {
final int col = _showColumns != null ? _showColumns[i] : i + 1;
String colString;
switch(_meta.getColumnType(col)) {
case Types.CLOB:
colString = readClob(_rset.getClob(col));
break;
case Types.BIT:
case Types.BOOLEAN:
colString = _rset.getObject(col) == null ? null : Boolean.toString(_rset.getBoolean(col));
break;
default:
colString = _rset.getString(col);
break;
}
final Column thisCol = new Column(colString);
currentRow[i] = thisCol;
}
if (_firstRowTime < 0) {
// read first row completely.
_firstRowTime = System.currentTimeMillis();
}
_table.addRow(currentRow);
++rows;
if (rows >= _rowLimit) {
_beyondLimit = true;
break;
}
}
_table.closeTable();
if (!_running) {
try {
_rset.getStatement().cancel();
} catch (final Exception e) {
HenPlus.msg().println("cancel statement failed: " + e.getMessage());
}
}
} finally {
_rset.close();
}
return rows;
}
use of henplus.view.Column in project henplus by neurolabs.
the class SetCommand method execute.
/**
* execute the command given.
*/
@Override
public int execute(final SQLSession currentSession, final String cmd, final String param) {
final StringTokenizer st = new StringTokenizer(param);
final int argc = st.countTokens();
if ("set-var".equals(cmd)) {
/*
* no args. only show.
*/
if (argc == 0) {
SET_META[0].resetWidth();
SET_META[1].resetWidth();
final TableRenderer table = new TableRenderer(SET_META, HenPlus.out());
for (Entry<String, String> entry : _variables.entrySet()) {
final Column[] row = new Column[4];
row[0] = new Column(entry.getKey());
row[1] = new Column(entry.getValue());
// row[2] = new Column("");
// row[3] = new Column("X");
table.addRow(row);
}
table.closeTable();
return SUCCESS;
} else if (argc >= 2) {
/*
* more than one arg
*/
final String varname = (String) st.nextElement();
int pos = 0;
final int paramLength = param.length();
// skip whitespace after 'set'
while (pos < paramLength && Character.isWhitespace(param.charAt(pos))) {
++pos;
}
// skip non-whitespace after 'set ': variable name
while (pos < paramLength && !Character.isWhitespace(param.charAt(pos))) {
++pos;
}
// skip whitespace before vlue..
while (pos < paramLength && Character.isWhitespace(param.charAt(pos))) {
++pos;
}
String value = param.substring(pos);
if (value.startsWith("\"") && value.endsWith("\"")) {
value = value.substring(1, value.length() - 1);
} else if (value.startsWith("\'") && value.endsWith("\'")) {
value = value.substring(1, value.length() - 1);
}
setVariable(varname, value);
return SUCCESS;
}
return SYNTAX_ERROR;
} else if ("unset-var".equals(cmd)) {
if (argc >= 1) {
while (st.hasMoreElements()) {
final String varname = (String) st.nextElement();
if (!_variables.containsKey(varname)) {
HenPlus.msg().println("unknown variable '" + varname + "'");
} else {
_variables.remove(varname);
}
}
return SUCCESS;
}
return SYNTAX_ERROR;
} else if ("unset-all".equals(cmd)) {
if (argc == 0) {
_variables.clear();
} else {
return SYNTAX_ERROR;
}
}
return SUCCESS;
}
use of henplus.view.Column in project henplus by neurolabs.
the class SystemInfoCommand method renderInfo.
// ================== rendering ================
private void renderInfo(final Map<String, String> info) {
final TableRenderer table = new TableRenderer(DESC_META, HenPlus.out());
for (Entry<String, String> entry : info.entrySet()) {
final String key = entry.getKey();
final String value = entry.getValue();
final Column[] row = new Column[2];
row[0] = new Column(key);
// don't call toString() on the value as it might be null
row[1] = new Column(value);
table.addRow(row);
}
table.closeTable();
}
use of henplus.view.Column in project henplus by neurolabs.
the class ResultTablePrinter method appendModified.
private static void appendModified(final List<Column[]> rows, final LinkedHashMap<henplus.sqlmodel.Column, henplus.sqlmodel.Column> modified) {
final Iterator<henplus.sqlmodel.Column> iter = modified.keySet().iterator();
while (iter.hasNext()) {
final henplus.sqlmodel.Column org = iter.next();
final henplus.sqlmodel.Column mod = modified.get(org);
final ExtendedColumn[] orgView = new ExtendedColumn[8];
final ExtendedColumn[] modView = new ExtendedColumn[8];
orgView[0] = new ExtendedColumn(STAT_MODIFIED_ORG, DESC_META[0].getAlignment());
modView[0] = new ExtendedColumn(STAT_MODIFIED_NEW, DESC_META[0].getAlignment());
// if this was modified it doesn't matter
orgView[1] = new ExtendedColumn(org.getPosition(), DESC_META[1].getAlignment());
modView[1] = new ExtendedColumn(mod.getPosition(), DESC_META[1].getAlignment());
// this should not differ
orgView[2] = new ExtendedColumn(org.getName(), DESC_META[2].getAlignment());
modView[2] = new ExtendedColumn(mod.getName(), DESC_META[2].getAlignment());
final String orgType = extractType(org);
final String modType = extractType(mod);
orgView[3] = new ExtendedColumn(orgType, DESC_META[3].getAlignment());
modView[3] = new ExtendedColumn(modType, DESC_META[3].getAlignment());
if (!modType.equals(orgType)) {
markAsChanged(modView[3]);
}
orgView[4] = new ExtendedColumn(org.isNullable() ? YES : NO, DESC_META[4].getAlignment());
modView[4] = new ExtendedColumn(mod.isNullable() ? YES : NO, DESC_META[4].getAlignment());
if (org.isNullable() != mod.isNullable()) {
markAsChanged(modView[4]);
}
Logger.debug("default: %s", org.getDefault());
final String orgDefaultVal = org.getDefault() != null ? org.getDefault().trim() : null;
// oracle appends newline to default values for some reason.
orgView[5] = new ExtendedColumn(orgDefaultVal, DESC_META[5].getAlignment());
final String modDefaultVal = mod.getDefault() != null ? mod.getDefault().trim() : null;
modView[5] = new ExtendedColumn(modDefaultVal, DESC_META[5].getAlignment());
if (orgDefaultVal != null && !orgDefaultVal.equals(modDefaultVal) || orgDefaultVal == null && modDefaultVal != null) {
markAsChanged(modView[5]);
}
// primary key
final String pkDescOrg = getPkDesc(org);
final String pkDescMod = getPkDesc(mod);
orgView[6] = new ExtendedColumn(pkDescOrg, DESC_META[6].getAlignment());
modView[6] = new ExtendedColumn(pkDescMod, DESC_META[6].getAlignment());
// check if one of the cols has to be marked as changed
if (org.isPartOfPk() && !mod.isPartOfPk()) {
markAsChanged(orgView[6]);
} else if (!org.isPartOfPk() && mod.isPartOfPk()) {
markAsChanged(modView[6]);
} else if (org.isPartOfPk() && mod.isPartOfPk()) {
// compare values of pk names
if (org.getPkInfo().getPkName() != null && !org.getPkInfo().getPkName().equals(mod.getPkInfo().getPkName())) {
markAsChanged(modView[6]);
}
}
// foreign key
final String fkDescOrg = getFkDesc(org);
final String fkDescMod = getFkDesc(mod);
orgView[7] = new ExtendedColumn(fkDescOrg, DESC_META[7].getAlignment());
modView[7] = new ExtendedColumn(fkDescMod, DESC_META[7].getAlignment());
// check if one of the cols has to be marked as changed
if (org.isForeignKey() && !mod.isForeignKey()) {
markAsChanged(orgView[7]);
} else if (!org.isForeignKey() && mod.isForeignKey()) {
markAsChanged(modView[7]);
} else if (org.isForeignKey() && mod.isForeignKey()) {
// compare values of pk names
if (!org.getFkInfo().equals(mod.getFkInfo())) {
markAsChanged(modView[7]);
}
}
rows.add(orgView);
rows.add(modView);
}
}
Aggregations