001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * // Copyright (c) 1998, 2007, Oracle. All rights reserved.
005: *
006: *
007: * The contents of this file are subject to the terms of either the GNU
008: * General Public License Version 2 only ("GPL") or the Common Development
009: * and Distribution License("CDDL") (collectively, the "License"). You
010: * may not use this file except in compliance with the License. You can obtain
011: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
012: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
013: * language governing permissions and limitations under the License.
014: *
015: * When distributing the software, include this License Header Notice in each
016: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
017: * Sun designates this particular file as subject to the "Classpath" exception
018: * as provided by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the License
020: * Header, with the fields enclosed by brackets [] replaced by your own
021: * identifying information: "Portions Copyrighted [year]
022: * [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * If you wish your version of this file to be governed by only the CDDL or
027: * only the GPL Version 2, indicate your decision by adding "[Contributor]
028: * elects to include this software in this distribution under the [CDDL or GPL
029: * Version 2] license." If you don't indicate a single choice of license, a
030: * recipient has the option to distribute your version of this file under
031: * either the CDDL, the GPL Version 2 or to extend the choice of license to
032: * its licensees as provided above. However, if you add GPL Version 2 code
033: * and therefore, elected the GPL Version 2 license, then the option applies
034: * only if the new code is made subject to such option by the copyright
035: * holder.
036: */
037: package oracle.toplink.essentials.internal.parsing;
038:
039: // Java imports
040: import java.util.Hashtable;
041: import java.util.Set;
042:
043: // TopLink imports
044: import oracle.toplink.essentials.internal.sessions.AbstractSession;
045: import oracle.toplink.essentials.expressions.Expression;
046: import oracle.toplink.essentials.expressions.ExpressionBuilder;
047:
048: /**
049: * INTERNAL
050: * <p><b>Purpose</b>: Maintain the generation context for an EJBQL query
051: * <p><b>Responsibilities</b>:<ul>
052: * <li> Maintain a table of expression builders and alias's
053: * <li> Maintain the base query class
054: * <li> Maintain a handle to the session
055: * <li> Maintain a handle to the parse tree
056: * </ul>
057: * @author Jon Driscoll and Joel Lucuik
058: * @since TopLink 4.0
059: */
060: public class GenerationContext {
061: protected AbstractSession session;
062: protected ParseTreeContext parseTreeContext;
063: protected Class baseQueryClass;
064: protected Expression baseExpression;
065: protected Hashtable expressions;
066: protected ParseTree parseTree;
067: protected boolean isNotIndicatedInMemberOf = false;
068:
069: //If a NOT MEMBER OF is encountered, we need to store the MEMBER OF
070: //so that the right side of the member of can use the stored expression
071: //from the left
072: protected MemberOfNode memberOfNode = null;
073:
074: public GenerationContext() {
075: super ();
076: expressions = new Hashtable();
077: }
078:
079: public GenerationContext(ParseTreeContext newContext,
080: AbstractSession newSession, ParseTree newParseTree) {
081: super ();
082: parseTreeContext = newContext;
083: session = newSession;
084: expressions = new Hashtable();
085: parseTree = newParseTree;
086: }
087:
088: public void addExpression(Expression expression, String aliasName) {
089: expressions.put(aliasName, expression);
090: }
091:
092: public Expression expressionFor(String aliasName) {
093: return (Expression) expressions.get(aliasName);
094: }
095:
096: public Class getBaseQueryClass() {
097: return baseQueryClass;
098: }
099:
100: public ParseTreeContext getParseTreeContext() {
101: return parseTreeContext;
102: }
103:
104: public ParseTree getParseTree() {
105: return parseTree;
106: }
107:
108: public AbstractSession getSession() {
109: return session;
110: }
111:
112: public void setBaseQueryClass(java.lang.Class newBaseQueryClass) {
113: baseQueryClass = newBaseQueryClass;
114: }
115:
116: /**
117: * Caches the specified expression under the variable name for the base
118: * query class.
119: */
120: public void setBaseExpression(String variable, Expression expr) {
121: // Store the expression for faster access
122: baseExpression = expr;
123:
124: // Store it into the cache
125: addExpression(expr, variable);
126: }
127:
128: /** */
129: public Expression getBaseExpression() {
130: return baseExpression;
131: }
132:
133: public void setParseTree(ParseTree parseTree) {
134: this .parseTree = parseTree;
135: }
136:
137: public void setParseTreeContext(ParseTreeContext newParseTreeContext) {
138: parseTreeContext = newParseTreeContext;
139: }
140:
141: public void setSession(AbstractSession newSession) {
142: session = newSession;
143: }
144:
145: //Answer true if we need to use parallel expressions
146: //This will be the case if a 1:1 is SELECTed in the EJBQL.
147: public boolean useParallelExpressions() {
148: return false;
149: }
150:
151: //Answer true if we want VariableNodes to check if they're
152: //SELECTed first, to determine how to instantiate the ExpressionBuilder
153: public boolean shouldCheckSelectNodeBeforeResolving() {
154: return false;
155: }
156:
157: //Set and get the contained MemberOfNode. This is for handling NOT MEMBER OF.
158: public void setMemberOfNode(MemberOfNode newMemberOfNode) {
159: memberOfNode = newMemberOfNode;
160: }
161:
162: public MemberOfNode getMemberOfNode() {
163: return memberOfNode;
164: }
165:
166: //Answer true if we have a MemberOfNode contained. This is for handling NOT MEMBER OF
167: public boolean hasMemberOfNode() {
168: return memberOfNode != null;
169: }
170:
171: //Answer true if we should use outer joins in our get() (vs getAllowingNull())
172: public boolean shouldUseOuterJoins() {
173: return false;
174: }
175:
176: /** */
177: public Expression joinVariables(Set variables) {
178: return null;
179: }
180: }
|