1 2 12 package com.versant.core.jdo; 13 14 import java.util.*; 15 16 25 public class MultiPartQueryResult extends QueryResultBase { 26 int size = -1; 27 private QueryResult[] queryResults; 28 private List totalResult; 29 30 private QueryResult curRes; 31 private int curIndex; 32 33 public MultiPartQueryResult(Set queryResultSet) { 34 queryResults = new QueryResult[queryResultSet.size()]; 35 queryResultSet.toArray(queryResults); 36 } 37 38 public void close() { 39 for (int i = 0; i < queryResults.length; i++) { 40 queryResults[i].close(); 41 } 42 } 43 44 public void setParams(Object [] params) { 45 } 46 47 public int size() { 48 if (totalResult == null) { 49 totalResult = new ArrayList(); 50 for (int i = 0; i < queryResults.length; i++) { 51 totalResult.addAll(queryResults[i]); 52 } 53 size = totalResult.size(); 54 } 55 return size; 56 } 57 58 public boolean isEmpty() { 59 return size() == 0; 60 } 61 62 public Iterator createInternalIterNoFlush() { 63 return null; 64 } 65 66 public Iterator iterator() { 67 return new Iter(queryResults, false); 68 } 69 70 public Object [] toArray() { 71 size(); 72 return totalResult.toArray(); 73 } 74 75 public Object [] toArray(Object a[]) { 76 size(); 77 return totalResult.toArray(a); 78 } 79 80 public Object get(int index) { 81 size(); 82 return totalResult.get(index); 83 } 84 85 public boolean contains(Object o) { 86 size(); 87 return totalResult.contains(o); 88 } 89 90 public boolean containsAll(Collection c) { 91 size(); 92 return totalResult.containsAll(c); 93 } 94 95 public int indexOf(Object o) { 96 size(); 97 return totalResult.indexOf(o); 98 } 99 100 public int lastIndexOf(Object o) { 101 size(); 102 return totalResult.lastIndexOf(o); 103 } 104 105 public ListIterator listIterator() { 106 return null; 107 } 108 109 public ListIterator listIterator(int index) { 110 return null; 111 } 112 113 public List subList(int fromIndex, int toIndex) { 114 return null; 115 } 116 117 class Iter implements Iterator { 118 private QueryResult[] queryResults; 119 private int nextIterIndex = 1; 120 private Iterator curIterator; 121 private boolean noFlush; 122 123 public Iter(QueryResult[] queryResults, boolean noFlush) { 124 this.queryResults = queryResults; 125 curIterator = queryResults[0].iterator(); 126 this.noFlush = noFlush; 127 } 128 129 private Iterator getIter(int index) { 130 if (noFlush) return queryResults[index].createInternalIterNoFlush(); 131 else return queryResults[index].iterator(); 132 } 133 134 public void remove() { 135 curIterator.remove(); 136 } 137 138 public boolean hasNext() { 139 if (curIterator.hasNext()) return true; 140 if (nextIterIndex == queryResults.length) return false; 141 curIterator = queryResults[nextIterIndex++].iterator(); 142 return curIterator.hasNext(); 143 } 144 145 public Object next() { 146 return curIterator.next(); 147 } 148 } 149 } 150 | Popular Tags |