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.config.*;
024: import com.db4o.foundation.*;
025: import com.db4o.internal.*;
026: import com.db4o.internal.query.processor.*;
027: import com.db4o.query.*;
028:
029: /**
030: * @exclude
031: */
032: public class HybridQueryResult extends AbstractQueryResult {
033:
034: private AbstractQueryResult _delegate;
035:
036: public HybridQueryResult(Transaction transaction,
037: QueryEvaluationMode mode) {
038: super (transaction);
039: _delegate = forMode(transaction, mode);
040: }
041:
042: private static AbstractQueryResult forMode(Transaction transaction,
043: QueryEvaluationMode mode) {
044: if (mode == QueryEvaluationMode.LAZY) {
045: return new LazyQueryResult(transaction);
046: }
047: if (mode == QueryEvaluationMode.SNAPSHOT) {
048: return new SnapShotQueryResult(transaction);
049: }
050: return new IdListQueryResult(transaction);
051: }
052:
053: public Object get(int index) {
054: _delegate = _delegate.supportElementAccess();
055: return _delegate.get(index);
056: }
057:
058: public int getId(int index) {
059: _delegate = _delegate.supportElementAccess();
060: return _delegate.getId(index);
061: }
062:
063: public int indexOf(int id) {
064: _delegate = _delegate.supportElementAccess();
065: return _delegate.indexOf(id);
066: }
067:
068: public IntIterator4 iterateIDs() {
069: return _delegate.iterateIDs();
070: }
071:
072: public Iterator4 iterator() {
073: return _delegate.iterator();
074: }
075:
076: public void loadFromClassIndex(ClassMetadata clazz) {
077: _delegate.loadFromClassIndex(clazz);
078: }
079:
080: public void loadFromClassIndexes(ClassMetadataIterator iterator) {
081: _delegate.loadFromClassIndexes(iterator);
082: }
083:
084: public void loadFromIdReader(Buffer reader) {
085: _delegate.loadFromIdReader(reader);
086: }
087:
088: public void loadFromQuery(QQuery query) {
089: if (query.requiresSort()) {
090: _delegate = new IdListQueryResult(transaction());
091: }
092: _delegate.loadFromQuery(query);
093: }
094:
095: public int size() {
096: _delegate = _delegate.supportSize();
097: return _delegate.size();
098: }
099:
100: public void sort(QueryComparator cmp) {
101: _delegate = _delegate.supportSort();
102: _delegate.sort(cmp);
103: }
104:
105: }
|