1 23 package org.objectweb.medor.query.lib; 24 25 import org.objectweb.jorm.type.api.PType; 26 import org.objectweb.medor.api.Field; 27 import org.objectweb.medor.api.MedorException; 28 import org.objectweb.medor.api.TupleStructure; 29 import org.objectweb.medor.datasource.api.DataStore; 30 import org.objectweb.medor.datasource.lib.BasicDataStore; 31 import org.objectweb.medor.lib.BasicTupleStructure; 32 import org.objectweb.medor.query.api.QueryTreeField; 33 import org.objectweb.medor.query.api.TCQueryLeaf; 34 import org.objectweb.medor.query.api.OrderField; 35 import org.objectweb.medor.tuple.api.TupleCollection; 36 import org.objectweb.medor.tuple.api.TupleLoader; 37 import org.objectweb.medor.expression.api.Expression; 38 39 import java.util.Map ; 40 41 47 public class MedorTCQueryLeaf extends BasicTupleStructure 48 implements TCQueryLeaf { 49 50 protected TupleCollection tcData; 51 protected TupleLoader loader; 52 protected DataStore ds; 53 protected Expression filter; 54 protected String nodeName; 55 56 public MedorTCQueryLeaf() { 57 } 58 59 public MedorTCQueryLeaf(String nodeName, String tcName, 60 TupleCollection tcData) 61 throws MedorException { 62 super(); 63 this.nodeName = nodeName; 64 this.tcData = tcData; 65 ds = new BasicDataStore(DataStore.MEDORTC_STORE, tcName); 66 } 67 68 public QueryTreeField addField(String fieldName, PType type, Field tcField) 69 throws MedorException { 70 QueryTreeField qtf = 71 new BasicQueryTreeField( 72 getFieldName(nodeName, fieldName), type, this); 73 name2field.put(qtf.getName(), qtf); 74 fields.add(qtf); 75 return qtf; 76 } 77 78 public Object clone(Object clone, 79 Map obj2clone) throws CloneNotSupportedException { 80 clone = super.clone(clone, obj2clone); 81 MedorTCQueryLeaf mql = (MedorTCQueryLeaf) clone; 82 mql.nodeName = nodeName; 83 mql.tcData = tcData; 84 mql.ds = ds; 85 mql.loader = loader; 86 mql.filter = (Expression) getClone(filter, obj2clone); 87 return clone; 88 } 89 90 public String getName() { 91 return nodeName; 92 } 93 94 public TupleStructure getTupleStructure() { 95 return this; 96 } 97 98 public void setDistinct(boolean d) throws MedorException { 99 throw new MedorException("Distinct not yet supported on MedorTCQueryLeaf"); 100 } 101 102 public boolean getDistinct() { 103 return false; 104 } 105 106 public void setOrderBy(OrderField[] orderfields) throws MedorException { 107 throw new MedorException("Order by not supported on MedorTCQueryLeaf"); 108 } 109 110 public OrderField[] getOrderBy() { 111 return null; 112 } 113 114 public DataStore getDataStore() { 115 return ds; 116 } 117 118 public TupleCollection getTupleCollection() { 119 return tcData; 120 } 121 122 public TupleLoader getTupleLoader() { 123 return loader; 124 } 125 126 public void setTupleLoader(TupleLoader tl) { 127 this.loader = tl; 128 } 129 130 public Expression getQueryFilter() { 131 return filter; 132 } 133 134 public void setQueryFilter(Expression filter) { 135 this.filter = filter; 136 } 137 138 private String getFieldName(String nodeName, String fieldName) { 139 if (nodeName == null || nodeName.length() == 0) 140 return fieldName; 141 else 142 return nodeName + "." + fieldName; 143 } 144 145 } 146 | Popular Tags |