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