KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > expressions > ExpressionNormalizer


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.expressions;
23
24 import java.util.*;
25 import oracle.toplink.essentials.expressions.*;
26 import oracle.toplink.essentials.internal.sessions.AbstractSession;
27
28 /**
29  * This is used during the normalization process to allow for a single main expression traversal.
30  */

31 public class ExpressionNormalizer {
32
33     /** A new root expression can be made from joins being added to the original expression. */
34     protected Expression additionalExpression;
35
36     /** The statement being normalized. */
37     protected SQLSelectStatement statement;
38
39     /** Subselect expressions found in the course of normalization. */
40     protected Vector subSelectExpressions;
41
42     /** The session being normalized in. */
43     protected AbstractSession session;
44
45     public ExpressionNormalizer(SQLSelectStatement statement) {
46         this.statement = statement;
47     }
48
49     public void addAdditionalExpression(Expression theExpression) {
50         // This change puts a null check into every call, but is printing additional
51
// expressions in a meaningfull order worth it?
52
additionalExpression = (additionalExpression == null) ? theExpression : additionalExpression.and(theExpression);
53     }
54
55     /**
56      * INTERNAL:
57      * Remember this subselect so that it can be normalized after the enclosing
58      * select statement is.
59      */

60     public void addSubSelectExpression(SubSelectExpression subSelectExpression) {
61         if (subSelectExpressions == null) {
62             subSelectExpressions = new Vector(1);
63         }
64         subSelectExpressions.add(subSelectExpression);
65     }
66
67     public Expression getAdditionalExpression() {
68         return additionalExpression;
69     }
70
71     public AbstractSession getSession() {
72         return session;
73     }
74
75     public SQLSelectStatement getStatement() {
76         return statement;
77     }
78
79     /**
80      * INTERNAL:
81      * Were subselect expressions found while normalizing the selection criteria?
82      * Assumes underlying collection is initialized on first add.
83      */

84     public boolean encounteredSubSelectExpressions() {
85         return (subSelectExpressions != null);
86     }
87
88     /**
89      * INTERNAL:
90      * Normalize all subselect expressions found in the course of normalizing the
91      * enclosing query.
92      * This method allows one to completely normalize the parent statement first
93      * (which should treat its sub selects as black boxes), and then normalize the
94      * subselects (which require full knowledge of the enclosing statement).
95      * This should make things clearer too,
96      * Assumes encounteredSubSelectExpressions() true.
97      * For CR#4223.
98      */

99     public void normalizeSubSelects(Dictionary clonedExpressions) {
100         for (Enumeration enumtr = subSelectExpressions.elements(); enumtr.hasMoreElements();) {
101             SubSelectExpression next = (SubSelectExpression)enumtr.nextElement();
102             next.normalizeSubSelect(this, clonedExpressions);
103         }
104     }
105
106     public void setAdditionalExpression(Expression additionalExpression) {
107         this.additionalExpression = additionalExpression;
108     }
109
110     public void setSession(AbstractSession session) {
111         this.session = session;
112     }
113
114     public void setStatement(SQLSelectStatement statement) {
115         this.statement = statement;
116     }
117 }
118
Popular Tags