Refactory: remove unused classes, imports, fields and methods.
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.sql / src / net / sourceforge / phpdt / sql / actions / ExecuteAction.java
index cac0de1..9e1294b 100644 (file)
 package net.sourceforge.phpdt.sql.actions;
 
+import java.sql.Connection;
 import java.util.Vector;
 
-import net.sourceforge.phpdt.sql.IConstants;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+
+import net.sourceforge.phpdt.sql.Messages;
 import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
 import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
 import net.sourceforge.phpdt.sql.sql.SQLParser;
 import net.sourceforge.phpdt.sql.sql.SQLResults;
+import net.sourceforge.phpdt.sql.view.BookmarkView;
 import net.sourceforge.phpdt.sql.view.QueryHistoryView;
 import net.sourceforge.phpdt.sql.view.SQLQueryView;
 import net.sourceforge.phpdt.sql.view.TableView;
+import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
 import net.sourceforge.phpdt.sql.view.tableview.DefaultSizes;
 
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.ui.IViewActionDelegate;
-import org.eclipse.ui.IViewPart;
-
-public class ExecuteAction
-  extends Action
-  implements IViewActionDelegate, IConstants {
-  SQLQueryView view;
-  boolean flag = false;
-  String execute1 = "Executing Query...";
-  String execute2 = "Executing Query..";
-  public void init(IViewPart view) {
-    this.view = (SQLQueryView) view;
-  }
+/**
+ * @author panic
+ *
+ *     Executes a query from the QueryView
+ */
+public class ExecuteAction extends Action implements IViewActionDelegate {
+       SQLQueryView view;
+       boolean flag = false;
+       String execute1 = Messages.getString("ExecuteAction.Executing_Query3"); //$NON-NLS-1$
+       String execute2 = Messages.getString("ExecuteAction.Executing_Query2"); //$NON-NLS-1$
+       public void init(IViewPart view) {
+               this.view = (SQLQueryView) view;
+       }
 
-  public void run(IAction action) {
-    run();
-  }
+       public void run(IAction action) {
+               run();
+       }
 
-  public void run() {
-    view.setStatus(execute1);
-    MultiSQLServer server = MultiSQLServer.getInstance();
-    view.setStatus("Parsing sql script...");
-    Vector queries = new Vector();
-    String viewQuery = view.getQuery();
-    queries = SQLParser.parse(viewQuery);
-    for (int i = 0; i < queries.size(); i++) {
-      String query = (String) queries.elementAt(i);
-      if (DEBUG) {
-        System.out.println(query);
-      }
-    }
-    int resultCount = 0;
-    int resultUpdateCount = 0;
-    int errorCount = 0;
-    int resultsDisplayed = 0;
-    for (int i = 0; i < queries.size(); i++) {
-      if (flag) {
-        view.setStatus(execute1);
-      } else {
-        view.setStatus(execute2);
-      }
-      String query = (String) queries.elementAt(i);
-      if (DEBUG) {
-        System.out.println(">" + query + "<");
-      }
-      if (!query.equals("")) {
-        SQLResults results =
-          server.execute(
-            query,
-            1,
-            DefaultSizes.PAGE_SIZE,
-            DefaultSizes.MAX_COLUMN_SIZE);
-        resultCount++;
-        if (results.isResultSet()) {
-          TableView.getInstance().loadQuery(results);
-          resultsDisplayed++;
-        } else {
-          int count = results.getUpdateCount();
-          if (count > 0) {
-            resultUpdateCount += results.getUpdateCount();
-          }
-        }
-        if (results.isError()) {
-          errorCount++;
-        }
-      }
-      flag = !flag;
-      view.setProgress(i + 1, queries.size());
-    }
-    if (errorCount > 0) {
-      Image error = PHPEclipseSQLPlugin.getImage("stop.gif");
-      view.setStatus(
-        error,
-        "Done ("
-          + resultCount
-          + " queries executed, "
-          + resultUpdateCount
-          + " rows updated, "
-          + resultsDisplayed
-          + " results displayed, "
-          + errorCount
-          + " errors)");
-    } else {
-      Image success = PHPEclipseSQLPlugin.getImage("success.gif");
-      view.setStatus(
-        success,
-        "Done ("
-          + resultCount
-          + " queries executed, "
-          + resultUpdateCount
-          + " rows updated, "
-          + resultsDisplayed
-          + " results displayed, "
-          + errorCount
-          + " errors)");
-    }
-    view.setProgress(0, 1);
-    QueryHistoryView history = QueryHistoryView.getInstance();
-    history.addQuery(viewQuery);
-  }
+       public void run() {
+               view.setStatus(execute1);
+               MultiSQLServer server = MultiSQLServer.getInstance();
+           view.setStatus(Messages.getString("ExecuteAction.Parsing_sql_script3")); //$NON-NLS-1$
+           Vector queries = new Vector();
+           String viewQuery = view.getQuery();
+               queries = SQLParser.parse(viewQuery);
+               for (int i = 0; i < queries.size(); i++) {
+                       String query = (String) queries.elementAt(i);
+                       System.out.println(query);
+               }
+               int resultCount = 0;
+               int resultUpdateCount = 0;
+               int errorCount = 0;
+               int resultsDisplayed = 0;
+               for (int i = 0; i < queries.size(); i++) {
+                       if (flag) {
+                               view.setStatus(execute1);
+                       } else {
+                               view.setStatus(execute2);
+                       }
+                  BookmarkNode current = BookmarkView.getInstance().getCurrentBookmark();
+                  Connection con = current.getConnection();
+                  
+                  String query = (String) queries.elementAt(i);
+                  System.out.println(">" + query + "<"); //$NON-NLS-1$ //$NON-NLS-2$
+                  if (con != null && !query.equals("")) { //$NON-NLS-1$
+                          SQLResults results = server.execute(con, query, 1, DefaultSizes.PAGE_SIZE, DefaultSizes.MAX_COLUMN_SIZE);
+                          resultCount++;
+                          if (results.isResultSet()) {
+                                PHPEclipseSQLPlugin phpesqlPluginInstance = PHPEclipseSQLPlugin.getDefault();
+                                phpesqlPluginInstance.showView("net.sourceforge.phpdt.sql.view.tableview"); //$NON-NLS-1$
+                                TableView.getInstance().loadQuery(current, results);
+                                resultsDisplayed++;
+                          } else {
+                                int count = results.getUpdateCount();
+                                if (count > 0) {
+                                       resultUpdateCount += results.getUpdateCount();
+                                }
+                          }
+                          if (results.isError()) {
+                               errorCount++;
+                          }
+                  }
+                  flag = !flag;
+                  view.setProgress(i + 1, queries.size());
+           }
+               Image statImage = PHPEclipseSQLPlugin.getImage((errorCount > 0) ? "stop.gif" : "success.gif"); //$NON-NLS-1$ //$NON-NLS-2$
+               view.setStatus(statImage, Messages.getString("ExecuteAction.Done") + "(" + //$NON-NLS-1$ //$NON-NLS-2$
+                                               resultCount + Messages.getString("ExecuteAction.QueriesExecuted") +  //$NON-NLS-1$
+                                               resultUpdateCount + Messages.getString("ExecuteAction.RowsUpdated") +  //$NON-NLS-1$
+                                               resultsDisplayed + Messages.getString("ExecuteAction.ResultsDisplayed") +  //$NON-NLS-1$
+                                               errorCount + Messages.getString("ExecuteAction.Errors") + ")");  //$NON-NLS-1$ //$NON-NLS-2$
+               view.setProgress(0, 1);
+               QueryHistoryView history = QueryHistoryView.getInstance();
+               if (history != null) history.addQuery(viewQuery);
+       }
 
-  public void selectionChanged(IAction action, ISelection selection) {
-  }
+       public void selectionChanged(IAction action, ISelection selection) {
+       }
 }