KickJava   Java API By Example, From Geeks To Geeks.

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


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

32 public abstract class AbstractLateQueryResult extends AbstractQueryResult {
33     
34     protected Iterable4 _iterable;
35
36     public AbstractLateQueryResult(Transaction transaction) {
37         super(transaction);
38     }
39     
40     public AbstractQueryResult supportSize(){
41         return toIdTree();
42     }
43     
44     public AbstractQueryResult supportSort(){
45         return toIdList();
46     }
47     
48     public AbstractQueryResult supportElementAccess(){
49         return toIdList();
50     }
51     
52     protected int knownSize(){
53         return 0;
54     }
55     
56     public IntIterator4 iterateIDs() {
57         if(_iterable == null){
58             throw new IllegalStateException JavaDoc();
59         }
60         return new IntIterator4Adaptor(_iterable);
61     }
62     
63     public AbstractQueryResult toIdList(){
64         return toIdTree().toIdList();
65     }
66
67     public boolean skipClass(YapClass yapClass){
68         if (yapClass.getName() == null) {
69             return true;
70         }
71         ReflectClass claxx = yapClass.classReflector();
72         if (stream().i_handlers.ICLASS_INTERNAL.isAssignableFrom(claxx)){
73             return true;
74         }
75         return false;
76     }
77     
78     protected Iterable4 classIndexesIterable(final YapClassCollectionIterator classCollectionIterator) {
79         return new Iterable4() {
80             public Iterator4 iterator() {
81                 return new CompositeIterator4(
82                     new MappingIterator(classCollectionIterator) {
83                         protected Object JavaDoc map(Object JavaDoc current) {
84                             final YapClass yapClass = (YapClass)current;
85                             if(skipClass(yapClass)){
86                                 return MappingIterator.SKIP;
87                             }
88                             return classIndexIterator(yapClass);
89                         }
90                     }
91                 );
92             }
93         };
94     }
95     
96     protected Iterable4 classIndexIterable(final YapClass clazz) {
97         return new Iterable4() {
98             public Iterator4 iterator() {
99                 return classIndexIterator(clazz);
100             }
101         };
102     }
103     
104     public Iterator4 classIndexIterator(YapClass clazz) {
105         return BTreeClassIndexStrategy.iterate(clazz, transaction());
106     }
107
108 }
109
Popular Tags