1 21 package oracle.toplink.essentials.internal.queryframework; 23 24 import java.util.List ; 25 26 import oracle.toplink.essentials.exceptions.*; 27 import oracle.toplink.essentials.expressions.*; 28 import oracle.toplink.essentials.mappings.*; 29 import oracle.toplink.essentials.descriptors.ClassDescriptor; 30 import oracle.toplink.essentials.queryframework.*; 31 import oracle.toplink.essentials.internal.expressions.FunctionExpression; 32 import oracle.toplink.essentials.internal.expressions.QueryKeyExpression; 33 34 40 public class ReportItem implements java.io.Serializable { 41 42 43 protected Expression attributeExpression; 44 45 46 protected String name; 47 48 49 protected DatabaseMapping mapping; 50 51 52 protected ClassDescriptor descriptor; 53 54 55 protected Class resultType; 56 57 58 protected JoinedAttributeManager joinManager; 59 60 61 protected int resultIndex; 62 63 public ReportItem() { 64 super(); 65 } 66 67 public ReportItem(String name, Expression attributeExpression) { 68 this.name = name; 69 this.attributeExpression = attributeExpression; 70 this.joinManager = new JoinedAttributeManager(); 71 } 72 73 public Expression getAttributeExpression() { 74 return attributeExpression; 75 } 76 77 public ClassDescriptor getDescriptor(){ 78 return this.descriptor; 79 } 80 81 86 public JoinedAttributeManager getJoinedAttributeManager() { 87 return this.joinManager; 88 } 89 90 public DatabaseMapping getMapping() { 91 return mapping; 92 } 93 94 public String getName() { 95 return name; 96 } 97 98 public int getResultIndex() { 99 return resultIndex; 100 } 101 102 public Class getResultType() { 103 return resultType; 104 } 105 106 110 public void initialize(ReportQuery query) throws QueryException { 111 if (getMapping() == null) { 112 DatabaseMapping mapping = query.getLeafMappingFor(getAttributeExpression(), query.getDescriptor()); 113 if (mapping == null){ 114 if (getAttributeExpression() != null){ 115 if (getAttributeExpression().isExpressionBuilder()) { 116 Class resultClass = ((ExpressionBuilder)getAttributeExpression()).getQueryClass(); 117 if (resultClass == null){ 118 resultClass = query.getReferenceClass(); 119 } 120 setDescriptor(query.getSession().getDescriptor(resultClass)); 121 if (getDescriptor().hasInheritance()){ 122 ((ExpressionBuilder)getAttributeExpression()).setShouldUseOuterJoinForMultitableInheritance(true); 123 } 124 } 125 } 126 }else{ 127 if (mapping.isForeignReferenceMapping()){ 129 setDescriptor(mapping.getReferenceDescriptor()); 130 if (getDescriptor().hasInheritance()){ 131 ((QueryKeyExpression)getAttributeExpression()).setShouldUseOuterJoinForMultitableInheritance(true); 132 } 133 } else if (mapping.isAbstractDirectMapping()){ 134 setMapping((DatabaseMapping)mapping); 135 } else { 136 throw QueryException.invalidExpressionForQueryItem(getAttributeExpression(), query); 137 } 138 } 139 this.joinManager.setDescriptor(this.descriptor); 140 this.joinManager.setBaseQuery(query); 141 if (getAttributeExpression() != null){ 142 if (getAttributeExpression().getBuilder().wasQueryClassSetInternally()){ 143 this.attributeExpression = getAttributeExpression().rebuildOn(query.getExpressionBuilder()); 145 } 146 this.joinManager.setBaseExpressionBuilder(this.attributeExpression.getBuilder()); 147 }else{ 148 this.joinManager.setBaseExpressionBuilder(query.getExpressionBuilder()); 149 } 150 this.joinManager.prepareJoinExpressions(query.getSession()); 151 } 152 } 153 154 public boolean isContructorItem(){ 155 return false; 156 } 157 158 161 public boolean isPlaceHolder() { 162 return getAttributeExpression() == null; 163 } 164 165 public void setDescriptor(ClassDescriptor descriptor){ 166 this.descriptor = descriptor; 167 } 168 169 public void setMapping(DatabaseMapping mapping) { 170 this.mapping = mapping; 171 } 172 173 public void setResultIndex(int resultIndex) { 174 this.resultIndex = resultIndex; 175 this.joinManager.setParentResultIndex(resultIndex); 176 } 177 178 public void setResultType(Class resultType) { 179 this.resultType = resultType; 180 181 if (getAttributeExpression()!=null && getAttributeExpression().isFunctionExpression()) { 183 ((FunctionExpression) getAttributeExpression()).setResultType(resultType); 184 } 185 } 186 187 public String toString() { 188 return "ReportQueryItem(" + getName() + " -> " + getAttributeExpression() + ")"; 189 } 190 191 } 192 | Popular Tags |