Search in sources :

Example 1 with Alias

use of net.sourceforge.sqlexplorer.dbproduct.Alias in project tdq-studio-se by Talend.

the class SQLHistory method loadFromFileV300.

/**
 * Load the sql history from previous sessions.
 */
private void loadFromFileV300() {
    try {
        File file = new File(ApplicationFiles.SQLHISTORY_FILE_NAME_V300);
        if (!file.exists()) {
            return;
        }
        BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
        String currentLine = reader.readLine();
        while (currentLine != null) {
            if (currentLine.trim().length() != 0) {
                String sessionHint = null;
                String query = null;
                String time = null;
                String executions = null;
                int pos = currentLine.indexOf(SESSION_HINT_MARKER);
                if (pos != -1) {
                    // split line in session and query
                    sessionHint = currentLine.substring(0, pos);
                    currentLine = currentLine.substring(pos + SESSION_HINT_MARKER.length());
                    int posT = currentLine.indexOf(TIME_HINT_MARKER);
                    if (posT != -1) {
                        // split line in session and query
                        query = currentLine.substring(0, posT);
                        currentLine = currentLine.substring(posT + TIME_HINT_MARKER.length());
                        int posE = currentLine.indexOf(EXECUTION_HINT_MARKER);
                        time = currentLine.substring(0, posE);
                        executions = currentLine.substring(posE + EXECUTION_HINT_MARKER.length());
                    } else {
                        query = currentLine;
                    }
                    // clean up query
                    query = query.replaceAll(NEWLINE_REPLACEMENT, NEWLINE_SEPARATOR);
                    query = query.replaceAll(TAB_REPLACEMENT, " ");
                }
                if (query != null && query.trim().length() != 0) {
                    Alias alias = SQLExplorerPlugin.getDefault().getAliasManager().getAlias(sessionHint);
                    _history.add(new SQLHistoryElement(query, alias.getDefaultUser(), time, executions));
                }
            }
            currentLine = reader.readLine();
        }
        reader.close();
    } catch (Exception e) {
        SQLExplorerPlugin.error("Couldn't load sql history.", e);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Alias(net.sourceforge.sqlexplorer.dbproduct.Alias) BufferedReader(java.io.BufferedReader) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) DocumentException(org.dom4j.DocumentException)

Example 2 with Alias

use of net.sourceforge.sqlexplorer.dbproduct.Alias in project tdq-studio-se by Talend.

the class ConnectionTreeActionGroup method fillContextMenu.

/**
 * Fill the node context menu with all the correct actions.
 *
 * @see org.eclipse.ui.actions.ActionGroup#fillContextMenu(org.eclipse.jface.action.IMenuManager)
 */
public void fillContextMenu(IMenuManager menu) {
    ConnectionsView view = SQLExplorerPlugin.getDefault().getConnectionsView();
    Object[] selection = (view == null) ? null : view.getSelected();
    // If nothing is selected, then show the default ones
    if (selection == null || selection.length != 1) {
        // addAction(menu, new CloseAllConnectionsAction());
        return;
    }
    if (selection[0] instanceof Alias) {
        Alias alias = (Alias) selection[0];
        addAction(menu, new NewEditorAction());
        addAction(menu, new NewDatabaseStructureViewAction());
        addAction(menu, new ConnectAliasAction());
        menu.add(new Separator());
        for (User user : alias.getUsers()) if (!user.isAutoCommit()) {
            addAction(menu, new CommitAction());
            addAction(menu, new RollbackAction());
            menu.add(new Separator());
            break;
        }
    // addAction(menu, new NewUserAction());
    // addAction(menu, new ChangeAliasAction());
    // addAction(menu, new CopyAliasAction());
    // addAction(menu, new DeleteAction());
    } else if (selection[0] instanceof User) {
        User user = (User) selection[0];
        addAction(menu, new NewEditorAction());
        addAction(menu, new NewDatabaseStructureViewAction());
        addAction(menu, new ConnectAliasAction());
        menu.add(new Separator());
        if (!user.isAutoCommit()) {
            addAction(menu, new CommitAction());
            addAction(menu, new RollbackAction());
            menu.add(new Separator());
        }
    // addAction(menu, new NewUserAction());
    // addAction(menu, new EditUserAction());
    // addAction(menu, new CopyUserAction());
    // addAction(menu, new DeleteAction());
    } else if (selection[0] instanceof SQLConnection) {
        SQLConnection connection = (SQLConnection) selection[0];
        addAction(menu, new NewEditorAction());
        addAction(menu, new NewDatabaseStructureViewAction());
        menu.add(new Separator());
        if (!connection.getUser().isAutoCommit()) {
            addAction(menu, new CommitAction());
            addAction(menu, new RollbackAction());
            menu.add(new Separator());
        }
    // addAction(menu, new CloseConnectionAction());
    }
}
Also used : User(net.sourceforge.sqlexplorer.dbproduct.User) NewDatabaseStructureViewAction(net.sourceforge.sqlexplorer.connections.actions.NewDatabaseStructureViewAction) Alias(net.sourceforge.sqlexplorer.dbproduct.Alias) SQLConnection(net.sourceforge.sqlexplorer.dbproduct.SQLConnection) NewEditorAction(net.sourceforge.sqlexplorer.connections.actions.NewEditorAction) ConnectAliasAction(net.sourceforge.sqlexplorer.connections.actions.ConnectAliasAction) RollbackAction(net.sourceforge.sqlexplorer.connections.actions.RollbackAction) Separator(org.eclipse.jface.action.Separator) CommitAction(net.sourceforge.sqlexplorer.connections.actions.CommitAction)

Example 3 with Alias

use of net.sourceforge.sqlexplorer.dbproduct.Alias in project tdq-studio-se by Talend.

the class ConnectionsView method getDefaultAlias.

private Alias getDefaultAlias() {
    IStructuredSelection selection = (IStructuredSelection) _treeViewer.getSelection();
    if (selection == null) {
        return null;
    }
    Object element = selection.getFirstElement();
    if (element instanceof Alias) {
        return (Alias) element;
    } else if (element instanceof Session) {
        ITreeContentProvider provider = (ITreeContentProvider) _treeViewer.getContentProvider();
        return (Alias) provider.getParent(element);
    }
    return null;
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) Alias(net.sourceforge.sqlexplorer.dbproduct.Alias) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Session(net.sourceforge.sqlexplorer.dbproduct.Session)

Example 4 with Alias

use of net.sourceforge.sqlexplorer.dbproduct.Alias in project tdq-studio-se by Talend.

the class ConnectionsView method getSelectedAliases.

/**
 * Returns a list of the selected Aliases. If recurse is true then the result will include any aliases associated
 * with other objects; eg, if a connection is selected and recurse is true, then the connection's alias will also be
 * returned
 *
 * @param recurse
 * @return Set of Aliases, never returns null
 */
public Set<Alias> getSelectedAliases(boolean recurse) {
    IStructuredSelection selection = (IStructuredSelection) _treeViewer.getSelection();
    if (selection == null) {
        return EMPTY_ALIASES;
    }
    LinkedHashSet<Alias> result = new LinkedHashSet<Alias>();
    Iterator iter = selection.iterator();
    while (iter.hasNext()) {
        Object obj = iter.next();
        if (obj instanceof Alias) {
            result.add((Alias) obj);
        } else if (recurse) {
            if (obj instanceof User) {
                User user = (User) obj;
                result.add(user.getAlias());
            } else if (obj instanceof SQLConnection) {
                SQLConnection connection = (SQLConnection) obj;
                result.add(connection.getUser().getAlias());
            }
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) User(net.sourceforge.sqlexplorer.dbproduct.User) Alias(net.sourceforge.sqlexplorer.dbproduct.Alias) SQLConnection(net.sourceforge.sqlexplorer.dbproduct.SQLConnection) Iterator(java.util.Iterator) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 5 with Alias

use of net.sourceforge.sqlexplorer.dbproduct.Alias in project tdq-studio-se by Talend.

the class ConnectionsView method getSelectedConnections.

/**
 * Returns a list of selected sessions; if recurse is true, then it includes indirectly selected sessions (eg a
 * selected user's sessions)
 *
 * @param recurse
 * @return Set of Sessions, never returns null
 */
public Set<SQLConnection> getSelectedConnections(boolean recurse) {
    IStructuredSelection selection = (IStructuredSelection) _treeViewer.getSelection();
    if (selection == null) {
        return EMPTY_CONNECTIONS;
    }
    LinkedHashSet<SQLConnection> result = new LinkedHashSet<SQLConnection>();
    Iterator iter = selection.iterator();
    while (iter.hasNext()) {
        Object obj = iter.next();
        if (obj instanceof SQLConnection) {
            result.add((SQLConnection) obj);
        } else if (recurse) {
            if (obj instanceof Alias) {
                Alias alias = (Alias) obj;
                for (User user : alias.getUsers()) {
                    result.addAll(user.getConnections());
                }
            } else if (obj instanceof User) {
                User user = (User) obj;
                result.addAll(user.getConnections());
            }
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) User(net.sourceforge.sqlexplorer.dbproduct.User) Alias(net.sourceforge.sqlexplorer.dbproduct.Alias) SQLConnection(net.sourceforge.sqlexplorer.dbproduct.SQLConnection) Iterator(java.util.Iterator) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Aggregations

Alias (net.sourceforge.sqlexplorer.dbproduct.Alias)27 User (net.sourceforge.sqlexplorer.dbproduct.User)14 SQLConnection (net.sourceforge.sqlexplorer.dbproduct.SQLConnection)6 AliasManager (net.sourceforge.sqlexplorer.dbproduct.AliasManager)5 DatabaseStructureView (net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 SQLExplorerPlugin (net.sourceforge.sqlexplorer.plugin.SQLExplorerPlugin)4 PartInitException (org.eclipse.ui.PartInitException)4 Iterator (java.util.Iterator)3 LinkedHashSet (java.util.LinkedHashSet)3 CreateAliasDlg (net.sourceforge.sqlexplorer.dialogs.CreateAliasDlg)3 MalformedURLException (java.net.MalformedURLException)2 SQLCannotConnectException (net.sourceforge.sqlexplorer.SQLCannotConnectException)2 Session (net.sourceforge.sqlexplorer.dbproduct.Session)2 OpenPasswordConnectDialogAction (net.sourceforge.sqlexplorer.plugin.actions.OpenPasswordConnectDialogAction)2 SQLEditor (net.sourceforge.sqlexplorer.plugin.editors.SQLEditor)2 SQLEditorInput (net.sourceforge.sqlexplorer.plugin.editors.SQLEditorInput)2 Menu (org.eclipse.swt.widgets.Menu)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1