Search in sources :

Example 1 with ConnectionsView

use of net.sourceforge.sqlexplorer.connections.ConnectionsView 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 ConnectionsView

use of net.sourceforge.sqlexplorer.connections.ConnectionsView in project tdq-studio-se by Talend.

the class Session method setAutoCommit.

public synchronized void setAutoCommit(boolean autoCommit) throws SQLException {
    boolean enabling = !this.autoCommit && autoCommit;
    this.autoCommit = autoCommit;
    // If we're turning it on, get rid of any existing connection back to the pool
    if (enabling) {
        // If there's a connection but its not in use, then release it
        if (connection != null && !connectionInUse) {
            try {
                user.releaseConnection(connection);
                internalSetConnection(null);
                ConnectionsView connectionsView = SQLExplorerPlugin.getDefault().getConnectionsView();
                if (connectionsView != null) {
                    connectionsView.refresh();
                }
            } catch (SQLException e) {
                SQLExplorerPlugin.error("Cannot release connection", e);
            }
        }
    }
}
Also used : ConnectionsView(net.sourceforge.sqlexplorer.connections.ConnectionsView) SQLException(java.sql.SQLException)

Example 3 with ConnectionsView

use of net.sourceforge.sqlexplorer.connections.ConnectionsView in project tdq-studio-se by Talend.

the class Session method releaseConnection.

/**
 * Releases the connection; if the connection does NOT have auto-commit, this session will hang on to it for next
 * time, otherwise it is returned to the pool
 *
 * @param toRelease
 */
public synchronized void releaseConnection(SQLConnection toRelease) {
    if (!connectionInUse) {
        throw new IllegalStateException("Cannot release connection - not inuse");
    }
    if (connection != toRelease) {
        // User will be null if we've closed
        if (user == null) {
            return;
        }
        throw new IllegalArgumentException("Attempt to release the wrong connection");
    }
    // Run any queued tasks
    try {
        while (!queuedTasks.isEmpty()) {
            QueuedTask task = queuedTasks.removeFirst();
            task.run();
        }
    } catch (SQLException e) {
        SQLExplorerPlugin.error("Failed running queued task", e);
    }
    connectionInUse = false;
    try {
        // Update the connection to the auto-commit and commit-on-close status
        connection.setAutoCommit(autoCommit);
        connection.setCommitOnClose(commitOnClose);
        // If it's not auto-commit, then we have to keep the connection
        if (!autoCommit || keepConnection) {
            return;
        }
    } catch (SQLException e) {
        SQLExplorerPlugin.error("Cannot commit", e);
    }
    // Give it back into the pool
    try {
        user.releaseConnection(connection);
        internalSetConnection(null);
    } catch (SQLException e) {
        SQLExplorerPlugin.error("Cannot release connection", e);
    }
    ConnectionsView connectionsView = SQLExplorerPlugin.getDefault().getConnectionsView();
    if (connectionsView != null) {
        connectionsView.refresh();
    }
}
Also used : ConnectionsView(net.sourceforge.sqlexplorer.connections.ConnectionsView) SQLException(java.sql.SQLException)

Example 4 with ConnectionsView

use of net.sourceforge.sqlexplorer.connections.ConnectionsView in project tdq-studio-se by Talend.

