Search in sources :

Example 6 with NameCompleter

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);
}
Also used : SQLSession(henplus.SQLSession) NameCompleter(henplus.view.util.NameCompleter)

Example 7 with NameCompleter

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;
}
Also used : NameCompleter(henplus.view.util.NameCompleter)

Example 8 with NameCompleter

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;
}
Also used : SessionManager(henplus.SessionManager) NameCompleter(henplus.view.util.NameCompleter) ArrayList(java.util.ArrayList) ListUserObjectsCommand(henplus.commands.ListUserObjectsCommand) SQLSession(henplus.SQLSession) HashSet(java.util.HashSet)

Aggregations

NameCompleter (henplus.view.util.NameCompleter)8 HashSet (java.util.HashSet)4 SQLSession (henplus.SQLSession)2 ResultSet (java.sql.ResultSet)2 LinkedHashSet (java.util.LinkedHashSet)2 StringTokenizer (java.util.StringTokenizer)2 SQLMetaData (henplus.SQLMetaData)1 SQLMetaDataBuilder (henplus.SQLMetaDataBuilder)1 SessionManager (henplus.SessionManager)1 ListUserObjectsCommand (henplus.commands.ListUserObjectsCommand)1 Table (henplus.sqlmodel.Table)1 DependencyResolver (henplus.util.DependencyResolver)1 ResolverResult (henplus.util.DependencyResolver.ResolverResult)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 Connection (java.sql.Connection)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1