1 22 23 package org.xquark.mediator.plan; 24 25 import java.util.ArrayList ; 26 27 import org.xquark.mediator.DOMUtils.Tuple; 28 import org.xquark.mediator.runtime.MediatorException; 29 import org.xquark.xml.xdbc.XMLDBCException; 30 import org.xquark.xquery.parser.XQueryExpression; 31 32 public class OpMerge extends OpBin { 33 private static final String RCSRevision = "$Revision: 1.8 $"; 37 private static final String RCSName = "$Name: $"; 38 39 48 public OpMerge(ExecutionPlan plan, XQueryExpression expression, Operator left, Operator right) throws MediatorException { 49 super(plan, expression, left, right); 50 init(); 51 } 52 53 58 private void init() throws MediatorException { 59 ArrayList childpaths1 = getLeftAlgebra().getPathsList(); 62 ArrayList childpaths2 = getRightAlgebra().getPathsList(); 63 size = getLeftAlgebra().getSize() + getRightAlgebra().getSize(); 64 65 75 idsize = getLeftAlgebra().getIdSize() + getRightAlgebra().getIdSize(); 79 87 ordertype = ORDER_PARALLELIZATION; 88 } 89 90 94 public void accept(OperatorVisitor visitor) throws MediatorException { 95 visitor.visit(this); 96 } 97 98 104 protected ResultSet getResultSet(DynamicContext context, OperatorRunnable[] children) throws MediatorException { 105 try { 106 return new MergeResultSet(this, context, children); 107 } catch (XMLDBCException e) { 108 throw new MediatorException("Can't construct " + getClass() + ": " + e.getMessage(), e); 109 } 110 } 111 112 121 123 129 } 130 131 class MergeResultSet extends BinResultSet { 132 private static final String RCSRevision = "$Revision: 1.8 $"; 136 private static final String RCSName = "$Name: $"; 139 private Tuple halftuple2 = null; 140 public MergeResultSet(OpMerge operator, DynamicContext context, OperatorRunnable[] children) throws XMLDBCException { 144 super(operator, context, children); 145 } 146 147 158 protected void evaluate(boolean non_blocking) throws MediatorException { 159 160 if (!children[0].getResultSet().hasNext()) { 161 children[0].getResultSet().close(); 162 if (halftuple2 == null) 163 children[1].getResultSet().close(); 164 setFinishedWhenEmpty(); 165 return; 166 } 167 168 if (halftuple2 == null) { 169 if (children[1].getResultSet().hasNext()) 170 halftuple2 = children[1].getResultSet().next() ; 171 children[1].getResultSet().close(); 172 } 173 174 while (true) { 175 if (children[0].getResultSet().hasNext()) { 176 Tuple halftuple1 = children[0].getResultSet().next() ; 177 if (halftuple2 != null) 178 buftuples.add(halftuple1.merge(halftuple2, operator)); 179 else 180 buftuples.add(halftuple1.completeTupleForLeft(operator.getSize())); 181 if (non_blocking) { 182 if ((buftuples != null) && (! buftuples.isEmpty())) 184 break ; 185 } 186 } 187 else { 188 children[0].getResultSet().close(); 189 setFinishedWhenEmpty() ; 190 return ; 191 } 192 } 193 if (! children[0].getResultSet().hasNext()) { 194 children[0].getResultSet().close(); 195 setFinishedWhenEmpty() ; 196 } 197 } 198 199 200 } 201 | Popular Tags |