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.ext.*;
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 abstract class AbstractQueryResult implements QueryResult {
033:
034: protected final Transaction _transaction;
035:
036: public AbstractQueryResult(Transaction transaction) {
037: _transaction = transaction;
038: }
039:
040: public final Object activate(Object obj) {
041: stream()
042: .activate(_transaction, obj, config().activationDepth());
043: return obj;
044: }
045:
046: public final Object activatedObject(int id) {
047: ObjectContainerBase stream = stream();
048: Object ret = stream.getActivatedObjectFromCache(_transaction,
049: id);
050: if (ret != null) {
051: return ret;
052: }
053: return stream.readActivatedObjectNotInCache(_transaction, id);
054: }
055:
056: public Object lock() {
057: final ObjectContainerBase stream = stream();
058: stream.checkClosed();
059: return stream.lock();
060: }
061:
062: public ObjectContainerBase stream() {
063: return _transaction.container();
064: }
065:
066: public Transaction transaction() {
067: return _transaction;
068: }
069:
070: public ExtObjectContainer objectContainer() {
071: return transaction().objectContainer().ext();
072: }
073:
074: public Iterator4 iterator() {
075: return new MappingIterator(iterateIDs()) {
076: protected Object map(Object current) {
077: if (current == null) {
078: return MappingIterator.SKIP;
079: }
080: synchronized (lock()) {
081: Object obj = activatedObject(((Integer) current)
082: .intValue());
083: if (obj == null) {
084: return MappingIterator.SKIP;
085: }
086: return obj;
087: }
088: }
089: };
090: }
091:
092: public AbstractQueryResult supportSize() {
093: return this ;
094: }
095:
096: public AbstractQueryResult supportSort() {
097: return this ;
098: }
099:
100: public AbstractQueryResult supportElementAccess() {
101: return this ;
102: }
103:
104: protected int knownSize() {
105: return size();
106: }
107:
108: public AbstractQueryResult toIdList() {
109: IdListQueryResult res = new IdListQueryResult(transaction(),
110: knownSize());
111: IntIterator4 i = iterateIDs();
112: while (i.moveNext()) {
113: res.add(i.currentInt());
114: }
115: return res;
116: }
117:
118: protected AbstractQueryResult toIdTree() {
119: return new IdTreeQueryResult(transaction(), iterateIDs());
120: }
121:
122: public Config4Impl config() {
123: return stream().config();
124: }
125:
126: public int size() {
127: throw new NotImplementedException();
128: }
129:
130: public void sort(QueryComparator cmp) {
131: throw new NotImplementedException();
132: }
133:
134: public Object get(int index) {
135: throw new NotImplementedException();
136: }
137:
138: /** @param i */
139: public int getId(int i) {
140: throw new NotImplementedException();
141: }
142:
143: public int indexOf(int id) {
144: throw new NotImplementedException();
145: }
146:
147: /** @param c */
148: public void loadFromClassIndex(ClassMetadata c) {
149: throw new NotImplementedException();
150: }
151:
152: /** @param i */
153: public void loadFromClassIndexes(ClassMetadataIterator i) {
154: throw new NotImplementedException();
155: }
156:
157: /** @param r */
158: public void loadFromIdReader(Buffer r) {
159: throw new NotImplementedException();
160: }
161:
162: /** @param q */
163: public void loadFromQuery(QQuery q) {
164: throw new NotImplementedException();
165: }
166:
167: }
|