1 /***
2 * The contents of this file are subject to the Mozilla Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/MPL/
6 *
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
11 *
12 * The Original Code is pow2toolkit library.
13 *
14 * The Initial Owner of the Original Code is
15 * Power Of Two S.R.L. (www.pow2.com)
16 *
17 * Portions created by Power Of Two S.R.L. are
18 * Copyright (C) Power Of Two S.R.L.
19 * All Rights Reserved.
20 *
21 * Contributor(s):
22 */
23
24 package com.pow2.dao.datalist;
25
26 import com.pow2.util.Util;
27
28
29
30 /***
31 * Query class
32 *
33 * @author Luca Fossato
34 * @created 7 dicembre 2002
35 */
36 public class Query
37 {
38 private final static char CHAR_BLANK = ' ';
39
40 private String query;
41 private String condition;
42 private String orderBy;
43
44
45 /***
46 * Gets the query attribute of the Query object
47 *
48 * @return The query value
49 */
50 public String getQuery()
51 {
52 return query;
53 }
54
55
56 /***
57 * Sets the query attribute of the Query object
58 *
59 * @param query The new query value
60 */
61 public void setQuery(String query)
62 {
63 this.query = query;
64 }
65
66
67 /***
68 * Sets the condition attribute of the Query object
69 *
70 * @param condition The new condition value
71 */
72 public void setCondition(String condition)
73 {
74 this.condition = condition;
75 }
76
77
78 /***
79 * Gets the condition attribute of the Query object
80 *
81 * @return The condition value
82 */
83 public String getCondition()
84 {
85 return condition;
86 }
87
88
89 /***
90 * Sets the orderBy attribute of the Query object
91 *
92 * @param orderBy The new orderBy value
93 */
94 public void setOrderBy(String orderBy)
95 {
96 this.orderBy = orderBy;
97 }
98
99
100 /***
101 * Gets the orderBy attribute of the Query object
102 *
103 * @return The orderBy value
104 */
105 public String getOrderBy()
106 {
107 return orderBy;
108 }
109
110
111 /***
112 * Get the string representation of the Query class.
113 *
114 * @return the string representation of the Query class
115 */
116 public String toString()
117 {
118 StringBuffer sb = new StringBuffer();
119
120 if (!Util.isNull(query))
121 {
122 sb.append(query.trim()).append(CHAR_BLANK);
123
124 if (!Util.isNull(condition))
125 sb.append("WHERE ").append(condition).append(CHAR_BLANK);
126
127 if (!Util.isNull(orderBy))
128 sb.append("ORDER BY ").append(orderBy);
129 }
130
131 return sb.toString();
132 }
133 }