1 21 package oracle.toplink.essentials.internal.parsing; 23 24 import oracle.toplink.essentials.queryframework.*; 25 import oracle.toplink.essentials.internal.sessions.AbstractSession; 26 27 39 public class EJBQLParseTree extends ParseTree { 40 41 44 public EJBQLParseTree() { 45 super(); 46 } 47 48 52 public GenerationContext buildContext(ReadQuery readQuery, AbstractSession session) { 53 GenerationContext contextForGeneration = super.buildContext(readQuery, session); 54 55 contextForGeneration.setBaseQueryClass(readQuery.getReferenceClass()); 56 return contextForGeneration; 57 } 58 59 64 private GenerationContext buildSubqueryContext(ReadQuery readQuery, GenerationContext outer) { 65 GenerationContext context = new SelectGenerationContext(outer, this); 66 context.setBaseQueryClass(readQuery.getReferenceClass()); 67 return context; 68 } 69 70 77 public GenerationContext populateSubquery(ObjectLevelReadQuery readQuery, GenerationContext outer) { 78 GenerationContext innerContext = buildSubqueryContext(readQuery, outer); 79 populateReadQueryInternal(readQuery, innerContext); 80 return innerContext; 81 } 82 83 89 public void populateQuery(DatabaseQuery query, AbstractSession session) { 90 if (query.isObjectLevelReadQuery()) { 91 ObjectLevelReadQuery objectQuery = (ObjectLevelReadQuery)query; 92 GenerationContext generationContext = buildContext(objectQuery, session); 93 populateReadQueryInternal(objectQuery, generationContext); 94 } else if (query.isUpdateAllQuery()) { 95 UpdateAllQuery updateQuery = (UpdateAllQuery)query; 96 GenerationContext generationContext = buildContext(updateQuery, session); 97 populateModifyQueryInternal(updateQuery, generationContext); 98 addUpdatesToQuery(updateQuery, generationContext); 99 } else if (query.isDeleteAllQuery()) { 100 DeleteAllQuery deleteQuery = (DeleteAllQuery)query; 101 GenerationContext generationContext = buildContext(deleteQuery, session); 102 populateModifyQueryInternal(deleteQuery, generationContext); 103 } 104 } 105 106 private void populateReadQueryInternal(ObjectLevelReadQuery objectQuery, 107 GenerationContext generationContext) { 108 if (objectQuery.getReferenceClass() == null) { 111 adjustReferenceClassForQuery(objectQuery, generationContext); 113 } 114 115 initBaseExpression(objectQuery, generationContext); 117 118 validate(generationContext.getSession(), getClassLoader()); 120 121 applyQueryNodeToQuery(objectQuery, generationContext); 123 124 verifySelect(objectQuery, generationContext); 126 127 setSelectionCriteriaForQuery(objectQuery, generationContext); 129 130 addOrderingToQuery(objectQuery, generationContext); 132 133 addGroupingToQuery(objectQuery, generationContext); 135 136 addHavingToQuery(objectQuery, generationContext); 138 139 addNonFetchJoinAttributes(objectQuery, generationContext); 141 } 142 143 private void populateModifyQueryInternal(ModifyAllQuery query, 144 GenerationContext generationContext) { 145 if (query.getReferenceClass() == null) { 146 adjustReferenceClassForQuery(query, generationContext); 148 } 149 query.setSession(generationContext.getSession()); 150 151 initBaseExpression(query, generationContext); 153 154 validate(generationContext.getSession(), getClassLoader()); 156 157 applyQueryNodeToQuery(query, generationContext); 159 160 setSelectionCriteriaForQuery(query, generationContext); 161 } 162 163 } 164 | Popular Tags |