Search in sources :

Example 1 with Session

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

the class FileListEditor method init.

@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    // Configure the editor
    setSite(site);
    setInput(input);
    // Create the text editor
    editor = new TextEditor();
    editor.init(site, input);
    // Make sure we get notification that our editor is closing because
    // we may need to stop running queries
    getSite().getPage().addPartListener(new PartAdapter2() {

        /* (non-JavaDoc)
			 * @see net.sourceforge.sqlexplorer.util.PartAdapter2#partClosed(org.eclipse.ui.IWorkbenchPartReference)
			 */
        public void partClosed(IWorkbenchPartReference partRef) {
            if (partRef.getPart(false) == FileListEditor.this) {
                onCloseEditor();
            }
        }
    });
    // If we havn't got a view, then try for the current session in the ConnectionsView
    if (getSession() == null) {
        ConnectionsView view = SQLExplorerPlugin.getDefault().getConnectionsView();
        if (view != null) {
            User user = view.getDefaultUser();
            if (user != null)
                user.queueForNewSession(new SessionEstablishedAdapter() {

                    @Override
                    public void sessionEstablished(Session session) {
                        setSession(session);
                    }
                });
        }
    }
}
Also used : PartAdapter2(net.sourceforge.sqlexplorer.util.PartAdapter2) TextEditor(org.eclipse.ui.editors.text.TextEditor) User(net.sourceforge.sqlexplorer.dbproduct.User) ConnectionsView(net.sourceforge.sqlexplorer.connections.ConnectionsView) IWorkbenchPartReference(org.eclipse.ui.IWorkbenchPartReference) SessionEstablishedAdapter(net.sourceforge.sqlexplorer.connections.SessionEstablishedAdapter) Session(net.sourceforge.sqlexplorer.dbproduct.Session)

Example 2 with Session

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

the class OpenPasswordConnectDialogAction method run.

public void run() {
    SessionEstablishedListener listener = null;
    if (!user.hasAuthenticated())
        listener = new SessionEstablishedAdapter() {

            @Override
            public void sessionEstablished(Session session) {
                Display.getDefault().asyncExec(new Runnable() {

                    public void run() {
                        DatabaseStructureView dsView = SQLExplorerPlugin.getDefault().getDatabaseStructureView();
                        if (dsView != null)
                            try {
                                dsView.addUser(user);
                            } catch (SQLCannotConnectException e) {
                                MessageDialog.openError(Display.getDefault().getActiveShell(), "Cannot connect", e.getMessage());
                            }
                    }
                });
            }
        };
    ConnectionJob.createSession(alias, user, listener, alwaysPrompt);
}
Also used : SessionEstablishedListener(net.sourceforge.sqlexplorer.connections.SessionEstablishedListener) DatabaseStructureView(net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView) SessionEstablishedAdapter(net.sourceforge.sqlexplorer.connections.SessionEstablishedAdapter) Session(net.sourceforge.sqlexplorer.dbproduct.Session) SQLCannotConnectException(net.sourceforge.sqlexplorer.SQLCannotConnectException)

Example 3 with Session

use of net.sourceforge.sqlexplorer.dbproduct.Session 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 Session

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

the class CloseConnectionAction method run.

