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 OpCartesian extends OpBin { 33 private static final String RCSRevision = "$Revision: 1.7 $"; 37 private static final String RCSName = "$Name: $"; 38 39 43 47 public OpCartesian(ExecutionPlan plan, XQueryExpression expression,Operator left, Operator right) throws MediatorException { 48 super(plan, expression, left, right) ; 49 init(); 50 } 51 52 public OpCartesian(ExecutionPlan plan, XQueryExpression expression, Operator[] operators) throws MediatorException { 53 super(plan, expression, operators) ; 54 init(); 55 } 56 57 private void init() { 58 ArrayList childpaths1 = getLeftAlgebra().getPathsList() ; 63 ArrayList childpaths2 = getRightAlgebra().getPathsList() ; 64 size = getLeftAlgebra().getSize() + getRightAlgebra().getSize(); 65 66 76 idsize = getLeftAlgebra().getIdSize() + getRightAlgebra().getIdSize(); 80 88 ordertype = ORDER_PARALLELIZATION ; 89 } 90 91 95 public void accept(OperatorVisitor visitor) throws MediatorException { 96 visitor.visit(this); 97 } 98 99 105 public ResultSet getResultSet(DynamicContext context, OperatorRunnable[] runnables) throws MediatorException { 106 try { 107 return new CartesianResultSet(this, context, runnables) ; 108 } 109 catch (XMLDBCException e) { 110 throw new MediatorException("Can't construct " + getClass() + ": " + e.getMessage(), e) ; 111 } 112 } 113 114 118 119 125 } 126 127 class CartesianResultSet extends BinResultSet { 128 private static final String RCSRevision = "$Revision: 1.7 $"; 132 private static final String RCSName = "$Name: $"; private int index = -1; 135 private Tuple tuplepivot = null; 136 ArrayList tuplelist = null; 137 143 public CartesianResultSet(OpCartesian operator, DynamicContext context, OperatorRunnable[] children) throws XMLDBCException { 144 super(operator, context, children) ; 145 } 146 147 159 160 protected void evaluate(boolean non_blocking) throws MediatorException { 161 while (true) { 162 Tuple tuple = null; 163 if (index == -1) { 164 if (tuplepivot == null) { 166 if (children[0].getResultSet().hasNext()) 167 tuplepivot = children[0].getResultSet().next(); 168 else { 169 setFinishedWhenEmpty(); 170 children[0].getResultSet().close(); 171 children[1].getResultSet().close(); 172 return; 173 } 174 } 175 if (children[1].getResultSet().hasNext()) { 176 tuple = children[1].getResultSet().next(); 177 if (tuplelist == null) 178 tuplelist = new ArrayList (); 179 tuplelist.add(tuple); 180 } else { 181 if (tuplelist != null && children[0].getResultSet().hasNext()) { 182 tuplepivot = children[0].getResultSet().next(); 183 index = 0; 184 tuple = (Tuple) tuplelist.get(index++); 185 } else { 186 setFinishedWhenEmpty(); 187 children[0].getResultSet().close(); 188 children[1].getResultSet().close(); 189 return; 190 } 191 } 192 } else { 193 if (index < tuplelist.size()) 194 tuple = (Tuple) tuplelist.get(index++); 195 else { 196 if (children[0].getResultSet().hasNext()) { 197 tuplepivot = children[0].getResultSet().next(); 198 index = 0; 199 tuple = (Tuple) tuplelist.get(index++); 200 } else { 201 setFinishedWhenEmpty(); 202 children[0].getResultSet().close(); 203 return; 204 } 205 } 206 } 207 buftuples.add(tuplepivot.merge(tuple, operator)); 208 if (non_blocking) 209 break; 210 } 211 } 212 } 213 | Popular Tags |