1 package com.quantum.wizards;
3 import java.sql.SQLException;
4 import java.util.Arrays;
6 import com.quantum.adapters.DatabaseAdapter;
7 import com.quantum.model.Bookmark;
8 import com.quantum.model.Column;
9 import com.quantum.model.Entity;
10 import com.quantum.model.NotConnectedException;
11 import com.quantum.sql.MultiSQLServer;
12 import com.quantum.sql.SQLResultSetResults;
13 import com.quantum.sql.SQLResults;
14 import com.quantum.ui.dialog.SQLExceptionDialog;
15 import com.quantum.util.connection.ConnectionUtil;
17 import org.eclipse.jface.wizard.WizardPage;
18 import org.eclipse.swt.widgets.Table;
19 import org.eclipse.swt.widgets.TableColumn;
25 public abstract class BaseSQLPage extends WizardPage implements SQLPage {
27 protected SQLResultSetResults.Row row;
28 protected SQLResultSetResults results;
29 private ConnectionUtil connectionUtil = new ConnectionUtil();
31 public BaseSQLPage(String pageName) {
34 public boolean performFinish() {
35 Bookmark bookmark = this.results.getBookmark();
37 bookmark.addQuery(getQueryText());
38 SQLResults sqlResults = MultiSQLServer.getInstance().execute(bookmark,
39 this.connectionUtil.getConnection(bookmark, getShell()), getQueryText());
40 return sqlResults == null ? false : true;
41 } catch (SQLException e) {
42 SQLExceptionDialog.openException(getShell(), bookmark, e);
47 protected abstract String getQueryText();
48 protected void appendColumn(StringBuffer whereClause, Entity entity, String columnName, DatabaseAdapter adapter, String value) {
50 if (adapter != null && entity != null && getColumn(entity, columnName) != null) {
51 Column column = getColumn(entity, columnName);
52 whereClause.append(adapter.quote(value, column.getType(), column.getTypeName()));
54 whereClause.append(value);
61 * @throws NotConnectedException
62 * @throws SQLException
64 protected Column getColumn(Entity entity, String columnName) {
66 return entity == null ? null : entity.getColumn(columnName);
67 } catch (NotConnectedException e) {
69 } catch (SQLException e) {
73 public void init(SQLResultSetResults results, SQLResultSetResults.Row row) {
74 this.results = results;
85 protected void createTableColumn(Table table, String colName, int style, int pos, int width) {
86 TableColumn column = new TableColumn(table, style, pos);
87 column.setText(colName);
88 column.setWidth(width);
95 protected java.util.List getColumnNamesAsList(String[] columnNames) {
96 return Arrays.asList(columnNames);