Search in sources :

Example 1 with Message

use of net.sourceforge.sqlexplorer.plugin.editors.Message in project tdq-studio-se by Talend.

the class SQLExecution method displayResults.

/**
 * Display SQL Results in result pane
 * @param sqlResult the results of the query
 */
protected void displayResults(final SQLResult sqlResult) {
    // Switch to the UI thread to execute this
    getEditor().getSite().getShell().getDisplay().asyncExec(new Runnable() {

        public void run() {
            ResultsTab resultsTab = allocateResultsTab(sqlResult.getQuery());
            if (resultsTab == null)
                return;
            String caption = sqlResult.getDataSet().getCaption();
            if (caption != null)
                resultsTab.getTabItem().setText(caption);
            try {
                // set initial message
                setProgressMessage(Messages.getString("SQLResultsView.ConnectionWait"));
                Composite composite = resultsTab.getParent();
                GridLayout gLayout = new GridLayout();
                gLayout.numColumns = 2;
                gLayout.marginLeft = 0;
                gLayout.horizontalSpacing = 0;
                gLayout.verticalSpacing = 0;
                gLayout.marginWidth = 0;
                gLayout.marginHeight = 0;
                composite.setLayout(gLayout);
                int resultCount = sqlResult.getDataSet().getRows().length;
                String statusMessage = Messages.getString("SQLResultsView.Time.Prefix") + " " + sqlResult.getExecutionTimeMillis() + " " + Messages.getString("SQLResultsView.Time.Postfix");
                getEditor().setMessage(statusMessage);
                if (resultCount > 0)
                    statusMessage = statusMessage + "  " + Messages.getString("SQLResultsView.Count.Prefix") + " " + resultCount;
                Query sql = sqlResult.getQuery();
                int lineNo = sql.getLineNo();
                lineNo = getQueryParser().adjustLineNo(lineNo);
                getEditor().addMessage(new Message(Message.Status.SUCCESS, lineNo, 0, sql.getQuerySql(), statusMessage));
                new DataSetTable(composite, sqlResult.getDataSet(), statusMessage);
                composite.setData("parenttab", resultsTab.getTabItem());
                composite.layout();
                composite.redraw();
                // reset to start message in case F5 will be used
                setProgressMessage(Messages.getString("SQLResultsView.ConnectionWait"));
            } catch (Exception e) {
                // add message
                if (resultsTab != null) {
                    String message = e.getMessage();
                    Label errorLabel = new Label(resultsTab.getParent(), SWT.FILL);
                    errorLabel.setText(message);
                    errorLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
                }
                SQLExplorerPlugin.error("Error creating result tab", e);
            }
        }
    });
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) Query(net.sourceforge.sqlexplorer.parsers.Query) Message(net.sourceforge.sqlexplorer.plugin.editors.Message) DataSetTable(net.sourceforge.sqlexplorer.dataset.DataSetTable) ResultsTab(net.sourceforge.sqlexplorer.sqleditor.results.ResultsTab) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) SQLException(java.sql.SQLException)

Example 2 with Message

use of net.sourceforge.sqlexplorer.plugin.editors.Message in project tdq-studio-se by Talend.

the class AbstractSQLExecution method logException.

/**
 * Handles a SQLException by parsing the message and populating the messages tab;
 * where error messages from the server are numbered, they start relative to the
 * line number of the query that was sent; lineNoOffset is added to each line
 * number so that they relate to the line in SQLEditor
 * @param e
 */
protected void logException(ParserException e, Query query) throws SQLException {
    LinkedList<Message> messages = new LinkedList<Message>();
    messages.add(new Message(Message.Status.FAILURE, e.getLineNo(), e.getCharNo(), query.getQuerySql(), e.getMessage()));
    addMessages(messages);
}
Also used : Message(net.sourceforge.sqlexplorer.plugin.editors.Message) LinkedList(java.util.LinkedList)

Example 3 with Message

use of net.sourceforge.sqlexplorer.plugin.editors.Message in project tdq-studio-se by Talend.

the class DefaultDatabaseProduct method getErrorMessages.

public Collection<Message> getErrorMessages(SQLConnection connection, SQLException e, int lineNoOffset) throws SQLException {
    LinkedList list = new LinkedList();
    list.add(new Message(Message.Status.FAILURE, lineNoOffset + 1, 0, e.getMessage()));
    return list;
}
Also used : Message(net.sourceforge.sqlexplorer.plugin.editors.Message) LinkedList(java.util.LinkedList)

Example 4 with Message

use of net.sourceforge.sqlexplorer.plugin.editors.Message in project tdq-studio-se by Talend.

the class SQLExecution method doExecution.

