use of henplus.view.TableRenderer in project henplus by neurolabs.
the class ConnectCommand method showSessions.
private void showSessions() {
HenPlus.msg().println("current session is marked with '*'");
for (int i = 0; i < SESS_META.length; ++i) {
SESS_META[i].resetWidth();
}
final TableRenderer table = new TableRenderer(SESS_META, HenPlus.out());
for (String sessName : _sessionManager.getSessionNames()) {
final SQLSession session = _sessionManager.getSessionByName(sessName);
final String prepend = sessName.equals(_currentSessionName) ? " * " : " ";
final Column[] row = new Column[5];
row[0] = new Column(prepend + sessName);
row[1] = new Column(session.getUsername());
row[2] = new Column(session.getURL());
row[3] = new Column(TimeRenderer.renderTime(session.getUptime()));
row[4] = new Column(session.getStatementCount());
table.addRow(row);
}
table.closeTable();
}
use of henplus.view.TableRenderer in project henplus by neurolabs.
the class DriverCommand 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 ("list-drivers".equals(cmd)) {
if (argc == 0) {
HenPlus.msg().println("loaded drivers are marked with '*' (otherwise not found in CLASSPATH)");
DRV_META[0].resetWidth();
DRV_META[1].resetWidth();
DRV_META[2].resetWidth();
DRV_META[3].resetWidth();
final TableRenderer table = new TableRenderer(DRV_META, HenPlus.out());
for (Entry<String, DriverDescription> entry : _drivers.entrySet()) {
final Column[] row = new Column[4];
final DriverDescription desc = entry.getValue();
final String dbName = entry.getKey();
row[0] = new Column((desc.isLoaded() ? "* " : " ") + dbName);
row[1] = new Column(desc.getClassName());
row[2] = new Column(desc.getVersion());
row[3] = new Column(desc.getSampleURL());
table.addRow(row);
}
table.closeTable();
return SUCCESS;
} else {
return SYNTAX_ERROR;
}
} else if ("register".equals(cmd)) {
if (argc < 2 || argc > 3) {
return SYNTAX_ERROR;
}
final String shortname = (String) st.nextElement();
final String driverClass = (String) st.nextElement();
String sampleURL = null;
if (argc >= 3) {
sampleURL = (String) st.nextElement();
}
DriverDescription drv;
drv = new DriverDescription(driverClass, sampleURL);
if (!drv.isLoaded()) {
HenPlus.msg().println("cannot load driver class '" + driverClass + "'");
return EXEC_FAILED;
} else {
_drivers.put(shortname, drv);
}
} else if ("unregister".equals(cmd)) {
if (argc != 1) {
return SYNTAX_ERROR;
}
final String shortname = (String) st.nextElement();
if (!_drivers.containsKey(shortname)) {
HenPlus.msg().println("unknown driver for '" + shortname + "'");
return EXEC_FAILED;
} else {
_drivers.remove(shortname);
}
}
return SUCCESS;
}
use of henplus.view.TableRenderer in project henplus by neurolabs.
the class DumpCommand method printMetaDataInfo.
private void printMetaDataInfo(final MetaProperty[] prop) {
HenPlus.out().println();
META_HEADERS[0].resetWidth();
META_HEADERS[1].resetWidth();
final TableRenderer table = new TableRenderer(META_HEADERS, HenPlus.out());
for (int i = 0; i < prop.length; ++i) {
final Column[] row = new Column[3];
row[0] = new Column(prop[i].getFieldName());
row[1] = new Column(prop[i].getTypeName());
row[2] = new Column(prop[i].getMaxLength());
table.addRow(row);
}
table.closeTable();
}
use of henplus.view.TableRenderer 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.TableRenderer 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();
}
Aggregations