1 23 24 package org.objectweb.medor.query.lib; 25 26 import org.objectweb.medor.api.Field; 27 import org.objectweb.medor.api.MedorException; 28 import org.objectweb.medor.expression.api.Expression; 29 import org.objectweb.medor.expression.lib.And; 30 import org.objectweb.medor.expression.lib.Equal; 31 import org.objectweb.medor.filter.lib.BasicFieldOperand; 32 import org.objectweb.medor.query.api.OperationType; 33 import org.objectweb.medor.query.api.QueryTree; 34 import org.objectweb.medor.query.api.QueryTreeField; 35 36 import java.util.Map ; 37 38 42 public class Intersection extends BasicQueryNode { 43 44 45 51 private Expression[] stack; 52 53 public Intersection() { 54 } 55 56 public Intersection(QueryTree leftQT, 57 QueryTree rightQT, 58 String name) 59 throws MedorException { 60 super(name); 61 62 Field[] lfs = leftQT.getTupleStructure().getFields(); 63 Field[] rfs = rightQT.getTupleStructure().getFields(); 64 if (lfs.length != rfs.length) { 67 throw new MedorException( 68 "The intersection must be with the same Tuple Collection"); 69 } 70 indexes = new int[lfs.length]; 71 stack = new Expression[4 * lfs.length - 1]; 72 for(int i=1; i<lfs.length; i++) { 73 if ( !lfs[i].getName().equalsIgnoreCase(rfs[i].getName()) 75 || 76 !(lfs[i].getType().isa(rfs[i].getType()) 78 || rfs[i].getType().isa(lfs[i].getType()))) { 79 throw new MedorException( 80 "The intersection must be with the same Tuple Collection"); 81 } 82 83 addPropagatedField( 85 lfs[i].getName(), 86 lfs[i].getType(), 87 new QueryTreeField[] {(QueryTreeField)lfs[i], 88 (QueryTreeField)rfs[i]}); 89 90 stack[4*(i-1)] = new BasicFieldOperand(lfs[i]); 94 stack[4*(i-1) + 1] = new BasicFieldOperand(rfs[i]); 95 stack[4*(i-1) + 2] = new Equal(stack[4*i-1], stack[4*i]); 96 if (i>1) { 97 stack[4*(i-1) + 3] = new And(stack[4*i+1], stack[4*i-2]); 98 } 99 indexes[i] = i; 100 } 101 } 102 103 public Object clone(Object clone, 104 Map obj2clone) throws CloneNotSupportedException { 105 clone = super.clone(clone, obj2clone); 106 Intersection intersec = (Intersection) clone; 107 if (stack != null) { 108 intersec.stack = new Expression[stack.length]; 109 for(int i=1; i<stack.length; i++) { 110 intersec.stack[i] = (Expression) getClone(stack[i], obj2clone); 111 } 112 } 113 return clone; 114 } 115 116 public void setQueryFilter(Expression f) { 117 throw new UnsupportedOperationException ("Intersections cannot be assigned a filter."); 118 } 119 120 public Expression getQueryFilter() { 121 return stack[stack.length-1]; 122 } 123 124 public short getType() { 125 return OperationType.INTERSECTION; 126 } 127 } 128 | Popular Tags |