1 2 12 package com.versant.core.jdo; 13 14 import com.versant.core.server.CompiledQuery; 15 import com.versant.core.server.QueryResultWrapper; 16 import com.versant.core.common.QueryResultContainer; 17 import com.versant.core.common.BindingSupportImpl; 18 19 import java.util.NoSuchElementException ; 20 21 24 public class QueryIterator implements JDOListIterator { 25 private PMProxy pm; 26 27 private Object [] data; 28 private int actualSize; 29 private int indexInData; 30 private QueryResultWrapper qrw; 31 private boolean noMoreDataInResultSet; 32 private boolean closed; 33 private int nextIndex; 34 35 public QueryIterator(PMProxy pm, CompiledQuery compiledQuery, Object [] params, 36 boolean doNotFlush) { 37 this.pm = pm; 38 if (!doNotFlush && !compiledQuery.getQueryDetails().isIgnoreCache()) { 39 pm.flushIfDepOn(compiledQuery.getEvictionClassBits()); 40 } 41 qrw = pm.executeQuery(compiledQuery, params); 42 } 43 44 public void remove() { 45 throw BindingSupportImpl.getInstance().unsupported("Not allowed to modify"); 46 } 47 48 public boolean hasNext() { 49 if (closed) return false; 50 51 if (!noMoreDataInResultSet && (data == null || indexInData == actualSize)) { 52 getMoreData(); 53 } 54 return !(data == null || indexInData == actualSize); 55 } 56 57 64 public Object next() { 65 if (closed) { 66 throw new NoSuchElementException (); 67 } 68 69 if (!noMoreDataInResultSet && (data == null || indexInData == actualSize)) { 70 getMoreData(); 71 } 72 return getNextData(); 73 } 74 75 private void getMoreData() { 76 QueryResultContainer container = pm.getNextQueryResult(qrw, 0); 78 pm.addToCache(container.container); 79 80 data = container.getDataArray(); 81 actualSize = container.size(); 82 noMoreDataInResultSet = container.isqFinished(); 83 indexInData = 0; 84 } 85 86 private Object getNextData() { 87 if (indexInData == actualSize) throw new NoSuchElementException (); 88 nextIndex++; 89 return QueryResultBase.resolveRow(data[indexInData++], pm); 90 } 91 92 95 public void close() { 96 if (closed) return; 97 98 if (qrw != null) { 99 pm.closeQuery(qrw); 100 qrw = null; 101 } 102 103 pm = null; 104 data = null; 105 qrw = null; 106 107 closed = true; 108 } 109 110 public int nextIndex() { 111 return nextIndex; 112 } 113 114 public int previousIndex() { 115 return nextIndex - 1; 116 } 117 118 public boolean hasPrevious() { 119 return nextIndex != 0; 120 } 121 122 public Object previous() { 123 throw BindingSupportImpl.getInstance().unsupportedOperation(null); 124 } 125 126 public void add(Object o) { 127 throw BindingSupportImpl.getInstance().unsupported("Not allowed to modify"); 128 } 129 130 public void set(Object o) { 131 throw BindingSupportImpl.getInstance().unsupported("Not allowed to modify"); 132 } 133 } 134 | Popular Tags |