Package henplus

Examples of henplus.SQLSession


     * @throws SQLException
     * @throws IOException
     */
    private void connect(final String url, final String username, final String password) throws ClassNotFoundException,
            SQLException, IOException {
        SQLSession session;
        session = new SQLSession(url, username, password);
        _currentSessionName = createSessionName(session, null);
        _sessionManager.addSession(_currentSessionName, session);
        _knownUrls.put(url, url);
        _henplus.setPrompt(_currentSessionName + "> ");
        _sessionManager.setCurrentSession(session);
View Full Code Here


    /**
     * execute the command given.
     */
    @Override
    public int execute(final SQLSession currentSession, final String cmd, final String param) {
        SQLSession session = null;

        final StringTokenizer st = new StringTokenizer(param);
        final int argc = st.countTokens();

        if ("sessions".equals(cmd)) {
            showSessions();
            return SUCCESS;
        } else if ("connect".equals(cmd)) {
            if (argc < 1 || argc > 2) {
                return SYNTAX_ERROR;
            }
            String url = (String) st.nextElement();
            String alias = argc == 2 ? st.nextToken() : null;
            if (alias == null) {
                /*
                 * we only got one parameter. So the that single parameter might
                 * have been an alias. let's see..
                 */
                if (_knownUrls.containsKey(url)) {
                    final String possibleAlias = url;
                    url = _knownUrls.get(url);
                    if (!possibleAlias.equals(url)) {
                        alias = possibleAlias;
                    }
                }
            }
            try {
                session = new SQLSession(url, null, null);
                _knownUrls.put(url, url);
                if (alias != null) {
                    _knownUrls.put(alias, url);
                }
                _currentSessionName = createSessionName(session, alias);
View Full Code Here

        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();
    }
View Full Code Here

    /**
     * fixme: add this to the cached values determined by rehash.
     */
    public Collection<String> columnsFor(String tabName) {
        final SQLSession session = _henplus.getCurrentSession();
        final Set<String> result = new HashSet<String>();
        final Connection conn = session.getConnection(); // use createStmt
        ResultSet rset = null;

        String schema = null;
        final int schemaDelim = tabName.indexOf('.');
        if (schemaDelim > 0) {
View Full Code Here

        final NameCompleter completer = getTableCompleter(session);
        return completer.getAlternatives(partialTable);
    }

    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);
View Full Code Here

        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) {
View Full Code Here

                }
            };
        } else if (partialCommand.indexOf(OPTION_SINGLE_DB) != -1 && argIndex > 0) {

            final SessionManager sessionManager = HenPlus.getInstance().getSessionManager();
            final SQLSession session = sessionManager.getCurrentSession();

            final HashSet<String> alreadyGiven = new HashSet<String>();
            while (st.hasMoreElements()) {
                alreadyGiven.add(st.nextToken());
            }
            final ListUserObjectsCommand objectList = HenPlus.getInstance().getObjectLister();
            final Iterator<String> iter = objectList.completeTableName(session, lastWord);
            return new Iterator<String>() {

                String table = null;

                @Override
                public boolean hasNext() {
                    while (iter.hasNext()) {
                        table = iter.next();
                        if (alreadyGiven.contains(table) && !lastWord.equals(table)) {
                            continue;
                        }
                        return true;
                    }
                    return false;
                }

                @Override
                public String next() {
                    return table;
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException("no!");
                }
            };

        } else if (partialCommand.indexOf(OPTION_SINGLE_DB) == -1 && argIndex == 0) {
            // !singledb && process the first session
            return HenPlus.getInstance().getSessionManager().completeSessionName(lastWord);
        } else if (partialCommand.indexOf(OPTION_SINGLE_DB) == -1 && argIndex == 1) {
            // !singledb && process the second session
            final String firstSession = st.nextToken();
            return getSecondSessionCompleter(lastWord, firstSession);
        } else if (argIndex > 1) {
            // process tables
            final SessionManager sessionManager = HenPlus.getInstance().getSessionManager();
            final SQLSession first = sessionManager.getSessionByName(st.nextToken());
            final SQLSession second = sessionManager.getSessionByName(st.nextToken());

            final HashSet<String> alreadyGiven = new HashSet<String>();
            while (st.hasMoreElements()) {
                alreadyGiven.add(st.nextToken());
            }
View Full Code Here

TOP

Related Classes of henplus.SQLSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.