KickJava   Java API By Example, From Geeks To Geeks.

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


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.ext.*;
24 import com.db4o.foundation.*;
25 import com.db4o.query.QueryComparator;
26
27 /**
28  * @exclude
29  */

30 public class StatefulQueryResult {
31     
32     private final QueryResult _delegate;
33     private final Iterable4Adaptor _iterable;
34     
35     public StatefulQueryResult(QueryResult queryResult){
36         _delegate = queryResult;
37         _iterable = new Iterable4Adaptor(queryResult);
38     }
39
40     public Object JavaDoc get(int index) {
41         return _delegate.get(index);
42     }
43     
44     public long[] getIDs() {
45         long[] ids = new long[size()];
46         int i = 0;
47         final IntIterator4 iterator = _delegate.iterateIDs();
48         while (iterator.moveNext()) {
49             ids[i++] = iterator.currentInt();
50         }
51         return ids;
52     }
53
54     public boolean hasNext() {
55         return _iterable.hasNext();
56     }
57
58     public Object JavaDoc next() {
59         return _iterable.next();
60     }
61
62     public void reset() {
63         _iterable.reset();
64     }
65
66     public int size() {
67         return _delegate.size();
68     }
69
70     public void sort(QueryComparator cmp) {
71         _delegate.sort(cmp);
72     }
73         
74     Object JavaDoc streamLock() {
75         // used on the .net version
76
return objectContainer().lock();
77     }
78     
79     ExtObjectContainer objectContainer() {
80         return _delegate.objectContainer();
81     }
82     
83     public int indexOf(Object JavaDoc a_object) {
84         synchronized(streamLock()){
85             int id = (int)objectContainer().getID(a_object);
86             if(id <= 0){
87                 return -1;
88             }
89             return _delegate.indexOf(id);
90         }
91     }
92
93     public Iterator4 iterateIDs() {
94         return _delegate.iterateIDs();
95     }
96
97     public Iterator4 iterator() {
98         return _delegate.iterator();
99     }
100 }
101
Popular Tags