1 23 24 package org.objectweb.medor.eval.lib; 25 26 import org.objectweb.medor.api.MedorException; 27 import org.objectweb.medor.api.QueryNodeException; 28 import org.objectweb.medor.eval.api.NodeEvaluator; 29 import org.objectweb.medor.eval.api.EvaluationMetaData; 30 import org.objectweb.medor.eval.cache.lib.TupleCache; 31 import org.objectweb.medor.eval.cache.lib.WindowCachedTupleCollection; 32 import org.objectweb.medor.eval.prefetch.api.PrefetchBuffer; 33 import org.objectweb.medor.expression.api.ParameterOperand; 34 import org.objectweb.medor.query.api.NestQueryNode; 35 import org.objectweb.medor.query.api.OperationType; 36 import org.objectweb.medor.query.api.QueryNode; 37 import org.objectweb.medor.query.api.UnnestQueryNode; 38 import org.objectweb.medor.tuple.api.TupleCollection; 39 40 public class UnaryIteratifNodeEvaluator implements NodeEvaluator { 41 42 QueryNode query; 43 NodeEvaluator subNodeEvaluator; 44 long cacheSize; 45 boolean open = false; 46 PrefetchBuffer prefetchBuffer; 47 EvaluationMetaData evaluationMetaData; 48 49 public UnaryIteratifNodeEvaluator(QueryNode query, 50 NodeEvaluator subNodeEvaluator, 51 EvaluationMetaData evaluationMetaData) { 52 this.query = query; 53 this.subNodeEvaluator = subNodeEvaluator; 54 this.evaluationMetaData = evaluationMetaData; 55 } 56 57 public boolean linkChildren() { 58 open = true; 60 return true; 61 } 62 63 public boolean unlinkChildren() { 64 open = false; 66 return true; 67 } 68 69 public TupleCollection fetchData(ParameterOperand[] parameters) 70 throws MedorException { 71 TupleCollection res = null; 72 switch (query.getType()) { 73 case OperationType.NEST: 74 res = new NestEvaluatedTC((NestQueryNode) query, 75 subNodeEvaluator, 76 parameters, 77 evaluationMetaData); 78 break; 79 case OperationType.PROJECT: 80 res = new ProjectEvaluatedTC(query, 81 subNodeEvaluator, 82 parameters, 83 prefetchBuffer); 84 break; 85 case OperationType.SELECT_PROJECT: 86 if (query.getQueryFilter() == null) { 87 res = new ProjectEvaluatedTC(query, 88 subNodeEvaluator, 89 parameters, 90 prefetchBuffer); 91 } else { 92 res = new SelProjEvaluatedTC(query, 93 subNodeEvaluator, 94 parameters, 95 prefetchBuffer); 96 } 97 break; 98 case OperationType.UNNEST: 99 res = new UnnestEvaluatedTC( 100 (UnnestQueryNode) query, subNodeEvaluator, parameters); 101 break; 102 default: 103 throw new QueryNodeException("Unreconized QueryNode: " + query); 104 } 105 if (evaluationMetaData == null) { 106 return res; 108 } else if (evaluationMetaData.isCache()) { 109 return new WindowCachedTupleCollection( 110 res, new TupleCache(cacheSize)); 111 } else { 112 return res; 113 } 114 } 115 116 public void setPrefetchBuffer(PrefetchBuffer pb) throws MedorException { 117 prefetchBuffer = pb; 118 } 119 120 public long getCacheSize() { 121 return cacheSize; 122 } 123 124 public void setCacheSize(long cacheSize) { 125 this.cacheSize = cacheSize; 126 } 127 128 public QueryNode getQueryNode() { 129 return query; 130 } 131 132 public EvaluationMetaData getEvaluationMetaData() { 133 return evaluationMetaData; 134 } 135 136 } 137 | Popular Tags |