1 23 24 27 package org.objectweb.medor.eval.lib; 28 29 import org.objectweb.medor.api.MedorException; 30 import org.objectweb.medor.api.TupleStructure; 31 import org.objectweb.medor.eval.api.BinaryEvaluatedTC; 32 import org.objectweb.medor.eval.api.NodeEvaluator; 33 import org.objectweb.medor.expression.api.ParameterOperand; 34 import org.objectweb.medor.query.api.QueryNode; 35 import org.objectweb.medor.tuple.api.Tuple; 36 import org.objectweb.medor.tuple.api.TupleCollection; 37 38 42 class UnionEvaluatedTC 43 extends BasicBinaryEvalutedTC 44 implements BinaryEvaluatedTC { 45 46 private boolean second = false; 49 private TupleCollection leftTCResult, rightTCResult; 50 private QueryNode query; 51 52 53 public UnionEvaluatedTC(QueryNode query, 54 NodeEvaluator leftNodeEvaluator, 55 NodeEvaluator rightNodeEvaluator, 56 ParameterOperand[] parameters) throws MedorException { 57 leftTCResult = leftNodeEvaluator.fetchData(parameters); 58 rightTCResult = rightNodeEvaluator.fetchData(parameters); 59 if (leftTCResult.isEmpty()) second = true; 60 } 61 62 public void close() throws MedorException { 63 super.close(); 64 if (leftTCResult != null) { 65 leftTCResult.close(); 66 } 67 if (rightTCResult != null) { 68 rightTCResult.close(); 69 } 70 } 71 72 public TupleStructure getMetaData() throws MedorException { 73 return query.getTupleStructure(); 74 } 75 76 public boolean isLast() throws MedorException { 77 boolean end = false; 78 if (!rightTCResult.isEmpty()) { 79 end = rightTCResult.isLast(); 80 } else { 81 end = leftTCResult.isLast(); 82 } 83 return end; 84 } 85 86 public boolean next() throws MedorException { 87 if (!second) { 88 if (!leftTCResult.next()) { 89 second = true; 90 return (!rightTCResult.isEmpty()); 91 } else 92 return true; 93 } else 94 return rightTCResult.next(); 95 } 96 97 public void first() throws MedorException { 98 leftTCResult.first(); 99 rightTCResult.first(); 100 second = false; 101 } 102 103 public int getRow() throws MedorException { 104 if (!second) 105 return leftTCResult.getRow(); 106 else 107 return leftTCResult.getRow() + rightTCResult.getRow(); 108 } 109 110 public Tuple getTuple() throws MedorException { 111 if (second) 112 return rightTCResult.getTuple(); 113 else 114 return leftTCResult.getTuple(); 115 } 116 117 public Tuple getTuple(int row) throws MedorException { 118 if (row <=0){ 119 throw new MedorException("Invalid Tuple index: "+ row); 120 }else{ 121 try{ 122 return leftTCResult.getTuple(row); 123 }catch (MedorException me){ 124 return rightTCResult.getTuple(row - getLeftCard()); } 126 } 127 } 128 129 133 private int getLeftCard(){ 134 return 0; } 136 137 public boolean isEmpty() throws MedorException { 138 return (leftTCResult.isEmpty() & rightTCResult.isEmpty()); 139 } 140 141 public boolean row(int numTuple) throws MedorException { 142 first(); 143 int cpt = 1; 144 boolean go = true; 145 while ((cpt <= numTuple) && (cpt > 1) && go) { 146 if (!next()) go = false; 147 } 148 if (!go) 149 return false; 150 else { 151 return true; 152 } 153 } 154 155 public synchronized int getLeftTCCursor() throws MedorException { 156 return leftTCResult.getRow(); 157 } 158 159 public synchronized int getRightTCCursor() throws MedorException { 160 return rightTCResult.getRow(); 161 } 162 163 } 164 | Popular Tags |