KickJava   Java API By Example, From Geeks To Geeks.

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


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
20 package org.apache.cayenne.remote;
21
22 import org.apache.cayenne.map.DataMap;
23 import org.apache.cayenne.map.DbEntity;
24 import org.apache.cayenne.map.EntityResolver;
25 import org.apache.cayenne.map.ObjEntity;
26 import org.apache.cayenne.map.Procedure;
27 import org.apache.cayenne.query.PrefetchTreeNode;
28 import org.apache.cayenne.query.Query;
29 import org.apache.cayenne.query.QueryMetadata;
30 import org.apache.cayenne.query.QueryRouter;
31 import org.apache.cayenne.query.SQLAction;
32 import org.apache.cayenne.query.SQLActionVisitor;
33 import org.apache.cayenne.query.SQLResultSetMapping;
34 import org.apache.cayenne.reflect.ClassDescriptor;
35
36 /**
37  * A client wrapper for the incremental query that overrides the metadata to ensure that
38  * query result is cached on the server, so that subranges could be retrieved at a later
39  * time.
40  *
41  * @since 1.2
42  * @author Andrus Adamchik
43  */

44 class IncrementalQuery implements Query {
45
46     private Query query;
47     private String JavaDoc cacheKey;
48
49     IncrementalQuery(Query query, String JavaDoc cacheKey) {
50         this.query = query;
51         this.cacheKey = cacheKey;
52     }
53
54     public QueryMetadata getMetaData(EntityResolver resolver) {
55         final QueryMetadata metadata = query.getMetaData(resolver);
56
57         // the way paginated queries work on the server is that they are never cached
58
// (IncrementalFaultList interception happens before cache interception). So
59
// overriding caching settings in the metadata will only affect
60
// ClientServerChannel behavior
61

62         return new QueryMetadata() {
63
64             public String JavaDoc getCacheKey() {
65                 return cacheKey;
66             }
67             
68             public SQLResultSetMapping getResultSetMapping() {
69                 return metadata.getResultSetMapping();
70             }
71             
72             public String JavaDoc[] getCacheGroups() {
73                 return metadata.getCacheGroups();
74             }
75
76             public String JavaDoc getCachePolicy() {
77                 return metadata.getCachePolicy();
78             }
79
80             public DataMap getDataMap() {
81                 return metadata.getDataMap();
82             }
83
84             public DbEntity getDbEntity() {
85                 return metadata.getDbEntity();
86             }
87
88             public int getFetchLimit() {
89                 return metadata.getFetchLimit();
90             }
91
92             public int getFetchStartIndex() {
93                 return metadata.getFetchStartIndex();
94             }
95
96             public ObjEntity getObjEntity() {
97                 return metadata.getObjEntity();
98             }
99             
100             public ClassDescriptor getClassDescriptor() {
101                 return metadata.getClassDescriptor();
102             }
103
104             public int getPageSize() {
105                 return metadata.getPageSize();
106             }
107
108             public PrefetchTreeNode getPrefetchTree() {
109                 return metadata.getPrefetchTree();
110             }
111
112             public Procedure getProcedure() {
113                 return metadata.getProcedure();
114             }
115
116             public boolean isFetchingDataRows() {
117                 return metadata.isFetchingDataRows();
118             }
119
120             public boolean isRefreshingObjects() {
121                 return metadata.isRefreshingObjects();
122             }
123
124             public boolean isResolvingInherited() {
125                 return metadata.isResolvingInherited();
126             }
127         };
128     }
129
130     public void route(QueryRouter router, EntityResolver resolver, Query substitutedQuery) {
131         query.route(router, resolver, substitutedQuery);
132     }
133
134     public SQLAction createSQLAction(SQLActionVisitor visitor) {
135         return query.createSQLAction(visitor);
136     }
137
138     public String JavaDoc getName() {
139         return query.getName();
140     }
141 }
142
Popular Tags