RSS news reader; initially copied from "all the news"
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / actions / BaseExecuteAction.java
index 5e8c9d6..830e5ee 100644 (file)
@@ -10,27 +10,29 @@ import com.quantum.Messages;
 import com.quantum.model.Bookmark;
 import com.quantum.model.BookmarkCollection;
 import com.quantum.sql.MultiSQLServer;
+import com.quantum.sql.SQLResultSetCollection;
+import com.quantum.sql.SQLResultSetResults;
 import com.quantum.sql.SQLResults;
+import com.quantum.sql.SQLUpdateResults;
 import com.quantum.ui.dialog.ExceptionDisplayDialog;
+import com.quantum.ui.dialog.SQLExceptionDialog;
 import com.quantum.ui.dialog.SimpleSelectionDialog;
 import com.quantum.util.connection.ConnectionUtil;
 import com.quantum.view.LogProxy;
-import com.quantum.view.tableview.DefaultSizes;
 import com.quantum.view.tableview.TableView;
 
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IStatusLineManager;
 import org.eclipse.jface.dialogs.ErrorDialog;
-import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.actions.SelectionListenerAction;
 
 /**
  * @author BC
  */
-public abstract class BaseExecuteAction extends Action {
+public abstract class BaseExecuteAction extends SelectionListenerAction {
        
        class Metrics {
                int resultCount = 0;
@@ -43,12 +45,12 @@ public abstract class BaseExecuteAction extends Action {
                        if (results == null) {
                                errorCount++;
                        } else {
-                               queryDuration += results.getTime()/1000.0; // calculate the execution time (in seconds)                          
+                               queryDuration += results.getTime()/1000.0; 
                                resultCount++;
                                if (results.isResultSet()) {
                                        resultsDisplayed++;
                                } else {
-                                       resultUpdateCount += results.getUpdateCount();
+                                       resultUpdateCount += ((SQLUpdateResults) results).getUpdateCount();
                                }
                        }
                }
@@ -79,6 +81,14 @@ public abstract class BaseExecuteAction extends Action {
        String execute1 = Messages.getString(BaseExecuteAction.class, "execute1");
        String execute2 = Messages.getString(BaseExecuteAction.class, "execute2");
 
+       protected BaseExecuteAction(String text) {
+               super(text);
+       }
+       
+       protected BaseExecuteAction() {
+               super(null);
+       }
+       
        public void run() {
                Bookmark bookmark = getBookmark();
                if (bookmark != null) {
@@ -100,7 +110,7 @@ public abstract class BaseExecuteAction extends Action {
                } catch (IOException e) {
                    ExceptionDisplayDialog.openError(getShell(), null, null, e);
                } catch (SQLException e) {
-                   ExceptionDisplayDialog.openError(getShell(), null, null, e);
+                   SQLExceptionDialog.openException(getShell(), bookmark, e);
                } catch (CoreException e) {
                    ErrorDialog.openError(getShell(), null, null, e.getStatus());
                }
@@ -129,12 +139,14 @@ public abstract class BaseExecuteAction extends Action {
                        String query = (String) queries.get(i);
                        System.out.println(">" + query + "<"); //$NON-NLS-1$ //$NON-NLS-2$
                        if (query != null && query.trim().length() > 0) {
-                               SQLResults results = getSQLResults(connection, server, query);
+                               SQLResults results = getSQLResults(bookmark, connection, server, query);
                                metrics.measure(results);
                                if (results != null) {
                                        bookmark.addQuery(query);
                                        if (results.isResultSet()) {
-                                               TableView.getInstance().loadQuery(bookmark, results);
+                                               SQLResultSetCollection.getInstance().addSQLResultSet(
+                                                               (SQLResultSetResults) results);
+                                               activateTableView();
                                        }
                                }
                    }
@@ -145,6 +157,13 @@ public abstract class BaseExecuteAction extends Action {
        }
 
        /**
+        * 
+        */
+       private void activateTableView() {
+               TableView.getInstance();
+       }
+
+       /**
         * @return
         * @throws CoreException
         * @throws IOException
@@ -162,14 +181,13 @@ public abstract class BaseExecuteAction extends Action {
        private void displayFinalStatusMessage(Metrics metrics) {
                String message = Messages.getString(
                                BaseExecuteAction.class, 
-                               "done", //$NON-NLS-1$ //$NON-NLS-2$
+                               "done", //$NON-NLS-1$ 
                                metrics.getResults()); 
                if (metrics.hasErrors()) {
                        getStatusLineManager().setErrorMessage(
                                        ImageStore.getImage(ImageStore.STOP), message);
                } else {
-                       getStatusLineManager().setMessage(
-                                       ImageStore.getImage(ImageStore.SUCCESS), message);
+                       getStatusLineManager().setMessage(message);
                }
        }
 
@@ -179,18 +197,15 @@ public abstract class BaseExecuteAction extends Action {
         * @param query
         * @return
         */
-       private SQLResults getSQLResults(Connection connection, MultiSQLServer server, String query) {
+       private SQLResults getSQLResults(Bookmark bookmark, Connection connection, MultiSQLServer server, String query) {
                SQLResults results = null;
                try {
-                       results = server.execute(connection, query, 1, 
-                                       DefaultSizes.PAGE_SIZE, DefaultSizes.MAX_COLUMN_SIZE);
+                       results = server.execute(bookmark, connection, query);
                } catch (SQLException e) {
                        LogProxy log = LogProxy.getInstance();
                        log.addText(LogProxy.ERROR,
                                "Error Executing: " + query + ":" + e.toString(), e); //$NON-NLS-1$ //$NON-NLS-2$
-                       MessageDialog.openConfirm(getShell(), 
-                                       "Database returned error", 
-                                       e.getLocalizedMessage());  //$NON-NLS-1$ 
+                       SQLExceptionDialog.openException(getShell(), bookmark, e);
                }
                return results;
        }