001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.internal.query.result;
022:
023: import com.db4o.foundation.*;
024: import com.db4o.internal.*;
025: import com.db4o.internal.classindex.*;
026: import com.db4o.reflect.*;
027:
028: /**
029: * @exclude
030: */
031: public abstract class AbstractLateQueryResult extends
032: AbstractQueryResult {
033:
034: protected Iterable4 _iterable;
035:
036: public AbstractLateQueryResult(Transaction transaction) {
037: super (transaction);
038: }
039:
040: public AbstractQueryResult supportSize() {
041: return toIdTree();
042: }
043:
044: public AbstractQueryResult supportSort() {
045: return toIdList();
046: }
047:
048: public AbstractQueryResult supportElementAccess() {
049: return toIdList();
050: }
051:
052: protected int knownSize() {
053: return 0;
054: }
055:
056: public IntIterator4 iterateIDs() {
057: if (_iterable == null) {
058: throw new IllegalStateException();
059: }
060: return new IntIterator4Adaptor(_iterable);
061: }
062:
063: public AbstractQueryResult toIdList() {
064: return toIdTree().toIdList();
065: }
066:
067: public boolean skipClass(ClassMetadata yapClass) {
068: if (yapClass.getName() == null) {
069: return true;
070: }
071: ReflectClass claxx = yapClass.classReflector();
072: if (stream()._handlers.ICLASS_INTERNAL.isAssignableFrom(claxx)) {
073: return true;
074: }
075: return false;
076: }
077:
078: protected Iterable4 classIndexesIterable(
079: final ClassMetadataIterator classCollectionIterator) {
080: return new Iterable4() {
081: public Iterator4 iterator() {
082: return new CompositeIterator4(new MappingIterator(
083: classCollectionIterator) {
084: protected Object map(Object current) {
085: final ClassMetadata yapClass = (ClassMetadata) current;
086: if (skipClass(yapClass)) {
087: return MappingIterator.SKIP;
088: }
089: return classIndexIterator(yapClass);
090: }
091: });
092: }
093: };
094: }
095:
096: protected Iterable4 classIndexIterable(final ClassMetadata clazz) {
097: return new Iterable4() {
098: public Iterator4 iterator() {
099: return classIndexIterator(clazz);
100: }
101: };
102: }
103:
104: public Iterator4 classIndexIterator(ClassMetadata clazz) {
105: return BTreeClassIndexStrategy.iterate(clazz, transaction());
106: }
107:
108: }
|