1 22 23 package org.xquark.mediator.plan ; 24 25 import org.xquark.mediator.DOMUtils.Tuple; 26 import org.xquark.mediator.runtime.MediatorException; 27 import org.xquark.xml.xdbc.XMLDBCException; 28 29 public class OpUnion extends OpMult { 30 private static final String RCSRevision = "$Revision: 1.8 $"; 34 private static final String RCSName = "$Name: $"; 39 40 public OpUnion(ExecutionPlan plan, Operator[] operators) throws MediatorException { 41 super(plan, null, operators) ; 42 init(); 43 } 44 45 private void init() { 46 size = childrenOperator[0].getSize(); 47 idsize = childrenOperator[0].getIdSize(); 48 ordertype = ORDER_PARALLELIZATION ; 49 } 51 52 56 public void accept(OperatorVisitor visitor) throws MediatorException { 57 visitor.visit(this); 58 } 59 60 66 protected ResultSet getResultSet(DynamicContext context, OperatorRunnable[] children) throws MediatorException { 67 try { 68 return new UnionResultSet(this, context, children) ; 69 } 70 catch (XMLDBCException e) { 71 throw new MediatorException("Can't construct " + getClass() + ": " + e.getMessage(), e) ; 72 } 73 } 74 75 84 86 } 90 91 class UnionResultSet extends MultResultSet { 92 private static final String RCSRevision = "$Revision: 1.8 $"; 96 private static final String RCSName = "$Name: $"; 97 98 private int index = 0; 99 105 public UnionResultSet(OpUnion operator, DynamicContext context, OperatorRunnable[] children) throws XMLDBCException { 106 super(operator, context, children) ; 107 } 108 109 118 protected void evaluate(boolean non_blocking) throws MediatorException { 119 120 122 boolean islet = operator.isLet(); 123 Tuple restuple = null; 124 while (true) { 125 while (index < children.length && (children[index].getResultSet() == null || !children[index].getResultSet().hasNext())) { 126 if (children[index].getResultSet() != null) 127 children[index].getResultSet().close(); 128 index++; 129 } 130 if (index == children.length) { 131 setFinishedWhenEmpty() ; 132 break; 133 } 134 135 Tuple tuple = children[index].getResultSet().next() ; 136 if (islet) { 137 if (restuple == null) restuple = tuple; 138 else restuple.appendTuple(tuple); 139 } 140 else buftuples.add(tuple) ; 141 if (non_blocking) { 142 if (!islet && buftuples != null && ! buftuples.isEmpty()) break ; 143 } 144 } 145 if (islet && restuple != null) buftuples.add(restuple); 146 } 147 } 148 | Popular Tags |