1 package org.apache.ojb.broker.query;
2
3 /* Copyright 2002-2005 The Apache Software Foundation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 import java.util.Map;
19
20 /**
21 * Query for Reports.
22 * Supports selection of a subset of attributes.
23 *
24 * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
25 * @version $Id: ReportQueryByCriteria.java,v 1.1 2007-08-24 22:17:36 ewestfal Exp $
26 */
27 public class ReportQueryByCriteria extends QueryByCriteria implements ReportQuery
28 {
29 // define the attributes (columns) to be selected for reports
30 private String[] m_attributes = null;
31
32 // define the Jdbc-Types of the columns to be selected for reports
33 private int[] m_jdbcTypes = null;
34
35 // define the additional attributes (columns) to be used for the join
36 private String[] m_joinAttributes = null;
37
38 // attribute -> FieldDescriptor
39 private Map m_attrToFld = null;
40
41 /**
42 * Constructor for ReportQueryByCriteria.
43 * @param targetClass
44 * @param attributes[]
45 * @param criteria
46 * @param distinct
47 */
48 public ReportQueryByCriteria(Class targetClass, String[] attributes, Criteria criteria, boolean distinct)
49 {
50 super(targetClass, criteria, distinct);
51 setAttributes(attributes);
52 }
53
54 /**
55 * Constructor for ReportQueryByCriteria.
56 * @param targetClass
57 * @param attributes[]
58 * @param criteria
59 */
60 public ReportQueryByCriteria(Class targetClass, String[] attributes, Criteria criteria)
61 {
62 this(targetClass, attributes, criteria, false);
63 }
64
65 /**
66 * Constructor for ReportQueryByCriteria.
67 * @param targetClass
68 * @param criteria
69 */
70 public ReportQueryByCriteria(Class targetClass, Criteria criteria)
71 {
72 this(targetClass, null, criteria, false);
73 }
74
75 /**
76 * Constructor for ReportQueryByCriteria.
77 * @param targetClass
78 * @param criteria
79 * @param distinct
80 */
81 public ReportQueryByCriteria(Class targetClass, Criteria criteria, boolean distinct)
82 {
83 this(targetClass, null, criteria, distinct);
84 }
85
86 /**
87 * Gets the columns.
88 * @return Returns a String[]
89 * @deprecated use getAttributes()
90 */
91 public String[] getColumns()
92 {
93 return getAttributes();
94 }
95
96 /**
97 * Sets the columns.
98 * @param columns The columns to set
99 * @deprecated use setAttributes()
100 */
101 public void setColumns(String[] columns)
102 {
103 setAttributes(columns);
104 }
105
106 /**
107 * Gets the attributes to be selected.</br>
108 * Attributes are translated into db-columns
109 * @return the attributes to be selected
110 */
111 public String[] getAttributes()
112 {
113 return m_attributes;
114 }
115
116 /**
117 * Sets the attributes to be selected.</br>
118 * Attributes are translated into db-columns
119 * @param attributes The attributes to set
120 */
121 public void setAttributes(String[] attributes)
122 {
123 m_attributes = attributes;
124 }
125
126 /**
127 * @return Returns the jdbcTypes.
128 */
129 public int[] getJdbcTypes()
130 {
131 return m_jdbcTypes;
132 }
133
134 /**
135 * @param jdbcTypes The jdbcTypes to set.
136 */
137 public void setJdbcTypes(int[] jdbcTypes)
138 {
139 this.m_jdbcTypes = jdbcTypes;
140 }
141
142 /**
143 * @return Returns the joinAttributes.
144 */
145 public String[] getJoinAttributes()
146 {
147 return m_joinAttributes;
148 }
149
150 /**
151 * @param joinAttributes The joinAttributes to set.
152 */
153 public void setJoinAttributes(String[] joinAttributes)
154 {
155 m_joinAttributes = joinAttributes;
156 }
157
158 /**
159 * @see java.lang.Object#toString()
160 */
161 public String toString()
162 {
163 String[] cols = getAttributes();
164 StringBuffer buf = new StringBuffer("ReportQuery from ");
165 buf.append(getSearchClass() + " ");
166 if (cols != null)
167 {
168 for (int i = 0; i < cols.length; i++)
169 {
170 buf.append(cols[i] + " ");
171 }
172 }
173 if (getCriteria() != null && !getCriteria().isEmpty())
174 {
175 buf.append(" where " + getCriteria());
176 }
177
178 return buf.toString();
179 }
180
181 public Map getAttributeFieldDescriptors()
182 {
183 return m_attrToFld;
184 }
185
186 public void setAttributeFieldDescriptors(Map attrToFld)
187 {
188 m_attrToFld = attrToFld;
189 }
190
191
192
193 }