1 18 package org.objectweb.jorm.lib; 19 20 import org.objectweb.jorm.api.PClassMapping; 21 import org.objectweb.jorm.api.PNameIterator; 22 import org.objectweb.jorm.api.PException; 23 24 import java.util.Iterator ; 25 import java.util.NoSuchElementException ; 26 27 33 public class MultiplePNameIterator implements PNameIterator { 34 35 38 private PClassMapping[] pcms; 39 40 43 private Iterator currentIterator; 44 45 48 private int pcmIdx; 49 50 54 private Object connection; 55 56 59 private Object txctx; 60 61 66 private Object nextPName; 67 68 73 private boolean prefetching; 74 75 82 public MultiplePNameIterator(PClassMapping[] pcms, 83 Object connection, 84 boolean prefetching, 85 Object txctx) throws PException { 86 this(pcms, null, connection, prefetching, txctx); 87 } 88 89 100 public MultiplePNameIterator(PClassMapping[] pcms, 101 Iterator currentIt, 102 Object connection, 103 boolean prefetching, 104 Object txctx) throws PException { 105 this.pcms = pcms; 106 this.prefetching = prefetching; 107 this.connection = connection; 108 currentIterator = currentIt; 109 this.txctx = txctx; 110 pcmIdx = -1; 111 calculateNext(); 112 } 113 114 120 private void calculateNext() throws PException { 121 if (currentIterator != null && currentIterator.hasNext()) { 122 nextPName = currentIterator.next(); 123 } else { 124 nextPName = null; 125 if (!prefetching && currentIterator instanceof PNameIterator) { 127 ((PNameIterator) currentIterator).close(); 128 } 129 pcmIdx ++; 131 if (pcmIdx < pcms.length) { 132 currentIterator = pcms[pcmIdx] 134 .getPNameIterator(connection, true, prefetching, txctx); 135 calculateNext(); 137 } } 139 } 140 141 144 public boolean hasNext() { 145 return nextPName != null; 146 } 147 148 public Object next() { 149 if (nextPName == null) { 150 throw new NoSuchElementException (); 151 } 152 Object res = nextPName; 153 try { 154 calculateNext(); 155 } catch (PException e) { 156 nextPName = null; 157 } 158 return res; 159 } 160 161 164 public void remove() { 165 throw new UnsupportedOperationException ("Remove operation not supported"); 166 } 167 168 172 public void close() throws PException { 173 nextPName = null; 174 if (!prefetching && currentIterator instanceof PNameIterator) { 175 ((PNameIterator) currentIterator).close(); 176 } 177 } 178 } 179 | Popular Tags |