home *** CD-ROM | disk | FTP | other *** search
- package asp.wizard.def;
-
- import asp.wizard.AspWizardExceptionHandler;
- import asp.wizard.EWizDbManager;
- import asp.wizard.WizDbManager;
- import java.sql.ResultSet;
- import java.sql.ResultSetMetaData;
- import java.sql.SQLException;
- import java.util.Vector;
-
- public class DefQuery extends DefAbstract {
- private DefConnection _defConnection;
- private String _dbConnection;
- private int _usePreviousQuery = 1;
- private String _select;
- private String _from;
- private String _where;
- private String _orderBy;
- private Vector _firstRecord;
- private Vector _resultSetColumns;
-
- public void setResultSet(ResultSet resultSet) {
- if (resultSet != null) {
- Vector firstRec = new Vector();
-
- try {
- ResultSetMetaData rsmd = resultSet.getMetaData();
- if (resultSet.next()) {
- int cols = rsmd.getColumnCount();
-
- for(int i = 1; i <= cols; ++i) {
- firstRec.addElement(resultSet.getObject(i));
- }
- }
-
- this.setFirstRecord(firstRec);
- this._resultSetColumns = WizDbManager.getResultSetColumnInfosFrom(resultSet);
- resultSet.close();
- } catch (SQLException e) {
- AspWizardExceptionHandler.showMessage(0, ((Throwable)e).getMessage());
- } catch (EWizDbManager e) {
- AspWizardExceptionHandler.showMessage(0, ((Throwable)e).getMessage());
- }
-
- }
- }
-
- private void setFirstRecord(Vector record) {
- this._firstRecord = record;
- }
-
- public Vector getFirstRecord() {
- return this._firstRecord;
- }
-
- public DefQuery() {
- }
-
- public DefQuery(DefQuery aDefQuery) {
- this._defConnection = aDefQuery._defConnection;
- this._dbConnection = aDefQuery._dbConnection;
- this._usePreviousQuery = aDefQuery._usePreviousQuery;
- this.setEqualSqlStatementTo(aDefQuery);
- }
-
- public void setEqualSqlStatementTo(DefQuery aDefQuery) {
- this._select = aDefQuery._select;
- this._from = aDefQuery._from;
- this._where = aDefQuery._where;
- this._orderBy = aDefQuery._orderBy;
- }
-
- public void setDefConnection(DefConnection defConnection) {
- this._defConnection = defConnection;
- }
-
- public DefConnection getDefConnection() {
- return this._defConnection;
- }
-
- public void setDBConnection(String dbConnection) {
- this._dbConnection = dbConnection;
- }
-
- public void setUsePreviousQuery(int usePreviousQuery) {
- this._usePreviousQuery = usePreviousQuery;
- }
-
- public void setSelect(String select) {
- this._select = select.trim();
- }
-
- public void setFrom(String from) {
- this._from = from.trim();
- }
-
- public void setWhere(String where) {
- this._where = where.trim();
- }
-
- public void setOrderBy(String orderBy) {
- this._orderBy = orderBy.trim();
- }
-
- public int getUsePreviousQuery() {
- return this._usePreviousQuery;
- }
-
- public String getSelect() {
- return this._select;
- }
-
- public String getFrom() {
- return this._from;
- }
-
- public String getWhere() {
- return this._where;
- }
-
- public String getOrderBy() {
- return this._orderBy;
- }
-
- public String getDBConnection() {
- return this._dbConnection;
- }
-
- public String getSql() {
- StringBuffer sb = new StringBuffer();
- if (this.getSelect() != null && !this.getSelect().equals("")) {
- sb.append("SELECT ");
- sb.append(this.getSelect());
- }
-
- if (this.getFrom() != null && !this.getFrom().equals("")) {
- if (sb.length() > 0) {
- sb.append(" ");
- }
-
- sb.append("FROM ");
- sb.append(this.getFrom());
- }
-
- if (this.getWhere() != null && !this.getWhere().equals("")) {
- if (sb.length() > 0) {
- sb.append(" ");
- }
-
- sb.append("WHERE ");
- sb.append(this.getWhere());
- }
-
- if (this.getOrderBy() != null && !this.getOrderBy().equals("")) {
- if (sb.length() > 0) {
- sb.append(" ");
- }
-
- sb.append("ORDER BY ");
- sb.append(this.getOrderBy());
- }
-
- return sb.toString();
- }
-
- public String getBaseName() {
- return "MSDBQuery";
- }
-
- public Vector getResultSetColumnInfos() {
- return this._resultSetColumns;
- }
-
- public boolean equalSqlStatementTo(DefQuery otherQuery) {
- return this._select.equals(otherQuery.getSelect()) && this._from.equals(otherQuery.getFrom()) && this._where.equals(otherQuery.getWhere()) && this._orderBy.equals(otherQuery.getOrderBy());
- }
- }
-