1 22 23 package org.xquark.mediator.plan; 24 25 import java.util.ArrayList ; 26 27 import org.xquark.mediator.algebra.Algebra; 28 import org.xquark.mediator.decomposer.Utils; 29 import org.xquark.mediator.runtime.MediatorException; 30 import org.xquark.schema.SchemaManager; 31 import org.xquark.xquery.parser.XQueryExpression; 32 import org.xquark.xquery.typing.TypeVisitor; 33 public abstract class Operator { 34 private static final String RCSRevision = "$Revision: 1.12 $"; 38 private static final String RCSName = "$Name: $"; 39 40 public final static int ORDER_SERIALIZATION = 0; 44 public final static int ORDER_PARALLELIZATION = 1; 45 46 protected XQueryExpression expression = null; 47 protected ExecutionPlan plan = null; 48 protected Operator parentOperator = null; 49 protected ArrayList paths = null; 50 protected ArrayList pathslist = null; 51 52 protected ArrayList sources = null; 53 protected boolean islet = false; 54 55 protected int size = 0; 56 protected int idsize = 0; 58 60 protected ArrayList indexesSpec = null; 61 protected boolean valueDepends = false; 62 protected boolean whereDepends = false; 63 64 protected boolean prepared = false; 65 66 72 public Operator(ExecutionPlan plan, XQueryExpression expression) throws MediatorException { 73 super(); 74 this.plan = plan; 75 this.expression = expression; 76 resetPaths(); 77 } 78 79 83 public XQueryExpression getExpression() { 84 return expression; 85 } 86 87 public void setExpression(XQueryExpression expression) { 88 this.expression = expression; 89 } 90 91 public int getSize() { 92 return size; 93 } 94 public int getIdSize() { 95 return idsize; 96 } 97 public void setDepends(Algebra depnode) { 98 valueDepends = !depnode.getVarsDependingOn().isEmpty(); 99 whereDepends = !depnode.getVarsWhereOn().isEmpty(); 100 } 101 public boolean getValueDepends() { 102 return valueDepends; 103 } 104 public void setValueDepends(boolean valueDepends) { 105 this.valueDepends = valueDepends; 106 } 107 public boolean getWhereDepends() { 108 return whereDepends; 109 } 110 public void setWhereDepends(boolean whereDepends) { 111 this.whereDepends = whereDepends; 112 } 113 public boolean getDepends() { 114 return valueDepends || whereDepends; 115 } 116 public ArrayList getIndexesSpec() { 118 return this.indexesSpec; 119 } 120 public ArrayList getIndexSpec(int index) { 121 if (indexesSpec == null || indexesSpec.size() <= index) 122 return null; 123 return (ArrayList ) this.indexesSpec.get(index); 124 } 125 public int addIndexSpec(ArrayList list) { 126 if (this.indexesSpec == null) 127 this.indexesSpec = new ArrayList (); 128 this.indexesSpec.add(list); 129 return this.indexesSpec.size(); 130 } 131 public int addIndexSpecs(ArrayList list) { 132 if (this.indexesSpec == null) 133 this.indexesSpec = new ArrayList (); 134 this.indexesSpec.addAll(list); 135 return this.indexesSpec.size(); 136 } 137 public void setParentOperator(Operator operator) { 139 this.parentOperator = operator; 140 } 141 public Operator getParentOperator() { 142 return parentOperator; 143 } 144 public abstract void setPrepared() throws MediatorException; 146 147 151 public OperatorRunnable getOperatorRunnable(DynamicContext ctx) { 152 return new OperatorRunnable(this,ctx); 153 } 154 155 161 protected abstract ResultSet executeQuery(DynamicContext context) throws MediatorException; 162 163 public Operator addCondition(ExecutionPlan plan, XQueryExpression expr) throws MediatorException { 164 return new OpRestrict(plan, expr, this); 165 } 166 167 173 public String toCompleteString() { 174 return toCompleteString(0); 175 } 176 177 180 public String toCompleteString(int indent) { 181 StringBuffer buf = new StringBuffer (); 182 buf.append(Utils.makeIndent(indent) + "<Class>" + getClass() + "</Class>"); 183 return buf.toString(); 184 } 185 186 public void resetPaths() { 190 if (this.paths != null) 191 this.paths.clear(); 192 else 193 this.paths = new ArrayList (); 194 if (this.pathslist != null) 195 this.pathslist.clear(); 196 else 197 this.pathslist = new ArrayList (); 198 } 199 public ArrayList getPaths() { 200 return paths; 201 } 202 public ArrayList getPathsList() { 203 return pathslist; 204 } 205 public void addPath(XQueryExpression pathi) { 206 if (pathi == null) 207 return; 208 if (!pathslist.contains(pathi.getStringValue())) { 209 paths.add(pathi); 210 pathslist.add(pathi.getStringValue()); 211 } 212 } 213 public void addPaths(ArrayList addpaths) { 214 if (addpaths == null || addpaths.isEmpty()) 215 return; 216 for (int i = 0; i < addpaths.size(); i++) 217 addPath((XQueryExpression) addpaths.get(i)); 218 } 219 public ExecutionPlan getPlan() { 220 return plan; 221 } 222 public TypeVisitor getTypeVisitor() { 223 return plan.getTypeVisitor(); 224 } 225 public SchemaManager getSchemaManager() { 226 return plan.getSchemaManager(); 227 } 228 229 235 257 265 269 278 282 288 292 301 303 311 313 317 public abstract boolean isSource(); 318 319 322 public abstract ArrayList getSources(); 323 324 public void isLet(boolean islet) { 325 this.islet = islet; 326 } 327 public boolean isLet() { 328 return islet; 329 } 330 public abstract void terminate(); 331 332 } 339 | Popular Tags |