KickJava   Java API By Example, From Geeks To Geeks.

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


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.querykeys.*;
26 import oracle.toplink.essentials.expressions.*;
27 import oracle.toplink.essentials.descriptors.ClassDescriptor;
28
29 /**
30  * This class represents a "query key" that isn't really there
31  * in the descriptors. For example, I could use this to create
32  * an 'employee' query key from an 'address' node even if addresses
33  * don't know their employee. It's called manual, because I will
34  * have to provide the relevant join criteria myself (normally based
35  * on a reverse relationship. Motivated by batch reading.
36  */

37 public class ManualQueryKeyExpression extends QueryKeyExpression {
38     public ManualQueryKeyExpression() {
39         super();
40     }
41
42     public ManualQueryKeyExpression(String JavaDoc impliedRelationshipName, Expression base) {
43         super(impliedRelationshipName, base);
44     }
45
46     public ManualQueryKeyExpression(String JavaDoc impliedRelationshipName, Expression base, ClassDescriptor descriptor) {
47         super(impliedRelationshipName, base);
48         this.descriptor = descriptor;
49     }
50
51     /**
52      * INTERNAL:
53      * Used for debug printing.
54      */

55     public String JavaDoc descriptionOfNodeType() {
56         return "Manual Query Key";
57     }
58
59     /**
60      * INTERNAL:
61      * If we ever get in the circumstance of a manual query key
62      * to an aggregate, then we can assume that the owner of that
63      * aggregate isn't participating (and even if it is, we can't
64      * know which node it is, so *DO* use the aggregate's parents tables
65      */

66     public Vector getOwnedTables() {
67         if (getDescriptor() == null) {
68             return null;
69         } else {
70             return getDescriptor().getTables();
71         }
72     }
73
74     public QueryKey getQueryKeyOrNull() {
75         return null;
76     }
77
78     /**
79      * INTERNAL:
80      * We can never be an attribute, we're always a join
81      */

82     public boolean isAttribute() {
83         return false;
84     }
85
86     public Expression mappingCriteria() {
87         return null;
88     }
89
90     /**
91      * INTERNAL:
92      * This expression is built on a different base than the one we want. Rebuild it and
93      * return the root of the new tree
94      */

95     public Expression rebuildOn(Expression newBase) {
96         ObjectExpression newLocalBase = (ObjectExpression)getBaseExpression().rebuildOn(newBase);
97         return newLocalBase.getManualQueryKey(getName(), getDescriptor());
98     }
99
100     /**
101      * INTERNAL:
102      * Rebuild myself against the base, with the values of parameters supplied by the context
103      * expression. This is used for transforming a standalone expression (e.g. the join criteria of a mapping)
104      * into part of some larger expression. You normally would not call this directly, instead calling twist
105      * See the comment there for more details"
106      */

107     public Expression twistedForBaseAndContext(Expression newBase, Expression context) {
108         ObjectExpression twistedBase = (ObjectExpression)getBaseExpression().twistedForBaseAndContext(newBase, context);
109         return twistedBase.getManualQueryKey(getName(), getDescriptor());
110
111     }
112
113     /**
114      * Do any required validation for this node. Throw an exception if it's incorrect.
115      */

116     public void validateNode() {
117         // Override super.validateNode() because those criteria don't apply to us
118
}
119 }
120
Popular Tags