1 21 package com.db4o.inside.cluster; 22 23 import com.db4o.*; 24 import com.db4o.cluster.*; 25 import com.db4o.ext.*; 26 import com.db4o.foundation.*; 27 import com.db4o.inside.query.*; 28 import com.db4o.query.*; 29 30 34 public class ClusterQueryResult implements QueryResult { 35 36 private final Cluster _cluster; 37 private final ObjectSet[] _objectSets; 38 private final int[] _sizes; 39 private final int _size; 40 41 public ClusterQueryResult(Cluster cluster, Query[] queries){ 42 _cluster = cluster; 43 _objectSets = new ObjectSet[queries.length]; 44 _sizes = new int[queries.length]; 45 int size = 0; 46 for (int i = 0; i < queries.length; i++) { 47 _objectSets[i] = queries[i].execute(); 48 _sizes[i] = _objectSets[i].size(); 49 size += _sizes[i]; 50 } 51 _size = size; 52 } 53 54 private static final class ClusterQueryResultIntIterator implements IntIterator4 { 55 56 private final CompositeIterator4 _delegate; 57 58 public ClusterQueryResultIntIterator(Iterator4[] iterators) { 59 _delegate = new CompositeIterator4(iterators); 60 } 61 62 public boolean moveNext() { 63 return _delegate.moveNext(); 64 } 65 66 public Object current() { 67 return _delegate.current(); 68 } 69 70 public void reset() { 71 _delegate.reset(); 72 } 73 74 public int currentInt() { 75 return ((IntIterator4)_delegate.currentIterator()).currentInt(); 76 } 77 } 78 79 public IntIterator4 iterateIDs() { 80 synchronized(_cluster) { 81 final Iterator4[] iterators = new Iterator4[_objectSets.length]; 82 for (int i = 0; i < _objectSets.length; i++) { 83 iterators[i] = ((ObjectSetFacade)_objectSets[i])._delegate.iterateIDs(); 84 } 85 return new ClusterQueryResultIntIterator(iterators); 86 } 87 } 88 89 public Iterator4 iterator() { 90 synchronized(_cluster) { 91 Iterator4[] iterators = new Iterator4[_objectSets.length]; 92 for (int i = 0; i < _objectSets.length; i++) { 93 iterators[i] = ((ObjectSetFacade)_objectSets[i])._delegate.iterator(); 94 } 95 return new CompositeIterator4(iterators); 96 } 97 } 98 99 public int size() { 100 return _size; 101 } 102 103 public Object get(int index) { 104 synchronized(_cluster){ 105 if (index < 0 || index >= size()) { 106 throw new IndexOutOfBoundsException (); 107 } 108 int i = 0; 109 while(index >= _sizes[i]){ 110 index -= _sizes[i]; 111 i++; 112 } 113 return ((ObjectSetFacade)_objectSets[i]).get(index); 114 } 115 } 116 117 public Object streamLock() { 118 return _cluster; 119 } 120 121 public ExtObjectContainer objectContainer() { 122 throw new NotSupportedException(); 123 } 124 125 public int indexOf(int id) { 126 throw new NotSupportedException(); 127 } 128 129 public void sort(QueryComparator cmp) { 130 throw new NotSupportedException(); 131 } 132 133 public void loadFromClassIndex(YapClass c) { 134 throw new NotSupportedException(); 135 } 136 137 public void loadFromQuery(QQuery q) { 138 throw new NotSupportedException(); 139 } 140 141 public void loadFromClassIndexes(YapClassCollectionIterator i) { 142 throw new NotSupportedException(); 143 } 144 145 public void loadFromIdReader(YapReader r) { 146 throw new NotSupportedException(); 147 } 148 } 149 150 | Popular Tags |