KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > inside > cluster > ClusterQueryResult


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.cluster;
22
23 import com.db4o.*;
24 import com.db4o.cluster.*;
25 import com.db4o.ext.*;
26 import com.db4o.foundation.*;
27 import com.db4o.inside.query.*;
28 import com.db4o.query.*;
29
30 /**
31  *
32  * @exclude
33  */

34 public class ClusterQueryResult implements QueryResult {
35     
36     private final Cluster _cluster;
37     private final ObjectSet[] _objectSets;
38     private final int[] _sizes;
39     private final int _size;
40     
41     public ClusterQueryResult(Cluster cluster, Query[] queries){
42         _cluster = cluster;
43         _objectSets = new ObjectSet[queries.length];
44         _sizes = new int[queries.length];
45         int size = 0;
46         for (int i = 0; i < queries.length; i++) {
47             _objectSets[i] = queries[i].execute();
48             _sizes[i] = _objectSets[i].size();
49             size += _sizes[i];
50         }
51         _size = size;
52     }
53     
54     private static final class ClusterQueryResultIntIterator implements IntIterator4 {
55
56         private final CompositeIterator4 _delegate;
57
58         public ClusterQueryResultIntIterator(Iterator4[] iterators) {
59             _delegate = new CompositeIterator4(iterators);
60         }
61
62         public boolean moveNext() {
63             return _delegate.moveNext();
64         }
65
66         public Object JavaDoc current() {
67             return _delegate.current();
68         }
69         
70         public void reset() {
71             _delegate.reset();
72         }
73
74         public int currentInt() {
75             return ((IntIterator4)_delegate.currentIterator()).currentInt();
76         }
77     }
78     
79     public IntIterator4 iterateIDs() {
80         synchronized(_cluster) {
81             final Iterator4[] iterators = new Iterator4[_objectSets.length];
82             for (int i = 0; i < _objectSets.length; i++) {
83                 iterators[i] = ((ObjectSetFacade)_objectSets[i])._delegate.iterateIDs();
84             }
85             return new ClusterQueryResultIntIterator(iterators);
86         }
87     }
88     
89     public Iterator4 iterator() {
90         synchronized(_cluster) {
91             Iterator4[] iterators = new Iterator4[_objectSets.length];
92             for (int i = 0; i < _objectSets.length; i++) {
93                 iterators[i] = ((ObjectSetFacade)_objectSets[i])._delegate.iterator();
94             }
95             return new CompositeIterator4(iterators);
96         }
97     }
98
99     public int size() {
100         return _size;
101     }
102     
103     public Object JavaDoc get(int index) {
104         synchronized(_cluster){
105             if (index < 0 || index >= size()) {
106                 throw new IndexOutOfBoundsException JavaDoc();
107             }
108             int i = 0;
109             while(index >= _sizes[i]){
110                 index -= _sizes[i];
111                 i++;
112             }
113             return ((ObjectSetFacade)_objectSets[i]).get(index);
114         }
115     }
116
117     public Object JavaDoc streamLock() {
118         return _cluster;
119     }
120
121     public ExtObjectContainer objectContainer() {
122         throw new NotSupportedException();
123     }
124
125     public int indexOf(int id) {
126         throw new NotSupportedException();
127     }
128
129     public void sort(QueryComparator cmp) {
130         throw new NotSupportedException();
131     }
132
133     public void loadFromClassIndex(YapClass c) {
134         throw new NotSupportedException();
135     }
136
137     public void loadFromQuery(QQuery q) {
138         throw new NotSupportedException();
139     }
140
141     public void loadFromClassIndexes(YapClassCollectionIterator i) {
142         throw new NotSupportedException();
143     }
144
145     public void loadFromIdReader(YapReader r) {
146         throw new NotSupportedException();
147     }
148 }
149
150
Popular Tags