KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > compile > NotNode


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.compile.NotNode
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.sql.compile;
23
24 import org.apache.derby.iapi.services.compiler.MethodBuilder;
25 import org.apache.derby.iapi.services.compiler.LocalField;
26 import org.apache.derby.iapi.reference.ClassName;
27
28
29 import org.apache.derby.iapi.services.sanity.SanityManager;
30
31 import org.apache.derby.iapi.error.StandardException;
32
33 import org.apache.derby.iapi.types.TypeId;
34
35 import org.apache.derby.iapi.types.DataValueDescriptor;
36 import org.apache.derby.iapi.types.BooleanDataValue;
37 import org.apache.derby.iapi.types.TypeId;
38 import org.apache.derby.iapi.types.DataTypeDescriptor;
39
40 import org.apache.derby.impl.sql.compile.ExpressionClassBuilder;
41 import org.apache.derby.iapi.services.classfile.VMOpcode;
42
43 import java.lang.reflect.Modifier JavaDoc;
44
45 /**
46  * A NotNode represents a NOT operator. Preprocessing will eliminate the
47  * NotNodes which exist above comparison operators so that the optimizer
48  * will see a query tree in CNF.
49  *
50  * @author Jerry Brenner
51  */

52
53 public final class NotNode extends UnaryLogicalOperatorNode
54 {
55     /**
56      * Initializer for a NotNode
57      *
58      * @param operand The operand of the NOT
59      */

60
61     public void init(Object JavaDoc operand)
62     {
63         super.init(operand, "not");
64     }
65
66     /**
67      * Eliminate NotNodes in the current query block. We traverse the tree,
68      * inverting ANDs and ORs and eliminating NOTs as we go. We stop at
69      * ComparisonOperators and boolean expressions. We invert
70      * ComparisonOperators and replace boolean expressions with
71      * boolean expression = false.
72      *
73      * @param underNotNode Whether or not we are under a NotNode.
74      *
75      *
76      * @return The modified expression
77      *
78      * @exception StandardException Thrown on error
79      */

80     ValueNode eliminateNots(boolean underNotNode)
81                     throws StandardException
82     {
83         return operand.eliminateNots(! underNotNode);
84     }
85
86     /**
87      * Do code generation for the NOT operator.
88      *
89      * @param acb The ExpressionClassBuilder for the class we're generating
90      * @param mb The method the expression will go into
91      *
92      * @exception StandardException Thrown on error
93      */

94
95     public void generateExpression(ExpressionClassBuilder acb,
96                                             MethodBuilder mb)
97                                     throws StandardException
98     {
99         /*
100         ** This generates the following code:
101         **
102         ** <boolean field> = <operand>.equals(<operand>,
103         ** <false truth value>);
104         */

105
106         /*
107         ** Generate the code for a Boolean false constant value.
108         */

109         String JavaDoc interfaceName = getTypeCompiler().interfaceName();
110         LocalField field = acb.newFieldDeclaration(Modifier.PRIVATE, interfaceName);
111         /*
112         ** Generate the call to the equals method.
113         ** equals is only on Orderable, not any subinterfaces.
114         */

115
116         /* Generate the code for operand */
117         operand.generateExpression(acb, mb);
118         mb.upCast(ClassName.DataValueDescriptor);
119
120         mb.dup(); // arg 1 is instance
121

122         // arg 2
123
mb.push(false);
124         acb.generateDataValue(mb, getTypeCompiler(), field);
125         mb.upCast(ClassName.DataValueDescriptor);
126
127         mb.callMethod(VMOpcode.INVOKEINTERFACE, (String JavaDoc) null, "equals", interfaceName, 2);
128     }
129 }
130
Popular Tags