1 22 23 package org.xquark.mediator.plan; 24 25 import java.util.ArrayList ; 26 27 import org.xquark.mediator.decomposer.Utils; 28 import org.xquark.mediator.runtime.MediatorException; 29 import org.xquark.xquery.parser.XQueryExpression; 30 31 36 public abstract class OpMult extends Operator { 37 private static final String RCSRevision = "$Revision: 1.6 $"; 41 private static final String RCSName = "$Name: $"; 42 43 47 protected Operator[] childrenOperator = null; 48 protected int ordertype = ORDER_SERIALIZATION; 49 50 70 public OpMult(ExecutionPlan plan, XQueryExpression expression, Operator left, Operator right) throws MediatorException { 71 super(plan, expression); 72 childrenOperator = new Operator[2]; 73 childrenOperator[0] = left; 74 childrenOperator[1] = right; 75 init(); 76 } 77 78 public OpMult(ExecutionPlan plan, XQueryExpression expression, Operator[] operators) throws MediatorException { 79 super(plan, expression); 80 this.childrenOperator = operators; 81 init(); 82 } 83 84 private void init() throws MediatorException { 85 for (int i = 0; i < childrenOperator.length; i++) { 87 childrenOperator[i].setParentOperator(this); 88 addPaths(childrenOperator[i].getPaths()); 89 } 91 } 92 93 97 public void accept(OperatorVisitor visitor) throws MediatorException { 98 visitor.visit(this); 99 } 100 101 110 111 public ResultSet executeQuery(DynamicContext context) throws MediatorException { 112 try { 113 OperatorRunnable[] runnables = new OperatorRunnable[childrenOperator.length]; 114 if (ordertype == ORDER_SERIALIZATION) { 115 for (int i = 0; i < childrenOperator.length; i++) { 116 OperatorRunnable ori = childrenOperator[i].getOperatorRunnable(context); 117 runnables[i] = ori; 118 ori.run(); 119 } 120 } else if (ordertype == ORDER_PARALLELIZATION) { 121 Thread [] threads = new Thread [childrenOperator.length]; 122 for (int i = 0; i < childrenOperator.length; i++) { 123 OperatorRunnable ori = childrenOperator[i].getOperatorRunnable((DynamicContext)context.clone()); 124 runnables[i] = ori; 125 threads[i] = new Thread (ori); 126 threads[i].start(); 127 } 128 for (int i = 0; i < threads.length; i++) { 130 Thread thread = threads[i]; 131 if (thread.isAlive()) 132 thread.join(); 133 } 134 } 135 return getResultSet(context, runnables); 136 } catch (InterruptedException e) { 137 throw new MediatorException("AlgMultOp.executeQuery: " + e.getMessage(), e); 138 } 139 } 140 141 145 protected abstract ResultSet getResultSet(DynamicContext context, OperatorRunnable[] runnables) throws MediatorException; 146 147 155 176 188 198 public Operator optimizeProjection() throws MediatorException { 199 return null; 200 } 201 202 209 public Operator optimizeRestriction() throws MediatorException { 210 return null; 211 } 212 213 220 229 235 250 256 public boolean isSource() { 257 return false; 258 } 259 260 264 public ArrayList getSources() { 265 if (sources == null) { 266 sources = new ArrayList (); 267 for (int i = 0; i < childrenOperator.length; i++) { 268 ArrayList tmplist = childrenOperator[i].getSources(); 269 for (int j = 0; j < tmplist.size(); j++) { 270 Object sourcej = tmplist.get(j); 271 if (!sources.contains(sourcej)) 272 sources.add(sourcej); 273 } 274 } 275 } 276 return sources; 277 } 278 279 public void terminate() { 280 for (int i = 0; i < childrenOperator.length; i++) 281 childrenOperator[i].terminate(); 282 } 283 284 public void setPrepared() throws MediatorException { 285 if (prepared) return; 286 prepared = true; 287 for (int i = 0; i < childrenOperator.length; i++) 288 childrenOperator[i].setPrepared(); 289 } 290 291 public String toCompleteString(int indent) { 292 StringBuffer buf = new StringBuffer (); 293 buf.append(Utils.makeIndent(indent) + "<" + getClass().getName() + " size=" + size + " id size=" + idsize + " isLet=\"" + islet + "\" valueDepends=\"" + valueDepends + "\" whereDepends=\"" + whereDepends + "\">\n"); 294 295 buf.append(Utils.makeIndent(indent + 1) + "<Expression>\n"); 296 buf.append(Utils.makeIndent(indent + 2) + expression + "\n"); 297 buf.append(Utils.makeIndent(indent + 1) + "</Expression>\n"); 298 if (paths != null) { 306 buf.append(Utils.makeIndent(indent + 1) + "<Paths>\n"); 307 for (int i = 0; i < paths.size(); i++) { 308 buf.append(Utils.makeIndent(indent + 2) + "<Path>" + paths.get(i) + "</Path>\n"); 309 } 310 buf.append(Utils.makeIndent(indent + 1) + "</Paths>\n"); 311 } 312 313 for (int i = 0; i < childrenOperator.length; i++) { 314 buf.append(Utils.makeIndent(indent + 1) + "<Element" + (i + 1) + ">\n"); 315 buf.append(childrenOperator[i].toCompleteString(indent + 2)); 316 buf.append(Utils.makeIndent(indent + 1) + "</Element" + (i + 1) + ">\n"); 317 } 318 buf.append(Utils.makeIndent(indent) + "</" + getClass().getName() + ">\n"); 319 return buf.toString(); 320 } 321 } 322 | Popular Tags |