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