KickJava   Java API By Example, From Geeks To Geeks.

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


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 oracle.toplink.essentials.exceptions.*;
25 import oracle.toplink.essentials.queryframework.*;
26 import oracle.toplink.essentials.expressions.*;
27 import oracle.toplink.essentials.internal.sessions.AbstractRecord;
28 import oracle.toplink.essentials.internal.sessions.AbstractSession;
29 import oracle.toplink.essentials.descriptors.ClassDescriptor;
30
31 /**
32  * Used for logical AND and OR. This is not used by NOT.
33  */

34 public class LogicalExpression extends CompoundExpression {
35
36     /**
37      * LogicalExpression constructor comment.
38      */

39     public LogicalExpression() {
40         super();
41     }
42
43     /**
44      * INTERNAL:
45      * Used for debug printing.
46      */

47     public String JavaDoc descriptionOfNodeType() {
48         return "Logical";
49     }
50
51     /**
52      * INTERNAL:
53      * Check if the object conforms to the expression in memory.
54      * This is used for in-memory querying.
55      * If the expression in not able to determine if the object conform throw a not supported exception.
56      */

57     public boolean doesConform(Object JavaDoc object, AbstractSession session, AbstractRecord translationRow, InMemoryQueryIndirectionPolicy valueHolderPolicy, boolean objectIsUnregistered) {
58         // This should always be and or or.
59
if (getOperator().getSelector() == ExpressionOperator.And) {
60             return getFirstChild().doesConform(object, session, translationRow, valueHolderPolicy, objectIsUnregistered) && getSecondChild().doesConform(object, session, translationRow, valueHolderPolicy, objectIsUnregistered);
61         } else if (getOperator().getSelector() == ExpressionOperator.Or) {
62             return getFirstChild().doesConform(object, session, translationRow, valueHolderPolicy, objectIsUnregistered) || getSecondChild().doesConform(object, session, translationRow, valueHolderPolicy, objectIsUnregistered);
63         }
64
65         throw QueryException.cannotConformExpression();
66
67     }
68
69     /**
70      * INTERNAL:
71      * Extract the primary key from the expression into the row.
72      * Ensure that the query is quering the exact primary key.
73      * Return false if not on the primary key.
74      */

75     public boolean extractPrimaryKeyValues(boolean requireExactMatch, ClassDescriptor descriptor, AbstractRecord primaryKeyRow, AbstractRecord translationRow) {
76         // If this is a primary key expression then it can only have and/or relationships.
77
if (getOperator().getSelector() != ExpressionOperator.And) {
78             // If this is an exact primary key expression it can not have ors.
79
// After fixing bug 2782991 this must now work correctly.
80
if (requireExactMatch || (getOperator().getSelector() != ExpressionOperator.Or)) {
81                 return false;
82             }
83         }
84         boolean validExpression = getFirstChild().extractPrimaryKeyValues(requireExactMatch, descriptor, primaryKeyRow, translationRow);
85         if (requireExactMatch && (!validExpression)) {
86             return false;
87         }
88         return getSecondChild().extractPrimaryKeyValues(requireExactMatch, descriptor, primaryKeyRow, translationRow);
89     }
90
91     /**
92      * INTERNAL:
93      */

94     public boolean isLogicalExpression() {
95         return true;
96     }
97 }
98
Popular Tags