KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > inside > query > HybridQueryResult


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o.inside.query;
22
23 import com.db4o.*;
24 import com.db4o.config.*;
25 import com.db4o.foundation.*;
26 import com.db4o.query.*;
27
28
29 /**
30  * @exclude
31  */

32 public class HybridQueryResult extends AbstractQueryResult {
33     
34     private AbstractQueryResult _delegate;
35     
36     public HybridQueryResult(Transaction transaction, QueryEvaluationMode mode) {
37         super(transaction);
38         _delegate = forMode(transaction, mode);
39     }
40     
41     private static AbstractQueryResult forMode(Transaction transaction, QueryEvaluationMode mode){
42         if(mode == QueryEvaluationMode.LAZY){
43             return new LazyQueryResult(transaction);
44         }
45         if(mode == QueryEvaluationMode.SNAPSHOT){
46             return new SnapShotQueryResult(transaction);
47         }
48         return new IdListQueryResult(transaction);
49     }
50
51     public Object JavaDoc get(int index) {
52         _delegate = _delegate.supportElementAccess();
53         return _delegate.get(index);
54     }
55     
56     public int getId(int index) {
57         _delegate = _delegate.supportElementAccess();
58         return _delegate.getId(index);
59     }
60
61     public int indexOf(int id) {
62         _delegate = _delegate.supportElementAccess();
63         return _delegate.indexOf(id);
64     }
65
66     public IntIterator4 iterateIDs() {
67         return _delegate.iterateIDs();
68     }
69     
70     public Iterator4 iterator() {
71         return _delegate.iterator();
72     }
73
74     public void loadFromClassIndex(YapClass clazz) {
75         _delegate.loadFromClassIndex(clazz);
76     }
77
78     public void loadFromClassIndexes(YapClassCollectionIterator iterator) {
79         _delegate.loadFromClassIndexes(iterator);
80     }
81
82     public void loadFromIdReader(YapReader reader) {
83         _delegate.loadFromIdReader(reader);
84     }
85
86     public void loadFromQuery(QQuery query) {
87         if(query.requiresSort()){
88             _delegate = new IdListQueryResult(transaction());
89         }
90         _delegate.loadFromQuery(query);
91     }
92
93     public int size() {
94         _delegate = _delegate.supportSize();
95         return _delegate.size();
96     }
97
98     public void sort(QueryComparator cmp) {
99         _delegate = _delegate.supportSort();
100         _delegate.sort(cmp);
101     }
102
103 }
104
Popular Tags