KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > remote > IncrementalSelectQuery


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  ****************************************************************/

19 package org.apache.cayenne.remote;
20
21 import java.util.List JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import org.apache.cayenne.access.IncrementalFaultList;
25 import org.apache.cayenne.exp.Expression;
26 import org.apache.cayenne.map.DataMap;
27 import org.apache.cayenne.map.DbEntity;
28 import org.apache.cayenne.map.EntityResolver;
29 import org.apache.cayenne.map.ObjEntity;
30 import org.apache.cayenne.map.Procedure;
31 import org.apache.cayenne.query.Ordering;
32 import org.apache.cayenne.query.PrefetchTreeNode;
33 import org.apache.cayenne.query.Query;
34 import org.apache.cayenne.query.QueryMetadata;
35 import org.apache.cayenne.query.QueryRouter;
36 import org.apache.cayenne.query.SQLAction;
37 import org.apache.cayenne.query.SQLActionVisitor;
38 import org.apache.cayenne.query.SQLResultSetMapping;
39 import org.apache.cayenne.query.SelectQuery;
40 import org.apache.cayenne.reflect.ClassDescriptor;
41 import org.apache.cayenne.util.XMLEncoder;
42
43 /**
44  * A SelectQuery decorator that overrides the metadata to ensure that query result is
45  * cached on the server, so that subranges could be retrieved at a later time. Note that a
46  * special decorator that is a subclass of SelectQuery is needed so that
47  * {@link IncrementalFaultList} on the server-side could apply SelectQuery-specific
48  * optimizations.
49  *
50  * @since 3.0
51  * @author Andrus Adamchik
52  */

