1 18 package org.objectweb.speedo.query.lib; 19 20 import org.objectweb.medor.tuple.api.TupleCollection; 21 import org.objectweb.medor.tuple.api.Tuple; 22 import org.objectweb.medor.api.TupleStructure; 23 import org.objectweb.medor.expression.api.ParameterOperand; 24 import org.objectweb.medor.api.MedorException; 25 import org.objectweb.medor.api.EvaluationException; 26 import org.objectweb.speedo.pm.api.ProxyManager; 27 import org.objectweb.speedo.query.api.QueryDefinition; 28 29 30 36 public class QueriesUnion implements TupleCollection { 37 38 41 ParameterOperand[] pos; 42 43 46 ProxyManager pm; 47 48 51 TupleCollection currentTC; 52 53 56 int queryIdx; 57 58 61 Object connection; 62 63 QueryEvalContext[] qecs; 64 65 int row = 0; 66 boolean hasResult = false; 67 68 69 public QueriesUnion(ParameterOperand[] pos, 70 ProxyManager pm, 71 Object connection, 72 QueryEvalContext[] qecs, 73 QueryDefinition userqd) throws MedorException { 74 queryIdx = -1; 75 this.pos = pos; 76 this.pm = pm; 77 this.connection = connection; 78 this.qecs = qecs; 79 calculateNext(); 80 } 81 82 83 private boolean calculateNext() throws EvaluationException, MedorException { 84 queryIdx++; 85 row++; 86 currentTC = null; 87 if (qecs.length <= queryIdx) { 88 return false; 89 } 90 currentTC = qecs[queryIdx].eval(pm, pos, connection, null); 91 if (currentTC == null || currentTC.isEmpty()) { 92 calculateNext(); 93 } 94 hasResult |= currentTC!= null; 95 if (currentTC == null) { 96 row = 0; 97 } 98 return currentTC != null; 99 } 100 101 104 public boolean next() throws MedorException { 105 return currentTC.next() || calculateNext(); 106 } 107 108 public void first() throws MedorException { 109 if (row != 1) { 110 queryIdx = -1; 111 row = 0; 112 calculateNext(); 113 } 114 } 115 116 public Tuple getTuple() throws MedorException { 117 if (currentTC == null) { 118 throw new MedorException("No more result"); 119 } 120 return currentTC.getTuple(); 121 } 122 123 public boolean isEmpty() throws MedorException { 124 return !hasResult; 125 } 126 127 public void close() throws MedorException { 128 if (currentTC != null) { 129 currentTC.close(); 130 } 131 } 132 133 public TupleStructure getMetaData() throws MedorException { 134 return currentTC.getMetaData(); 135 } 136 137 public boolean isLast() throws MedorException { 138 throw new MedorException("IsLast not yet suuported"); 139 } 140 141 public Tuple getTuple(int row) throws MedorException { 142 throw new MedorException("getTuple(int) not yet suuported"); 143 } 144 145 public boolean row(int row) throws MedorException { 146 throw new MedorException("row(int) not yet suuported"); 147 } 148 public int getRow() throws MedorException { 149 throw new MedorException("getRow not yet suuported"); 150 } 151 } 152 | Popular Tags |