the class SQLEditor method init.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.ui.IEditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
     */
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    // Configure the editor
    setSite(site);
    // PTODO qzhang fixed bug 3904: syschronize the resource.
    if (input instanceof FileEditorInput) {
        try {
            ((FileEditorInput) input).getFile().getParent().refreshLocal(IResource.DEPTH_ONE, null);
        } catch (CoreException e) {
            e.printStackTrace();
        }
    }
    setInput(input);
    // Create the text editor
    textEditor = new SQLTextEditor(this);
    textEditor.init(site, input);
    // setPartName(getSite().getPage().getLabel());
    // 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)
             */
        @Override
        public void partClosed(IWorkbenchPartReference partRef) {
            if (partRef.getPart(false) == SQLEditor.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) User(net.sourceforge.sqlexplorer.dbproduct.User) CoreException(org.eclipse.core.runtime.CoreException) ConnectionsView(net.sourceforge.sqlexplorer.connections.ConnectionsView) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPartReference(org.eclipse.ui.IWorkbenchPartReference) SessionEstablishedAdapter(net.sourceforge.sqlexplorer.connections.SessionEstablishedAdapter) Session(net.sourceforge.sqlexplorer.dbproduct.Session)

Example 5 with ConnectionsView

use of net.sourceforge.sqlexplorer.connections.ConnectionsView in project tdq-studio-se by Talend.

the class OpenInEditorAction method run.

public void run() {
    try {
        TableItem[] ti = _table.getSelection();
        if (ti == null || ti.length == 0) {
            return;
        }
        String queryDelimiter = SQLExplorerPlugin.getDefault().getPluginPreferences().getString(IConstants.SQL_QRY_DELIMITER);
        StringBuffer copiedText = new StringBuffer();
        for (int i = 0; i < ti.length; i++) {
            SQLHistoryElement el = (SQLHistoryElement) ti[i].getData();
            copiedText.append(el.getRawSQLString());
            if (ti.length > 0) {
                copiedText.append(queryDelimiter);
                copiedText.append("\n");
            }
        }
        SQLHistoryElement sqlHistoryElement = (SQLHistoryElement) ti[0].getData();
        User user = sqlHistoryElement.getUser();
        Alias alias;
        if (user != null)
            alias = user.getAlias();
        else {
            alias = sqlHistoryElement.getAlias();
            if (alias != null)
                user = alias.getDefaultUser();
            if (user == null) {
                ConnectionsView view = SQLExplorerPlugin.getDefault().getConnectionsView();
                if (view != null)
                    user = view.getDefaultUser();
            }
        }
        if (user != null && !user.hasAuthenticated()) {
            boolean okToOpen = MessageDialog.openConfirm(_table.getShell(), Messages.getString("SQLHistoryView.OpenInEditor.Confirm.Title"), Messages.getString("SQLHistoryView.OpenInEditor.Confirm.Message.Prefix") + " " + user.getDescription() + Messages.getString("SQLHistoryView.OpenInEditor.Confirm.Message.Postfix"));
            if (okToOpen) {
                OpenPasswordConnectDialogAction openDlgAction = new OpenPasswordConnectDialogAction(alias, user, false);
                openDlgAction.run();
            }
        }
        SQLEditorInput input = new SQLEditorInput("SQL Editor (" + SQLExplorerPlugin.getDefault().getEditorSerialNo() + ").sql");
        input.setUser(user);
        IWorkbenchPage page = SQLExplorerPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
        if (page == null)
            return;
        SQLEditor editorPart = (SQLEditor) page.openEditor(input, SQLEditor.class.getName());
        editorPart.setText(copiedText.toString());
    } catch (Throwable e) {
        SQLExplorerPlugin.error("Error creating sql editor", e);
    }
}
Also used : SQLEditor(net.sourceforge.sqlexplorer.plugin.editors.SQLEditor) User(net.sourceforge.sqlexplorer.dbproduct.User) ConnectionsView(net.sourceforge.sqlexplorer.connections.ConnectionsView) TableItem(org.eclipse.swt.widgets.TableItem) OpenPasswordConnectDialogAction(net.sourceforge.sqlexplorer.plugin.actions.OpenPasswordConnectDialogAction) SQLEditorInput(net.sourceforge.sqlexplorer.plugin.editors.SQLEditorInput) SQLHistoryElement(net.sourceforge.sqlexplorer.history.SQLHistoryElement) Alias(net.sourceforge.sqlexplorer.dbproduct.Alias) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage)

Aggregations

ConnectionsView (net.sourceforge.sqlexplorer.connections.ConnectionsView)5 User (net.sourceforge.sqlexplorer.dbproduct.User)3 SQLException (java.sql.SQLException)2 SessionEstablishedAdapter (net.sourceforge.sqlexplorer.connections.SessionEstablishedAdapter)2 Session (net.sourceforge.sqlexplorer.dbproduct.Session)2 PartAdapter2 (net.sourceforge.sqlexplorer.util.PartAdapter2)2 IWorkbenchPartReference (org.eclipse.ui.IWorkbenchPartReference)2 Alias (net.sourceforge.sqlexplorer.dbproduct.Alias)1 SQLHistoryElement (net.sourceforge.sqlexplorer.history.SQLHistoryElement)1 OpenPasswordConnectDialogAction (net.sourceforge.sqlexplorer.plugin.actions.OpenPasswordConnectDialogAction)1 SQLEditor (net.sourceforge.sqlexplorer.plugin.editors.SQLEditor)1 SQLEditorInput (net.sourceforge.sqlexplorer.plugin.editors.SQLEditorInput)1 CoreException (org.eclipse.core.runtime.CoreException)1 TableItem (org.eclipse.swt.widgets.TableItem)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 TextEditor (org.eclipse.ui.editors.text.TextEditor)1 FileEditorInput (org.eclipse.ui.part.FileEditorInput)1