53 class IncrementalSelectQuery extends SelectQuery {
54
55     private SelectQuery query;
56     private String JavaDoc cacheKey;
57
58     IncrementalSelectQuery(SelectQuery delegate, String JavaDoc cacheKey) {
59         this.query = delegate;
60         this.cacheKey = cacheKey;
61     }
62
63     public QueryMetadata getMetaData(EntityResolver resolver) {
64         final QueryMetadata metadata = query.getMetaData(resolver);
65
66         // the way paginated queries work on the server is that they are never cached
67
// (IncrementalFaultList interception happens before cache interception). So
68
// overriding caching settings in the metadata will only affect
69
// ClientServerChannel behavior
70

71         return new QueryMetadata() {
72
73             public String JavaDoc getCacheKey() {
74                 return cacheKey;
75             }
76
77             public SQLResultSetMapping getResultSetMapping() {
78                 return metadata.getResultSetMapping();
79             }
80
81             public String JavaDoc[] getCacheGroups() {
82                 return metadata.getCacheGroups();
83             }
84
85             public String JavaDoc getCachePolicy() {
86                 return metadata.getCachePolicy();
87             }
88
89             public DataMap getDataMap() {
90                 return metadata.getDataMap();
91             }
92
93             public DbEntity getDbEntity() {
94                 return metadata.getDbEntity();
95             }
96
97             public int getFetchLimit() {
98                 return metadata.getFetchLimit();
99             }
100
101             public int getFetchStartIndex() {
102                 return metadata.getFetchStartIndex();
103             }
104
105             public ObjEntity getObjEntity() {
106                 return metadata.getObjEntity();
107             }
108
109             public ClassDescriptor getClassDescriptor() {
110                 return metadata.getClassDescriptor();
111             }
112
113             public int getPageSize() {
114                 return metadata.getPageSize();
115             }
116
117             public PrefetchTreeNode getPrefetchTree() {
118                 return metadata.getPrefetchTree();
119             }
120
121             public Procedure getProcedure() {
122                 return metadata.getProcedure();
123             }
124
125             public boolean isFetchingDataRows() {
126                 return metadata.isFetchingDataRows();
127             }
128
129             public boolean isRefreshingObjects() {
130                 return metadata.isRefreshingObjects();
131             }
132
133             public boolean isResolvingInherited() {
134                 return metadata.isResolvingInherited();
135             }
136         };
137     }
138
139     public void addCustomDbAttribute(String JavaDoc attributePath) {
140         query.addCustomDbAttribute(attributePath);
141     }
142
143     public void addCustomDbAttributes(List JavaDoc attrPaths) {
144         query.addCustomDbAttributes(attrPaths);
145     }
146
147     public void addOrdering(Ordering ordering) {
148         query.addOrdering(ordering);
149     }
150
151     public void addOrdering(String JavaDoc sortPathSpec, boolean isAscending, boolean ignoreCase) {
152         query.addOrdering(sortPathSpec, isAscending, ignoreCase);
153     }
154
155     public void addOrdering(String JavaDoc sortPathSpec, boolean isAscending) {
156         query.addOrdering(sortPathSpec, isAscending);
157     }
158
159     public void addOrderings(List JavaDoc orderings) {
160         query.addOrderings(orderings);
161     }
162
163     public PrefetchTreeNode addPrefetch(String JavaDoc prefetchPath) {
164         return query.addPrefetch(prefetchPath);
165     }
166
167     public void andParentQualifier(Expression e) {
168         query.andParentQualifier(e);
169     }
170
171     public void andQualifier(Expression e) {
172         query.andQualifier(e);
173     }
174
175     public void clearOrderings() {
176         query.clearOrderings();
177     }
178
179     public void clearPrefetches() {
180         query.clearPrefetches();
181     }
182
183     public Query createQuery(Map JavaDoc parameters) {
184         return query.createQuery(parameters);
185     }
186
187     public SQLAction createSQLAction(SQLActionVisitor visitor) {
188         return query.createSQLAction(visitor);
189     }
190
191     public void encodeAsXML(XMLEncoder encoder) {
192         query.encodeAsXML(encoder);
193     }
194
195     public boolean equals(Object JavaDoc obj) {
196         return query.equals(obj);
197     }
198
199     public String JavaDoc[] getCacheGroups() {
200         return query.getCacheGroups();
201     }
202
203     public String JavaDoc getCachePolicy() {
204         return query.getCachePolicy();
205     }
206
207     public List JavaDoc getCustomDbAttributes() {
208         return query.getCustomDbAttributes();
209     }
210
211     public int getFetchLimit() {
212         return query.getFetchLimit();
213     }
214
215     public String JavaDoc getName() {
216         return query.getName();
217     }
218
219     public List JavaDoc getOrderings() {
220         return query.getOrderings();
221     }
222
223     public int getPageSize() {
224         return query.getPageSize();
225     }
226
227     public String JavaDoc getParentObjEntityName() {
228         return query.getParentObjEntityName();
229     }
230
231     public Expression getParentQualifier() {
232         return query.getParentQualifier();
233     }
234
235     public PrefetchTreeNode getPrefetchTree() {
236         return query.getPrefetchTree();
237     }
238
239     public Expression getQualifier() {
240         return query.getQualifier();
241     }
242
243     public Object JavaDoc getRoot() {
244         return query.getRoot();
245     }
246
247     public int hashCode() {
248         return query.hashCode();
249     }
250
251     public void initWithProperties(Map JavaDoc properties) {
252         query.initWithProperties(properties);
253     }
254
255     public boolean isDistinct() {
256         return query.isDistinct();
257     }
258
259     public boolean isFetchingCustomAttributes() {
260         return query.isFetchingCustomAttributes();
261     }
262
263     public boolean isFetchingDataRows() {
264         return query.isFetchingDataRows();
265     }
266
267     public boolean isQualifiedOnParent() {
268         return query.isQualifiedOnParent();
269     }
270
271     public boolean isRefreshingObjects() {
272         return query.isRefreshingObjects();
273     }
274
275     public boolean isResolvingInherited() {
276         return query.isResolvingInherited();
277     }
278
279     public void orParentQualifier(Expression e) {
280         query.orParentQualifier(e);
281     }
282
283     public void orQualifier(Expression e) {
284         query.orQualifier(e);
285     }
286
287     public SelectQuery queryWithParameters(Map JavaDoc parameters, boolean pruneMissing) {
288         return query.queryWithParameters(parameters, pruneMissing);
289     }
290
291     public SelectQuery queryWithParameters(Map JavaDoc parameters) {
292         return query.queryWithParameters(parameters);
293     }
294
295     public void removeOrdering(Ordering ordering) {
296         query.removeOrdering(ordering);
297     }
298
299     public void removePrefetch(String JavaDoc prefetchPath) {
300         query.removePrefetch(prefetchPath);
301     }
302
303     public void route(QueryRouter router, EntityResolver resolver, Query substitutedQuery) {
304         query.route(router, resolver, substitutedQuery);
305     }
306
307     public void setCacheGroups(String JavaDoc[] cachGroups) {
308         query.setCacheGroups(cachGroups);
309     }
310
311     public void setCachePolicy(String JavaDoc policy) {
312         query.setCachePolicy(policy);
313     }
314
315     public void setDistinct(boolean distinct) {
316         query.setDistinct(distinct);
317     }
318
319     public void setFetchingDataRows(boolean flag) {
320         query.setFetchingDataRows(flag);
321     }
322
323     public void setFetchLimit(int fetchLimit) {
324         query.setFetchLimit(fetchLimit);
325     }
326
327     public void setName(String JavaDoc name) {
328         query.setName(name);
329     }
330
331     public void setPageSize(int pageSize) {
332         query.setPageSize(pageSize);
333     }
334
335     public void setParentObjEntityName(String JavaDoc parentObjEntityName) {
336         query.setParentObjEntityName(parentObjEntityName);
337     }
338
339     public void setParentQualifier(Expression parentQualifier) {
340         query.setParentQualifier(parentQualifier);
341     }
342
343     public void setPrefetchTree(PrefetchTreeNode prefetchTree) {
344         query.setPrefetchTree(prefetchTree);
345     }
346
347     public void setQualifier(Expression qualifier) {
348         query.setQualifier(qualifier);
349     }
350
351     public void setRefreshingObjects(boolean flag) {
352         query.setRefreshingObjects(flag);
353     }
354
355     public void setResolvingInherited(boolean b) {
356         query.setResolvingInherited(b);
357     }
358
359     public void setRoot(Object JavaDoc value) {
360         query.setRoot(value);
361     }
362
363     public String JavaDoc toString() {
364         return query.toString();
365     }
366 }
367
Popular Tags