bug 1469012, exception in CompletionProposal
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / actions / BaseSequenceAction.java
index 0e967c4..d0f4217 100644 (file)
@@ -3,8 +3,13 @@ package com.quantum.actions;
 import java.sql.Connection;
 import java.util.List;
 
+import com.quantum.adapters.DatabaseAdapter;
 import com.quantum.model.Bookmark;
+import com.quantum.sql.SQLResultSetCollection;
+import com.quantum.sql.SQLResultSetResults;
+import com.quantum.sql.SQLResults;
 import com.quantum.util.connection.ConnectionUtil;
+import com.quantum.view.ViewHelper;
 import com.quantum.view.bookmark.EntityNode;
 import com.quantum.view.bookmark.TreeNode;
 
@@ -23,7 +28,7 @@ public abstract class BaseSequenceAction extends SelectionListenerAction {
 
     protected BaseSequenceAction(String text, IViewPart view) {
         super(text);
-        
+        this.view = view;
     }
 
     protected Bookmark getBookmark() {
@@ -50,4 +55,28 @@ public abstract class BaseSequenceAction extends SelectionListenerAction {
             && (selection.getFirstElement() instanceof EntityNode) 
             && ((EntityNode) selection.getFirstElement()).isSequence();
     }
+
+       public void run() {
+               EntityNode sequence = getEntityNode();
+               String name = null;
+               if (sequence.isSequence()) {
+                       Bookmark bookmark = sequence.getBookmark();
+                       DatabaseAdapter adapter = bookmark.getAdapter();
+                       if (adapter == null) return;
+                       name = sequence.getName();
+                       String query = getQuery(sequence, name, adapter);
+                       
+                       SQLResults results = ViewHelper.tryGetResults(view, bookmark, getConnection(), query);
+                       if (results != null && results.isResultSet()) 
+                               SQLResultSetCollection.getInstance().addSQLResultSet((SQLResultSetResults) results);
+               }
+       }
+
+       /**
+        * @param sequence
+        * @param name
+        * @param adapter
+        * @return
+        */
+       protected abstract String getQuery(EntityNode sequence, String name, DatabaseAdapter adapter);
 }