use of henplus.view.util.NameCompleter in project henplus by neurolabs.
the class ListUserObjectsCommand method completeAllColumns.
public Iterator<String> completeAllColumns(final String partialColumn) {
final SQLSession session = _henplus.getCurrentSession();
if (session == null) {
return null;
}
final NameCompleter completer = getAllColumnsCompleter(session);
return completer.getAlternatives(partialColumn);
}
use of henplus.view.util.NameCompleter in project henplus by neurolabs.
the class SessionManager method completeSessionName.
/* ===================== Helper methods ====================== */
/**
* Used from several commands that need session name completion.
*/
public Iterator<String> completeSessionName(final String partialSession) {
Iterator<String> result = null;
if (_sessions != null) {
final NameCompleter completer = new NameCompleter(getSessionNames());
Logger.debug("[SessionManager.completeSessionName] created completer for sessionnames '%s'", getSessionNames().toString());
result = completer.getAlternatives(partialSession);
}
return result;
}
use of henplus.view.util.NameCompleter in project henplus by neurolabs.
the class TableDiffCommand method executeDoubleDb.
private int executeDoubleDb(final StringTokenizer st, final boolean colNameIgnoreCase) {
if (st.countTokens() < 3) {
return SYNTAX_ERROR;
}
final SessionManager sessionManager = HenPlus.getInstance().getSessionManager();
if (sessionManager.getSessionCount() < 2) {
Logger.error("You need two valid sessions for this command.");
return SYNTAX_ERROR;
}
final SQLSession first = sessionManager.getSessionByName(st.nextToken());
final SQLSession second = sessionManager.getSessionByName(st.nextToken());
if (first == null || second == null) {
Logger.error("You need two valid sessions for this command.");
return EXEC_FAILED;
} else if (first == second) {
Logger.error("You should specify two different sessions for this command.");
return EXEC_FAILED;
} else if (!st.hasMoreTokens()) {
Logger.error("You should specify at least one table.");
return EXEC_FAILED;
}
try {
final long start = System.currentTimeMillis();
int count = 0;
final ListUserObjectsCommand objectLister = HenPlus.getInstance().getObjectLister();
final SortedSet<String> tablesOne = objectLister.getTableNamesForSession(first);
final SortedSet<String> tablesTwo = objectLister.getTableNamesForSession(second);
// which tables got already
final Set<String> alreadyDiffed = new HashSet<String>();
// diffed?
/*
* which tables are found in the first session via wildcards but are
* not contained in the second session?
*/
final ArrayList<String> missedFromWildcards = new ArrayList<String>();
while (st.hasMoreTokens()) {
final String nextToken = st.nextToken();
if ("*".equals(nextToken) || nextToken.indexOf('*') > -1) {
Iterator<String> iter = null;
if ("*".equals(nextToken)) {
iter = objectLister.getTableNamesIteratorForSession(first);
} else if (nextToken.indexOf('*') > -1) {
final String tablePrefix = nextToken.substring(0, nextToken.length() - 1);
final NameCompleter compl = new NameCompleter(tablesOne);
iter = compl.getAlternatives(tablePrefix);
}
while (iter.hasNext()) {
final String objTableName = iter.next();
count = diffConditionally(objTableName, colNameIgnoreCase, first, second, tablesTwo, alreadyDiffed, missedFromWildcards, count);
}
} else if (!alreadyDiffed.contains(nextToken)) {
diffTable(first, second, nextToken, colNameIgnoreCase);
alreadyDiffed.add(nextToken);
count++;
}
}
final StringBuilder msg = new StringBuilder();
msg.append("Diffing ").append(count).append(count == 1 ? " table took " : " tables took ").append(System.currentTimeMillis() - start).append(" ms.");
// the user know this.
if (missedFromWildcards.size() > 0) {
msg.append("\nTables which matched a given wildcard in your first\n" + "session but were not found in your second session:\n");
for (String missed : missedFromWildcards) {
msg.append(missed).append(", ");
}
// remove the last two chars
msg.delete(msg.length() - 2, msg.length());
}
Logger.info(msg.toString());
} catch (final Exception e) {
e.printStackTrace();
}
return SUCCESS;
}
Aggregations