001: /*
002: * JFolder, Copyright 2001-2006 Gary Steinmetz
003: *
004: * Distributable under LGPL license.
005: * See terms of license at gnu.org.
006: */
007:
008: package org.jfolder.platforms.stores.base;
009:
010: //base classes
011: import java.math.BigDecimal;
012: import java.sql.PreparedStatement;
013: import java.sql.ResultSet;
014: import java.sql.SQLException;
015: import java.util.ArrayList;
016: import java.util.HashSet;
017: import java.util.Iterator;
018:
019: //project specific classes
020: import org.jfolder.platforms.stores.base.SystemStatement;
021:
022: //other classes
023:
024: public class SelectStatement extends WhereStatement {
025:
026: //
027: private ArrayList selectColumnNames = null;
028: private ArrayList selectColumnTypes = null;
029: private ArrayList selectColumnTables = null;
030: private ArrayList selectColumnQuantifiers = null;
031: //
032: private HashSet selectColumnTablesSet = null;
033:
034: //
035: private boolean lastSeriesSequenceOnly = false;
036:
037: //
038: private ArrayList groupByColumnNames = null;
039: private ArrayList groupByColumnTypes = null;
040: private ArrayList groupByColumnTables = null;
041:
042: //
043: private String orderByName = null;
044: private Integer orderByType = null;
045: private CreateStatement orderByTable = null;
046:
047: //
048: private boolean listOrderAscending = false;
049:
050: //
051: private int startRow = 0;
052: private int querySize = 0;
053:
054: //
055: private SystemResultSet results = null;
056:
057: //
058: //private WorkflowResultSet wrs = null;
059:
060: public final static SelectStatement createOrderByColumn(
061: String inName, CreateStatement inTable, Integer inQuantifier) {
062:
063: return new SelectStatement(inName, NORMAL_COLUMN, inTable,
064: inQuantifier);
065: }
066:
067: public final static SelectStatement createOrderById(
068: CreateStatement inTable, Integer inQuantifier) {
069:
070: return new SelectStatement(null, ID_COLUMN, inTable,
071: inQuantifier);
072: }
073:
074: public final static SelectStatement createOrderBySeriesSequence(
075: CreateStatement inTable, Integer inQuantifier) {
076:
077: return new SelectStatement(null, SERIES_SEQUENCE_COLUMN,
078: inTable, inQuantifier);
079: }
080:
081: private SelectStatement(String inName, Integer inType,
082: CreateStatement inTable, Integer inQuantifier) {
083: //
084: this .selectColumnNames = new ArrayList();
085: this .selectColumnTypes = new ArrayList();
086: this .selectColumnTables = new ArrayList();
087: this .selectColumnQuantifiers = new ArrayList();
088: //
089: this .selectColumnTablesSet = new HashSet();
090:
091: //
092: this .groupByColumnNames = new ArrayList();
093: this .groupByColumnTypes = new ArrayList();
094: this .groupByColumnTables = new ArrayList();
095:
096: //
097: this .lastSeriesSequenceOnly = true;
098:
099: //
100: this .listOrderAscending = true;
101:
102: //
103: this .startRow = 0;
104: this .querySize = 1000;
105:
106: //init
107: addSelectColumn(inName, inType, inTable, inQuantifier);
108: //
109: this .orderByName = inName;
110: this .orderByType = inType;
111: this .orderByTable = inTable;
112: }
113:
114: public void addSelectColumn(String inName, CreateStatement inTable,
115: Integer inQuantifier) {
116: addSelectColumn(inName, NORMAL_COLUMN, inTable, inQuantifier);
117: }
118:
119: public void addSelectIdColumn(CreateStatement inTable,
120: Integer inQuantifier) {
121: addSelectColumn(null, ID_COLUMN, inTable, inQuantifier);
122: }
123:
124: public void addSelectSeriesSequenceColumn(CreateStatement inTable,
125: Integer inQuantifier) {
126: addSelectColumn(null, SERIES_SEQUENCE_COLUMN, inTable,
127: inQuantifier);
128: }
129:
130: //
131: private void addSelectColumn(String inName, Integer inType,
132: CreateStatement inTable, Integer inQuantifier) {
133: //
134: this .selectColumnNames.add(inName);
135: this .selectColumnTypes.add(inType);
136: this .selectColumnTables.add(inTable);
137: this .selectColumnQuantifiers.add(inQuantifier);
138: //
139: this .selectColumnTablesSet.add(inTable);
140: //
141: addToAllTables(inTable);
142: }
143:
144: //
145: public int getSelectColumnCount() {
146: return this .selectColumnNames.size();
147: }
148:
149: public String getSelectColumnName(int inIndex) {
150: return (String) this .selectColumnNames.get(inIndex);
151: }
152:
153: public Integer getSelectColumnMetaType(int inIndex) {
154: return (Integer) this .selectColumnTypes.get(inIndex);
155: }
156:
157: public CreateStatement getSelectColumnTable(int inIndex) {
158: return (CreateStatement) this .selectColumnTables.get(inIndex);
159: }
160:
161: public Integer getSelectColumnQuantifier(int inIndex) {
162: return (Integer) this .selectColumnQuantifiers.get(inIndex);
163: }
164:
165: //
166: public void addGroupByColumn(String inName, Integer inType,
167: CreateStatement inTable) {
168:
169: this .groupByColumnNames.add(inName);
170: this .groupByColumnTypes.add(inType);
171: this .groupByColumnTables.add(inTable);
172: //
173: addToAllTables(inTable);
174: }
175:
176: public int getGroupByColumnCount() {
177: return this .groupByColumnNames.size();
178: }
179:
180: public String getGroupByColumnName(int inIndex) {
181: return (String) this .groupByColumnNames.get(inIndex);
182: }
183:
184: public Integer getGroupByColumnType(int inIndex) {
185: return (Integer) this .groupByColumnTypes.get(inIndex);
186: }
187:
188: public CreateStatement getGroupByColumnTable(int inIndex) {
189: return (CreateStatement) this .groupByColumnTables.get(inIndex);
190: }
191:
192: //
193: public void setLastSeriesSequenceOnly(
194: boolean inLastSeriesSequenceOnly) {
195: this .lastSeriesSequenceOnly = inLastSeriesSequenceOnly;
196: }
197:
198: public boolean isLastSeriesSequenceOnly() {
199: return this .lastSeriesSequenceOnly;
200: }
201:
202: //
203: public void setListOrderAscending(boolean inListOrderAscending) {
204: this .listOrderAscending = inListOrderAscending;
205: }
206:
207: public boolean isListOrderAscending() {
208: return this .listOrderAscending;
209: }
210:
211: //
212: public void setStartRow(int inStartRow) {
213: this .startRow = inStartRow;
214: }
215:
216: public int getStartRow() {
217: return this .startRow;
218: }
219:
220: //
221: public void setQuerySize(int inQuerySize) {
222: this .querySize = inQuerySize;
223: }
224:
225: public int getQuerySize() {
226: return this .querySize;
227: }
228:
229: //
230: public void setResults(SystemResultSet inWrs) {
231: this .results = inWrs;
232: }
233:
234: public SystemResultSet getResults() {
235: return this .results;
236: }
237:
238: //
239: public String getOrderByName() {
240: return this .orderByName;
241: }
242:
243: public Integer getOrderByType() {
244: return this .orderByType;
245: }
246:
247: public CreateStatement getOrderByTable() {
248: return this .orderByTable;
249: }
250:
251: //
252: //public void setWorkflowResultSet(WorkflowResultSet inWrs) {
253: // this.wrs = inWrs;
254: //}
255: //public WorkflowResultSet getWorkflowResultSet() {
256: // return this.wrs;
257: //}
258: }
|