Very ugly start of a first wizard page. Needs a lot of cleanup!
[phpeclipse.git] / net.sourceforge.phpeclipse.wizards / src / net / sourceforge / phpeclipse / wizards / actions / metadata / BaseSQLPage.java
diff --git a/net.sourceforge.phpeclipse.wizards/src/net/sourceforge/phpeclipse/wizards/actions/metadata/BaseSQLPage.java b/net.sourceforge.phpeclipse.wizards/src/net/sourceforge/phpeclipse/wizards/actions/metadata/BaseSQLPage.java
new file mode 100644 (file)
index 0000000..201953e
--- /dev/null
@@ -0,0 +1,72 @@
+package net.sourceforge.phpeclipse.wizards.actions.metadata;
+
+import java.sql.SQLException;
+
+import org.eclipse.jface.wizard.WizardPage;
+
+import com.quantum.adapters.DatabaseAdapter;
+import com.quantum.model.Column;
+import com.quantum.model.Entity;
+import com.quantum.sql.SQLResultSetResults;
+import com.quantum.ui.dialog.ConnectionUtil;
+import com.quantum.util.connection.NotConnectedException;
+
+/**
+ * @author BC Holmes
+ */
+public abstract class BaseSQLPage extends WizardPage implements SQLPage {
+
+    protected Row row;
+    protected Column[] columns;
+//     protected SQLResultSetResults results;
+       private ConnectionUtil connectionUtil = new ConnectionUtil();
+
+    public BaseSQLPage(String pageName) {
+        super(pageName);
+    }
+    public boolean performFinish() {
+//             Bookmark bookmark = (Bookmark) this.results.getConnectable();
+//             try {
+//                     bookmark.addQuery(getQueryText());
+//                     SQLResults sqlResults = MultiSQLServer.getInstance().execute(bookmark, 
+//                                     this.connectionUtil.getConnection(bookmark, getShell()), getQueryText());
+//                     return sqlResults == null ? false : true;
+//             } catch (SQLException e) {
+//                     SQLExceptionDialog.openException(getShell(), bookmark, e);
+//                     return false;
+//             }
+      return false;
+       }
+    
+    protected abstract String getQueryText();
+    protected void appendColumn(StringBuffer whereClause, Entity entity, String columnName, DatabaseAdapter adapter, String value) {
+        
+        if (adapter != null && entity != null && getColumn(entity, columnName) != null) {
+            Column column = getColumn(entity, columnName);
+               whereClause.append(adapter.quote(value, column.getType(), column.getTypeName()));
+        } else {
+               whereClause.append(value);
+        }
+    }
+    /**
+        * @param entity
+        * @param columnName
+        * @return
+        * @throws NotConnectedException
+        * @throws SQLException
+        */
+       protected Column getColumn(Entity entity, String columnName)  {
+               try {
+                       return entity == null ? null : entity.getColumn(columnName);
+               } catch (NotConnectedException e) {
+                       return null;
+               } catch (SQLException e) {
+                       return null;
+               }
+       }
+       public void init(Row row, Column[] columns) {
+//     this.results = results;
+               this.row = row;
+               this.columns = columns;
+    }
+}