KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > parsing > GenerationContext


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2006, Oracle. All rights reserved.
22
package oracle.toplink.essentials.internal.parsing;
23
24
25 // Java imports
26
import java.util.Hashtable JavaDoc;
27 import java.util.Set JavaDoc;
28
29 // TopLink imports
30
import oracle.toplink.essentials.internal.sessions.AbstractSession;
31 import oracle.toplink.essentials.expressions.Expression;
32 import oracle.toplink.essentials.expressions.ExpressionBuilder;
33
34 /**
35  * INTERNAL
36  * <p><b>Purpose</b>: Maintain the generation context for an EJBQL query
37  * <p><b>Responsibilities</b>:<ul>
38  * <li> Maintain a table of expression builders and alias's
39  * <li> Maintain the base query class
40  * <li> Maintain a handle to the session
41  * <li> Maintain a handle to the parse tree
42  * </ul>
43  * @author Jon Driscoll and Joel Lucuik
44  * @since TopLink 4.0
45  */

46 public class GenerationContext {
47     protected AbstractSession session;
48     protected ParseTreeContext parseTreeContext;
49     protected Class JavaDoc baseQueryClass;
50     protected Expression baseExpression;
51     protected Hashtable JavaDoc expressions;
52     protected ParseTree parseTree;
53     protected boolean isNotIndicatedInMemberOf = false;
54
55     //If a NOT MEMBER OF is encountered, we need to store the MEMBER OF
56
//so that the right side of the member of can use the stored expression
57
//from the left
58
protected MemberOfNode memberOfNode = null;
59
60     public GenerationContext() {
61         super();
62         expressions = new Hashtable JavaDoc();
63     }
64
65     public GenerationContext(ParseTreeContext newContext, AbstractSession newSession, ParseTree newParseTree) {
66         super();
67         parseTreeContext = newContext;
68         session = newSession;
69         expressions = new Hashtable JavaDoc();
70         parseTree = newParseTree;
71     }
72
73     public void addExpression(Expression expression, String JavaDoc aliasName) {
74         expressions.put(aliasName, expression);
75     }
76
77     public Expression expressionFor(String JavaDoc aliasName) {
78         return (Expression)expressions.get(aliasName);
79     }
80
81     public Class JavaDoc getBaseQueryClass() {
82         return baseQueryClass;
83     }
84
85     public ParseTreeContext getParseTreeContext() {
86         return parseTreeContext;
87     }
88
89     public ParseTree getParseTree() {
90         return parseTree;
91     }
92
93     public AbstractSession getSession() {
94         return session;
95     }
96
97     public void setBaseQueryClass(java.lang.Class JavaDoc newBaseQueryClass) {
98         baseQueryClass = newBaseQueryClass;
99     }
100
101     /**
102      * Caches the specified expression under the variable name for the base
103      * query class.
104      */

105     public void setBaseExpression(String JavaDoc variable, Expression expr) {
106         // Store the expression for faster access
107
baseExpression = expr;
108         
109         // Store it into the cache
110
addExpression(expr, variable);
111     }
112
113     /** */
114     public Expression getBaseExpression() {
115         return baseExpression;
116     }
117
118     public void setParseTree(ParseTree parseTree) {
119         this.parseTree = parseTree;
120     }
121
122     public void setParseTreeContext(ParseTreeContext newParseTreeContext) {
123         parseTreeContext = newParseTreeContext;
124     }
125
126     public void setSession(AbstractSession newSession) {
127         session = newSession;
128     }
129
130     //Answer true if we need to use parallel expressions
131
//This will be the case if a 1:1 is SELECTed in the EJBQL.
132
public boolean useParallelExpressions() {
133         return false;
134     }
135
136     //Answer true if we want VariableNodes to check if they're
137
//SELECTed first, to determine how to instantiate the ExpressionBuilder
138
public boolean shouldCheckSelectNodeBeforeResolving() {
139         return false;
140     }
141
142     //Set and get the contained MemberOfNode. This is for handling NOT MEMBER OF.
143
public void setMemberOfNode(MemberOfNode newMemberOfNode) {
144         memberOfNode = newMemberOfNode;
145     }
146
147     public MemberOfNode getMemberOfNode() {
148         return memberOfNode;
149     }
150
151     //Answer true if we have a MemberOfNode contained. This is for handling NOT MEMBER OF
152
public boolean hasMemberOfNode() {
153         return memberOfNode != null;
154     }
155
156     //Answer true if we should use outer joins in our get() (vs getAllowingNull())
157
public boolean shouldUseOuterJoins() {
158         return false;
159     }
160
161     /** */
162     public Expression joinVariables(Set JavaDoc variables) {
163         return null;
164     }
165 }
166
Popular Tags