Search in sources :

Example 6 with Session

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

the class FilterStructureAction method run.

public void run() {
    try {
        DatabaseStructureView view = SQLExplorerPlugin.getDefault().getDatabaseStructureView();
        FilterStructureDialog dialog = new FilterStructureDialog();
        Session session = view.getSession();
        if (session == null)
            return;
        Alias alias = session.getUser().getAlias();
        if (alias.getSchemaFilterExpression() != null && alias.getSchemaFilterExpression().length() != 0) {
            dialog.setSchemaFilter(alias.getSchemaFilterExpression().split(","));
        }
        if (alias.getFolderFilterExpression() != null && alias.getFolderFilterExpression().length() != 0) {
            dialog.setFolderFilter(alias.getFolderFilterExpression().split(","));
        }
        if (alias.getNameFilterExpression() != null && alias.getNameFilterExpression().length() != 0) {
            dialog.setNameFilter(alias.getNameFilterExpression());
        }
        if (dialog.open() != Window.OK) {
            return;
        }
        String[] schemaFilter = dialog.getSchemaFilter();
        StringBuffer schemaFilterString = new StringBuffer("");
        String sep = "";
        if (schemaFilter != null) {
            for (int i = 0; i < schemaFilter.length; i++) {
                schemaFilterString.append(sep);
                schemaFilterString.append(schemaFilter[i]);
                sep = ",";
            }
        }
        alias.setSchemaFilterExpression(schemaFilterString.toString());
        String[] folderFilter = dialog.getFolderFilter();
        StringBuffer folderFilterString = new StringBuffer("");
        sep = "";
        if (folderFilter != null) {
            for (int i = 0; i < folderFilter.length; i++) {
                folderFilterString.append(sep);
                folderFilterString.append(folderFilter[i]);
                sep = ",";
            }
        }
        alias.setFolderFilterExpression(folderFilterString.toString());
        alias.setNameFilterExpression(dialog.getNameFilter());
        view.refreshSessionTrees(view.getSession());
    } catch (Exception e) {
        SQLExplorerPlugin.error("Error creating dialog", e);
    }
}
Also used : Alias(net.sourceforge.sqlexplorer.dbproduct.Alias) DatabaseStructureView(net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView) FilterStructureDialog(net.sourceforge.sqlexplorer.dialogs.FilterStructureDialog) Session(net.sourceforge.sqlexplorer.dbproduct.Session)

Example 7 with Session

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

the class ExecSQLAction method run.

protected void run(int maxRows) {
    Session session = getSession();
    if (session == null)
        return;
    QueryParser qt = session.getDatabaseProduct().getQueryParser(_editor.getSQLToBeExecuted(), _editor.getSQLLineNumber());
    try {
        qt.parse();
    } catch (final ParserException e) {
        _editor.getSite().getShell().getDisplay().asyncExec(new Runnable() {

            public void run() {
                MessageDialog.openError(_editor.getSite().getShell(), Messages.getString("SQLResultsView.Error.Title"), e.getMessage());
            }
        });
    }
    if (qt.iterator().hasNext()) {
        boolean clearResults = SQLExplorerPlugin.getDefault().getPreferenceStore().getBoolean(IConstants.CLEAR_RESULTS_ON_EXECUTE);
        if (clearResults)
            _editor.clearResults();
        AbstractSQLExecution job = new SQLExecution(_editor, qt, maxRows);
        job.schedule();
    }
}
Also used : ParserException(net.sourceforge.sqlexplorer.parsers.ParserException) QueryParser(net.sourceforge.sqlexplorer.parsers.QueryParser) AbstractSQLExecution(net.sourceforge.sqlexplorer.sqlpanel.AbstractSQLExecution) SQLExecution(net.sourceforge.sqlexplorer.sqlpanel.SQLExecution) AbstractSQLExecution(net.sourceforge.sqlexplorer.sqlpanel.AbstractSQLExecution) Session(net.sourceforge.sqlexplorer.dbproduct.Session)

Example 8 with Session

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

the class SQLEditor method setInput.

/*
     * (non-JavaDoc)
     * 
     * @see org.eclipse.ui.part.EditorPart#setInput(org.eclipse.ui.IEditorInput)
     */
@Override
protected void setInput(IEditorInput input) {
    super.setInput(input);
    if (textEditor != null) {
        textEditor.setInput(input);
    }
    // Handle our own form of input
    if (input instanceof SQLEditorInput) {
        SQLEditorInput sqlInput = (SQLEditorInput) input;
        if (input != null) {
            User user = sqlInput.getUser();
            if (user != null) {
                user.queueForNewSession(new SessionEstablishedAdapter() {

                    @Override
                    public void sessionEstablished(Session session) {
                        setSession(session);
                    }
                });
            }
            isDirty = true;
            isUntitled = true;
        }
    }
    // set part name as displayName + " " + version
    String partName = input.getName();
    if (input instanceof FileEditorInput) {
        FileEditorInput fileEditorInput = (FileEditorInput) input;
        // $NON-NLS-1$
        IPath fileName = fileEditorInput.getPath().removeFileExtension().addFileExtension("properties");
        Property property = null;
        URI propURI = URI.createFileURI(fileName.toOSString());
        Resource resource = new ResourceSetImpl().getResource(propURI, true);
        if (resource.getContents() != null) {
            Object object = EcoreUtil.getObjectByType(resource.getContents(), PropertiesPackage.eINSTANCE.getProperty());
            if (object != null) {
                property = (Property) object;
            }
        }
        if (property != null) {
            // $NON-NLS-1$
            partName = property.getDisplayName() + " " + property.getVersion();
        }
    }
    setPartName(partName);
}
Also used : User(net.sourceforge.sqlexplorer.dbproduct.User) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) IPath(org.eclipse.core.runtime.IPath) Resource(org.eclipse.emf.ecore.resource.Resource) IResource(org.eclipse.core.resources.IResource) URI(org.eclipse.emf.common.util.URI) FileEditorInput(org.eclipse.ui.part.FileEditorInput) Property(org.talend.core.model.properties.Property) SessionEstablishedAdapter(net.sourceforge.sqlexplorer.connections.SessionEstablishedAdapter) Session(net.sourceforge.sqlexplorer.dbproduct.Session)

