KickJava   Java API By Example, From Geeks To Geeks.

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


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

32 public abstract class AbstractQueryResult implements QueryResult {
33     
34     protected final Transaction _transaction;
35
36     public AbstractQueryResult(Transaction transaction) {
37         _transaction = transaction;
38     }
39     
40     public final Object JavaDoc activate(Object JavaDoc obj) {
41         stream().activate1(_transaction, obj, config().activationDepth());
42         return obj;
43     }
44
45     public final Object JavaDoc activatedObject(int id) {
46         YapStream stream = stream();
47         Object JavaDoc ret = stream.getActivatedObjectFromCache(_transaction, id);
48         if(ret != null){
49             return ret;
50         }
51         return stream.readActivatedObjectNotInCache(_transaction, id);
52     }
53
54     public Object JavaDoc streamLock() {
55         final YapStream stream = stream();
56         stream.checkClosed();
57         return stream.lock();
58     }
59
60     public YapStream stream() {
61         return _transaction.stream();
62     }
63     
64     public Transaction transaction(){
65         return _transaction;
66     }
67
68     public ExtObjectContainer objectContainer() {
69         return stream();
70     }
71     
72     public Iterator4 iterator() {
73         return new MappingIterator(iterateIDs()){
74             protected Object JavaDoc map(Object JavaDoc current) {
75                 if(current == null){
76                     return MappingIterator.SKIP;
77                 }
78                 synchronized (streamLock()) {
79                     Object JavaDoc obj = activatedObject(((Integer JavaDoc)current).intValue());
80                     if(obj == null){
81                         return MappingIterator.SKIP;
82                     }
83                     return obj;
84                 }
85             }
86         };
87     }
88     
89     public AbstractQueryResult supportSize(){
90         return this;
91     }
92     
93     public AbstractQueryResult supportSort(){
94         return this;
95     }
96     
97     public AbstractQueryResult supportElementAccess(){
98         return this;
99     }
100     
101     protected int knownSize(){
102         return size();
103     }
104     
105     public AbstractQueryResult toIdList(){
106         IdListQueryResult res = new IdListQueryResult(transaction(), knownSize());
107         IntIterator4 i = iterateIDs();
108         while(i.moveNext()){
109             res.add(i.currentInt());
110         }
111         return res;
112     }
113     
114     protected AbstractQueryResult toIdTree(){
115         return new IdTreeQueryResult(transaction(), iterateIDs());
116     }
117     
118     public Config4Impl config(){
119         return stream().config();
120     }
121
122     public int size() {
123         throw new NotImplementedException();
124     }
125
126     public void sort(QueryComparator cmp) {
127         throw new NotImplementedException();
128     }
129
130     public Object JavaDoc get(int index) {
131         throw new NotImplementedException();
132     }
133     
134     public int getId(int i) {
135         throw new NotImplementedException();
136     }
137
138     public int indexOf(int id) {
139         throw new NotImplementedException();
140     }
141
142     public void loadFromClassIndex(YapClass c) {
143         throw new NotImplementedException();
144     }
145
146     public void loadFromClassIndexes(YapClassCollectionIterator i) {
147         throw new NotImplementedException();
148     }
149
150     public void loadFromIdReader(YapReader r) {
151         throw new NotImplementedException();
152     }
153
154     public void loadFromQuery(QQuery q) {
155         throw new NotImplementedException();
156     }
157
158 }
159
Popular Tags