protected void doExecution(IProgressMonitor monitor) throws Exception {
    int numErrors = 0;
    SQLException lastSQLException = null;
    try {
        long overallUpdateCount = 0;
        long overallStartTime = System.currentTimeMillis();
        for (Query query : getQueryParser()) {
            if (monitor.isCanceled())
                break;
            if (getEditor().isClosed())
                break;
            // Get the next bit of SQL to run and store it as "current"
            if (query == null)
                break;
            String querySQL = query.getQuerySql().toString();
            if (querySQL == null)
                continue;
            // Initialise
            setProgressMessage(Messages.getString("SQLResultsView.Executing"));
            final long startTime = System.currentTimeMillis();
            // Run it
            DatabaseProduct.ExecutionResults results = null;
            try {
                DatabaseProduct product = getEditor().getSession().getDatabaseProduct();
                try {
                    results = product.executeQuery(_connection, query, _maxRows);
                } catch (RuntimeException e) {
                    throw new SQLException(e.getMessage());
                }
                final long endTime = System.currentTimeMillis();
                DataSet dataSet;
                boolean checkedForMessages = false;
                while ((dataSet = results.nextDataSet()) != null) {
                    // update sql result
                    SQLResult sqlResult = new SQLResult();
                    sqlResult.setQuery(query);
                    sqlResult.setDataSet(dataSet);
                    sqlResult.setExecutionTimeMillis(endTime - startTime);
                    // Save successfull query
                    SQLExplorerPlugin.getDefault().getSQLHistory().addSQL(querySQL, _session);
                    if (monitor.isCanceled())
                        return;
                    checkForMessages(query);
                    checkedForMessages = true;
                    // show results..
                    displayResults(sqlResult);
                }
                overallUpdateCount += results.getUpdateCount();
                if (!checkedForMessages)
                    checkForMessages(query);
                debugLogQuery(query, null);
            } catch (final SQLException e) {
                debugLogQuery(query, e);
                boolean stopOnError = SQLExplorerPlugin.getDefault().getPreferenceStore().getBoolean(IConstants.STOP_ON_ERROR);
                logException(e, query, stopOnError);
                closeStatement();
                hasMessages = true;
                if (stopOnError) {
                    errorDialog(Messages.getString("SQLResultsView.Error.Title"), e.getMessage());
                    return;
                }
                numErrors++;
                lastSQLException = e;
            } finally {
                try {
                    if (results != null) {
                        results.close();
                        results = null;
                    }
                } catch (SQLException e) {
                // Nothing
                }
            }
        }
        if (!hasMessages || SQLExplorerPlugin.getDefault().getPreferenceStore().getBoolean(IConstants.LOG_SUCCESS_MESSAGES)) {
            long overallTime = System.currentTimeMillis() - overallStartTime;
            String message = Long.toString(overallUpdateCount) + " " + Messages.getString("SQLEditor.Update.Prefix") + " " + Long.toString(overallTime) + " " + Messages.getString("SQLEditor.Update.Postfix");
            addMessage(new Message(Message.Status.STATUS, getQueryParser().adjustLineNo(1), 0, "", message));
        }
    } catch (Exception e) {
        closeStatement();
        throw e;
    }
    if (numErrors == 1)
        throw lastSQLException;
    else if (numErrors > 1 && SQLExplorerPlugin.getDefault().getPreferenceStore().getBoolean(IConstants.CONFIRM_BOOL_SHOW_DIALOG_ON_QUERY_ERROR))
        getEditor().getSite().getShell().getDisplay().asyncExec(new Runnable() {

            public void run() {
                MessageDialogWithToggle dialog = MessageDialogWithToggle.openInformation(getEditor().getSite().getShell(), Messages.getString("SQLExecution.Error.Title"), Messages.getString("SQLExecution.Error.Message"), Messages.getString("SQLExecution.Error.Toggle"), false, null, null);
                if (dialog.getToggleState() && dialog.getReturnCode() == IDialogConstants.OK_ID)
                    SQLExplorerPlugin.getDefault().getPluginPreferences().setValue(IConstants.CONFIRM_BOOL_SHOW_DIALOG_ON_QUERY_ERROR, false);
            }
        });
}
Also used : Query(net.sourceforge.sqlexplorer.parsers.Query) Message(net.sourceforge.sqlexplorer.plugin.editors.Message) SQLException(java.sql.SQLException) DataSet(net.sourceforge.sqlexplorer.dataset.DataSet) SQLException(java.sql.SQLException) DatabaseProduct(net.sourceforge.sqlexplorer.dbproduct.DatabaseProduct) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle)

Example 5 with Message

use of net.sourceforge.sqlexplorer.plugin.editors.Message in project tdq-studio-se by Talend.

the class AbstractSQLExecution method checkForMessages.

/**
 * Checks the database server for messages
 */
protected boolean checkForMessages(Query query) throws SQLException {
    LinkedList<Message> messages = new LinkedList<Message>();
    Collection<Message> messagesTmp;
    if (query != null) {
        messagesTmp = _session.getDatabaseProduct().getErrorMessages(_connection, query);
        if (messagesTmp != null)
            messages.addAll(messagesTmp);
    }
    messagesTmp = _session.getDatabaseProduct().getServerMessages(_connection);
    if (messagesTmp != null)
        messages.addAll(messagesTmp);
    boolean hasMessages = false;
    for (Message msg : messages) {
        msg.setLineNo(getQueryParser().adjustLineNo(msg.getLineNo()));
        if (msg.getStatus() != Message.Status.SUCCESS)
            hasMessages = true;
    }
    addMessages(messages);
    return hasMessages;
}
Also used : Message(net.sourceforge.sqlexplorer.plugin.editors.Message) LinkedList(java.util.LinkedList)

Aggregations

Message (net.sourceforge.sqlexplorer.plugin.editors.Message)8 LinkedList (java.util.LinkedList)4 SQLException (java.sql.SQLException)3 DatabaseProduct (net.sourceforge.sqlexplorer.dbproduct.DatabaseProduct)3 Query (net.sourceforge.sqlexplorer.parsers.Query)3 DataSet (net.sourceforge.sqlexplorer.dataset.DataSet)2 File (java.io.File)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 DataSetTable (net.sourceforge.sqlexplorer.dataset.DataSetTable)1 SQLConnection (net.sourceforge.sqlexplorer.dbproduct.SQLConnection)1 ParserException (net.sourceforge.sqlexplorer.parsers.ParserException)1 QueryParser (net.sourceforge.sqlexplorer.parsers.QueryParser)1 ResultsTab (net.sourceforge.sqlexplorer.sqleditor.results.ResultsTab)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 MessageDialogWithToggle (org.eclipse.jface.dialogs.MessageDialogWithToggle)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1