public void run() {
    boolean confirm = SQLExplorerPlugin.getDefault().getPluginPreferences().getBoolean(IConstants.CONFIRM_BOOL_CLOSE_CONNECTION);
    for (SQLConnection connection : getView().getSelectedConnections(false)) {
        Session session = connection.getSession();
        if (session != null && !session.isConnectionInUse()) {
            if (confirm) {
                MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(getView().getSite().getShell(), Messages.getString("ConnectionsView.Actions.CloseAll.Confirm.Title"), Messages.getString("ConnectionsView.Actions.CloseAll.Confirm.Message"), Messages.getString("ConnectionsView.Actions.CloseAll.Confirm.Toggle"), false, null, null);
                if (dialog.getToggleState() && dialog.getReturnCode() == IDialogConstants.YES_ID)
                    SQLExplorerPlugin.getDefault().getPluginPreferences().setValue(IConstants.CONFIRM_BOOL_CLOSE_CONNECTION, false);
                if (dialog.getReturnCode() != IDialogConstants.YES_ID)
                    return;
            }
            session.disposeConnection();
        } else if (session == null)
            connection.getUser().releaseFromPool(connection);
    }
    getView().refresh();
}
Also used : SQLConnection(net.sourceforge.sqlexplorer.dbproduct.SQLConnection) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) Session(net.sourceforge.sqlexplorer.dbproduct.Session)

Example 5 with Session

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

the class CloseAllConnectionsAction method run.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.IAction#run()
     */
public void run() {
    boolean confirm = SQLExplorerPlugin.getDefault().getPluginPreferences().getBoolean(IConstants.CONFIRM_BOOL_CLOSE_ALL_CONNECTIONS);
    if (confirm) {
        MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(getView().getSite().getShell(), Messages.getString("ConnectionsView.Actions.CloseAll.Confirm.Title"), Messages.getString("ConnectionsView.Actions.CloseAll.Confirm.Message"), Messages.getString("ConnectionsView.Actions.CloseAll.Confirm.Toggle"), false, null, null);
        if (dialog.getToggleState() && dialog.getReturnCode() == IDialogConstants.YES_ID)
            SQLExplorerPlugin.getDefault().getPluginPreferences().setValue(IConstants.CONFIRM_BOOL_CLOSE_ALL_CONNECTIONS, false);
        if (dialog.getReturnCode() != IDialogConstants.YES_ID)
            return;
    }
    Set<SQLConnection> connections = getView().getSelectedConnections(true);
    for (SQLConnection connection : connections) {
        synchronized (connection) {
            Session session = connection.getSession();
            if (session != null) {
                synchronized (session) {
                    if (!session.isConnectionInUse())
                        session.disposeConnection();
                }
            } else
                connection.getUser().releaseFromPool(connection);
        }
    }
    setEnabled(false);
    getView().refresh();
}
Also used : SQLConnection(net.sourceforge.sqlexplorer.dbproduct.SQLConnection) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) Session(net.sourceforge.sqlexplorer.dbproduct.Session)

Aggregations

Session (net.sourceforge.sqlexplorer.dbproduct.Session)10 SessionEstablishedAdapter (net.sourceforge.sqlexplorer.connections.SessionEstablishedAdapter)4 SQLConnection (net.sourceforge.sqlexplorer.dbproduct.SQLConnection)3 User (net.sourceforge.sqlexplorer.dbproduct.User)3 ConnectionsView (net.sourceforge.sqlexplorer.connections.ConnectionsView)2 Alias (net.sourceforge.sqlexplorer.dbproduct.Alias)2 ParserException (net.sourceforge.sqlexplorer.parsers.ParserException)2 QueryParser (net.sourceforge.sqlexplorer.parsers.QueryParser)2 DatabaseStructureView (net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView)2 PartAdapter2 (net.sourceforge.sqlexplorer.util.PartAdapter2)2 MessageDialogWithToggle (org.eclipse.jface.dialogs.MessageDialogWithToggle)2 IWorkbenchPartReference (org.eclipse.ui.IWorkbenchPartReference)2 FileEditorInput (org.eclipse.ui.part.FileEditorInput)2 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 SQLCannotConnectException (net.sourceforge.sqlexplorer.SQLCannotConnectException)1 SessionEstablishedListener (net.sourceforge.sqlexplorer.connections.SessionEstablishedListener)1 FilterStructureDialog (net.sourceforge.sqlexplorer.dialogs.FilterStructureDialog)1 AbstractSQLExecution (net.sourceforge.sqlexplorer.sqlpanel.AbstractSQLExecution)1