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
1 package net.sourceforge.phpeclipse.wizards.actions.metadata;
2
3 import java.sql.SQLException;
4
5 import org.eclipse.jface.wizard.WizardPage;
6
7 import com.quantum.adapters.DatabaseAdapter;
8 import com.quantum.model.Column;
9 import com.quantum.model.Entity;
10 import com.quantum.sql.SQLResultSetResults;
11 import com.quantum.ui.dialog.ConnectionUtil;
12 import com.quantum.util.connection.NotConnectedException;
13
14 /**
15  * @author BC Holmes
16  */
17 public abstract class BaseSQLPage extends WizardPage implements SQLPage {
18
19     protected Row row;
20     protected Column[] columns;
21 //      protected SQLResultSetResults results;
22         private ConnectionUtil connectionUtil = new ConnectionUtil();
23
24     public BaseSQLPage(String pageName) {
25         super(pageName);
26     }
27     public boolean performFinish() {
28 //              Bookmark bookmark = (Bookmark) this.results.getConnectable();
29 //              try {
30 //                      bookmark.addQuery(getQueryText());
31 //                      SQLResults sqlResults = MultiSQLServer.getInstance().execute(bookmark, 
32 //                                      this.connectionUtil.getConnection(bookmark, getShell()), getQueryText());
33 //                      return sqlResults == null ? false : true;
34 //              } catch (SQLException e) {
35 //                      SQLExceptionDialog.openException(getShell(), bookmark, e);
36 //                      return false;
37 //              }
38       return false;
39         }
40     
41     protected abstract String getQueryText();
42     protected void appendColumn(StringBuffer whereClause, Entity entity, String columnName, DatabaseAdapter adapter, String value) {
43         
44         if (adapter != null && entity != null && getColumn(entity, columnName) != null) {
45             Column column = getColumn(entity, columnName);
46                 whereClause.append(adapter.quote(value, column.getType(), column.getTypeName()));
47         } else {
48                 whereClause.append(value);
49         }
50     }
51     /**
52          * @param entity
53          * @param columnName
54          * @return
55          * @throws NotConnectedException
56          * @throws SQLException
57          */
58         protected Column getColumn(Entity entity, String columnName)  {
59                 try {
60                         return entity == null ? null : entity.getColumn(columnName);
61                 } catch (NotConnectedException e) {
62                         return null;
63                 } catch (SQLException e) {
64                         return null;
65                 }
66         }
67         public void init(Row row, Column[] columns) {
68 //      this.results = results;
69                 this.row = row;
70                 this.columns = columns;
71     }
72 }