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.query.api.NestedField; 30 import org.objectweb.medor.query.api.OperationType; 31 import org.objectweb.medor.query.api.PropagatedField; 32 import org.objectweb.medor.query.api.QueryTreeField; 33 import org.objectweb.medor.query.api.UnnestQueryNode; 34 import org.objectweb.medor.type.lib.QType; 35 36 import java.util.Map ; 37 38 39 public class Unnest extends BasicQueryNode implements UnnestQueryNode { 40 43 protected NestedField unnestedField = null; 44 protected PropagatedField[] projectedFields; 45 46 public Unnest() { 47 } 48 49 public Unnest(QueryTreeField[] queryTreeFields, 50 Field field, 51 String nodeName) 52 throws MedorException { 53 54 super(nodeName); 55 56 this.projectedFields = new PropagatedField[queryTreeFields.length]; 58 59 for (int i = 0; i < queryTreeFields.length; i++) { 60 QueryTreeField[] anc = {queryTreeFields[i]}; 61 this.projectedFields[i] = this.addPropagatedField( 62 queryTreeFields[i].getName(), 63 queryTreeFields[i].getType(), 64 anc); 65 } 66 67 68 if(field.getType().getTypeCode()!=QType.TYPECODE_TUPLE_COLLECTION) 69 throw new MedorException("The field to unnest must be a TupleCollection"); 70 Field[] origs; 71 if (field instanceof PropagatedField) { 72 origs = ((PropagatedField) field).getOriginFields(); 73 } 74 else 75 origs = new Field[] { field }; 76 if (!(origs[0] instanceof NestedField)) 77 throw new MedorException("The support of Tuplecollection fields (which are not NestedFields) is not yet implemented"); 78 79 unnestedField = (NestedField) origs[0]; 80 81 for (int i = 0; i < unnestedField.getSize(); i++) { 84 QueryTreeField[] anc = {unnestedField}; 85 Field f = unnestedField.getFields()[i]; 86 addField(new BasicPropagFromNestedField( 87 getFieldName(nodeName, f.getName()), 88 f.getType(), 89 this, 90 anc, 91 new Field[] {f})); 92 } 93 addChild(unnestedField.getQueryTree()); 94 } 95 96 public Object clone(Object clone, 97 Map obj2clone) throws CloneNotSupportedException { 98 clone = super.clone(clone, obj2clone); 99 Unnest un = (Unnest) clone; 100 un.unnestedField = (NestedField) getClone(unnestedField, obj2clone); 101 if (projectedFields != null) { 102 un.projectedFields = new PropagatedField[projectedFields.length]; 103 for(int i=0; i<projectedFields.length; i++) { 104 un.projectedFields[i] = (PropagatedField) getClone(projectedFields[i], obj2clone); 105 } 106 } 107 return clone; 108 } 109 110 public NestedField getUnnestedField() { 111 return unnestedField; 112 } 113 114 public PropagatedField[] getProjectedFields() { 115 return projectedFields; 116 } 117 118 public short getType() { 119 return OperationType.UNNEST; 120 } 121 122 public void setQueryFilter(Expression e) { 123 throw new UnsupportedOperationException ("Unnest operators cannot be assigned a filter."); 124 } 125 126 } 127 | Popular Tags |