01: //This class access the private class QueryCacheStoreQuery.
02: //So this has to be in kodo.datacache package
03: /*
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
20: */
21: package org.apache.openjpa.persistence.datacache;
22:
23: import java.util.Collections;
24: import java.util.List;
25:
26: import org.apache.openjpa.datacache.QueryCacheStoreQuery.CachedList;
27: import org.apache.openjpa.kernel.Broker;
28: import org.apache.openjpa.kernel.BrokerImpl;
29: import org.apache.openjpa.kernel.QueryImpl;
30: import org.apache.openjpa.kernel.StoreQuery;
31: import org.apache.openjpa.lib.rop.ListResultList;
32: import org.apache.openjpa.lib.rop.ListResultObjectProvider;
33: import org.apache.openjpa.lib.rop.ResultObjectProvider;
34:
35: /**
36: * <p>
37: * Used to mark cached query results for testing.
38: * </p>
39: */
40: public class CacheTestBroker extends BrokerImpl {
41:
42: protected QueryImpl newQueryImpl(String language, StoreQuery sq) {
43: return new CacheTestQuery(this , language, sq);
44: }
45:
46: public static class CachedQueryResult extends ListResultList {
47:
48: public CachedQueryResult(List list) {
49: super (list);
50: }
51: }
52:
53: private static class CacheTestQuery extends QueryImpl {
54:
55: public CacheTestQuery(Broker broker, String language,
56: StoreQuery query) {
57: super (broker, language, query);
58: }
59:
60: protected Object toResult(StoreQuery q, StoreQuery.Executor ex,
61: ResultObjectProvider rop, StoreQuery.Range range)
62: throws Exception {
63: boolean cached = rop instanceof ListResultObjectProvider
64: && (((ListResultObjectProvider) rop).getDelegate() instanceof CachedList || ((ListResultObjectProvider) rop)
65: .getDelegate() == Collections.EMPTY_LIST);
66: Object res = super .toResult(q, ex, rop, range);
67: if (cached && res instanceof List)
68: return new CachedQueryResult((List) res);
69: return res;
70: }
71: }
72: }
|