Example 9 with Session

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

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

the class ExplainAction2 method run.

public void run() {
    try {
        Session session;
        SQLConnection connection;
        Statement stmt;
        ResultSet rs;
        session = getSession();
        if (session == null)
            return;
        connection = null;
        stmt = null;
        rs = null;
        boolean createPlanTable;
        boolean notFoundTable;
        connection = session.grabConnection();
        Statement st = connection.createStatement();
        createPlanTable = false;
        notFoundTable = true;
        try {
            rs = st.executeQuery("select statement_id from plan_table");
            notFoundTable = false;
            rs.close();
            rs = null;
        } catch (SQLException _ex) {
            createPlanTable = MessageDialog.openQuestion(null, Messages.getString("oracle.editor.actions.explain.notFound.Title"), Messages.getString("oracle.editor.actions.explain.notFound"));
        }
        st.close();
        st = null;
        if (notFoundTable && !createPlanTable) {
            if (rs != null)
                try {
                    rs.close();
                } catch (SQLException e) {
                    SQLExplorerPlugin.error("Cannot close result set", e);
                }
            if (stmt != null)
                try {
                    stmt.close();
                } catch (SQLException e) {
                    SQLExplorerPlugin.error("Cannot close statement", e);
                }
            if (connection != null)
                session.releaseConnection(connection);
            return;
        }
        try {
            if (notFoundTable && createPlanTable) {
                st = connection.createStatement();
                st.execute("CREATE TABLE PLAN_TABLE (  STATEMENT_ID                    VARCHAR2(30), TIMESTAMP                       DATE,  REMARKS                         VARCHAR2(80),  OPERATION                       VARCHAR2(30),  OPTIONS                         VARCHAR2(30),  OBJECT_NODE                     VARCHAR2(128),  OBJECT_OWNER                    VARCHAR2(30),  OBJECT_NAME                     VARCHAR2(30),  OBJECT_INSTANCE                 NUMBER(38),  OBJECT_TYPE                     VARCHAR2(30),  OPTIMIZER                       VARCHAR2(255),  SEARCH_COLUMNS                  NUMBER,  ID                              NUMBER(38),  PARENT_ID                       NUMBER(38),  POSITION                        NUMBER(38),  COST                            NUMBER(38),  CARDINALITY                     NUMBER(38),  BYTES                           NUMBER(38),  OTHER_TAG                       VARCHAR2(255),  PARTITION_START                 VARCHAR2(255),  PARTITION_STOP                  VARCHAR2(255),  PARTITION_ID                    NUMBER(38),  OTHER                           LONG,  DISTRIBUTION                    VARCHAR2(30))");
                st.close();
                st = null;
            }
            QueryParser qt = session.getDatabaseProduct().getQueryParser(_editor.getSQLToBeExecuted(), _editor.getSQLLineNumber());
            qt.parse();
            (new ExplainExecution(_editor, qt)).schedule();
        } catch (SQLException e) {
            SQLExplorerPlugin.error("Error creating explain plan", e);
        } catch (ParserException e) {
            SQLExplorerPlugin.error("Cannot parse query", e);
        }
        if (rs != null)
            try {
                rs.close();
            } catch (SQLException e) {
                SQLExplorerPlugin.error("Cannot close result set", e);
            }
        if (stmt != null)
            try {
                stmt.close();
            } catch (SQLException e) {
                SQLExplorerPlugin.error("Cannot close statement", e);
            }
        if (connection != null)
            session.releaseConnection(connection);
        if (rs != null)
            try {
                rs.close();
            } catch (SQLException e) {
                SQLExplorerPlugin.error("Cannot close result set", e);
            }
        if (stmt != null)
            try {
                stmt.close();
            } catch (SQLException e) {
                SQLExplorerPlugin.error("Cannot close statement", e);
            }
        if (connection != null)
            session.releaseConnection(connection);
    } catch (Exception e) {
    }
}
Also used : ParserException(net.sourceforge.sqlexplorer.parsers.ParserException) QueryParser(net.sourceforge.sqlexplorer.parsers.QueryParser) SQLException(java.sql.SQLException) Statement(java.sql.Statement) SQLConnection(net.sourceforge.sqlexplorer.dbproduct.SQLConnection) ResultSet(java.sql.ResultSet) SQLException(java.sql.SQLException) ParserException(net.sourceforge.sqlexplorer.parsers.ParserException) 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