1 22 23 package org.xquark.mediator.plan ; 24 25 import org.xquark.mediator.DOMUtils.EvaluationVisitor; 26 import org.xquark.mediator.DOMUtils.Tuple; 27 import org.xquark.mediator.runtime.MediatorException; 28 import org.xquark.xquery.parser.XQueryException; 29 import org.xquark.xquery.parser.XQueryExpression; 30 31 32 public class OpRestrict extends OpUn { 33 private static final String RCSRevision = "$Revision: 1.12 $"; 37 private static final String RCSName = "$Name: $"; 42 public OpRestrict(ExecutionPlan plan, XQueryExpression expression,Operator childexp) throws MediatorException { 43 super(plan, expression, childexp) ; 44 size = childexp.getSize(); 45 idsize = childexp.getIdSize(); 46 } 47 48 52 public void accept(OperatorVisitor visitor) throws MediatorException { 53 visitor.visit(this); 54 } 55 56 62 protected ResultSet getResultSet(DynamicContext context, OperatorRunnable child) throws MediatorException { 63 return new RestrictResultSet(this, context, child) ; 64 } 65 66 70 } 74 75 76 77 class RestrictResultSet extends UnResultSet { 78 private static final String RCSRevision = "$Revision: 1.12 $"; 82 private static final String RCSName = "$Name: $"; 85 private EvaluationVisitor evalvisitor = null; 86 87 90 public RestrictResultSet(OpRestrict operator, DynamicContext context, OperatorRunnable child) throws MediatorException { 91 super(operator, context, child) ; 92 } 93 94 101 protected void evaluate(boolean non_blocking) throws MediatorException { 102 103 while (true) { 104 if (resultset.hasNext()) { 105 Tuple tuple = resultset.next() ; 106 try { 107 if (expression == null) buftuples.add(tuple) ; 108 else { 109 if (evalvisitor == null) 110 evalvisitor = new EvaluationVisitor(this.operator.getPlan().getSchemaManager()) ; 111 context.addCurrentTuple(tuple); 112 evalvisitor.reset(context.getCurrentTuples()); 114 evalvisitor.setReturnType(EvaluationVisitor.BOOLEAN_TYPE); 115 expression.accept(evalvisitor) ; 116 context.deleteCurrentTuple(tuple); 117 if (evalvisitor.getVerdict()) { 118 buftuples.add(tuple) ; 119 } 120 else if (! resultset.hasNext()) setFinishedWhenEmpty() ; 121 } 122 } 123 catch (XQueryException e) { 124 throw new MediatorException("AlgRestrict.evaluate: " + e.getMessage(), e) ; 125 } 126 127 if (non_blocking) { 128 if ((buftuples != null) && (! buftuples.isEmpty())) 130 break ; 131 } 132 } 133 else { 134 setFinishedWhenEmpty() ; 135 resultset.close(); 136 return ; 137 } 138 } 139 if (! resultset.hasNext()) { 140 setFinishedWhenEmpty() ; 141 resultset.close(); 142 } 143 return; 144 } 145 } 146 | Popular Tags |