01: /*
02: * SQLeonardo :: java database frontend
03: * Copyright (C) 2004 nickyb@users.sourceforge.net
04: *
05: * This program is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU General Public License
07: * as published by the Free Software Foundation; either version 2
08: * of the License, or (at your option) any later version.
09: *
10: * This program is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: * GNU General Public License for more details.
14: *
15: * You should have received a copy of the GNU General Public License
16: * along with this program; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18: *
19: */
20:
21: package nickyb.sqleonardo.querybuilder;
22:
23: import java.util.ArrayList;
24:
25: import nickyb.sqleonardo.querybuilder.syntax.QueryExpression;
26: import nickyb.sqleonardo.querybuilder.syntax.QueryTokens;
27: import nickyb.sqleonardo.querybuilder.syntax.SQLFormatter;
28: import nickyb.sqleonardo.querybuilder.syntax._ReservedWords;
29:
30: public class QueryModel {
31: private QueryExpression queryExpression;
32: private ArrayList orderClause;
33:
34: private String schema;
35:
36: public QueryModel() {
37: this (null);
38: }
39:
40: public QueryModel(String schema) {
41: this .schema = schema;
42:
43: queryExpression = new QueryExpression();
44: orderClause = new ArrayList();
45: }
46:
47: public String getSchema() {
48: return schema == null ? null : new String(schema);
49: }
50:
51: public void setSchema(String schema) {
52: this .schema = schema;
53: }
54:
55: public void addOrderByClause(QueryTokens.Sort token) {
56: orderClause.add(token);
57: }
58:
59: public QueryTokens.Sort[] getOrderByClause() {
60: QueryTokens.Sort[] a = new QueryTokens.Sort[orderClause.size()];
61: return (QueryTokens.Sort[]) orderClause.toArray(a);
62: }
63:
64: public void removeOrderByClause(QueryTokens.Sort token) {
65: orderClause.remove(token);
66: }
67:
68: public QueryExpression getQueryExpression() {
69: return queryExpression;
70: }
71:
72: public void setQueryExpression(QueryExpression qe) {
73: queryExpression = qe;
74: }
75:
76: public String toString(boolean wrap) {
77: String syntax = queryExpression.toString(wrap);
78:
79: if (orderClause.size() > 0)
80: syntax = syntax
81: + (wrap ? SQLFormatter.BREAK : SQLFormatter.SPACE)
82: + _ReservedWords.ORDER_BY
83: + (wrap ? SQLFormatter.BREAK : SQLFormatter.SPACE)
84: + SQLFormatter
85: .concat(this .getOrderByClause(), wrap);
86:
87: return syntax;
88: }
89:
90: public String toString() {
91: return toString(false);
92: }
93: }
|