KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.compile.UnaryLogicalOperatorNode
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.sql.dictionary.DataDictionary;
25
26 import org.apache.derby.iapi.types.TypeId;
27
28 import org.apache.derby.iapi.reference.SQLState;
29 import org.apache.derby.iapi.error.StandardException;
30 import org.apache.derby.iapi.types.DataTypeDescriptor;
31
32 import org.apache.derby.iapi.services.sanity.SanityManager;
33
34 import java.util.Vector JavaDoc;
35
36 public abstract class UnaryLogicalOperatorNode extends UnaryOperatorNode
37 {
38     /**
39      * Initializer for a UnaryLogicalOperatorNode
40      *
41      * @param operand The operand of the operator
42      * @param methodName The name of the method to call in the generated
43      * class. In this case, it's actually an operator
44      * name.
45      */

46
47     public void init(
48                 Object JavaDoc operand,
49                 Object JavaDoc methodName)
50     {
51         /* For logical operators, the operator and method names are the same */
52         super.init(operand, methodName, methodName);
53     }
54
55     /**
56      * Bind this logical operator. All that has to be done for binding
57      * a logical operator is to bind the operand, check that the operand
58      * is SQLBoolean, and set the result type to SQLBoolean.
59      *
60      * @param fromList The query's FROM list
61      * @param subqueryList The subquery list being built as we find SubqueryNodes
62      * @param aggregateVector The aggregate vector being built as we find AggregateNodes
63      *
64      * @return The new top of the expression tree.
65      *
66      * @exception StandardException Thrown on error
67      */

68
69     public ValueNode bindExpression(
70         FromList fromList, SubqueryList subqueryList,
71         Vector JavaDoc aggregateVector)
72             throws StandardException
73     {
74         super.bindExpression(fromList, subqueryList,
75                              aggregateVector);
76
77         /*
78         ** Logical operators work only on booleans. If the operand
79         ** is not boolean, throw an exception.
80         **
81         ** For now, this exception will never happen, because the grammar
82         ** does not allow arbitrary expressions with NOT. But when
83         ** we start allowing generalized boolean expressions, we will modify
84         ** the grammar, so this test will become useful.
85         */

86
87         if ( ! operand.getTypeServices().getTypeId().equals(TypeId.BOOLEAN_ID))
88         {
89 operand.treePrint();
90             throw StandardException.newException(SQLState.LANG_UNARY_LOGICAL_NON_BOOLEAN);
91         }
92
93         /* Set the type info */
94         setFullTypeInfo();
95
96         return this;
97     }
98         
99     /**
100      * Set all of the type info (nullability and DataTypeServices) for
101      * this node. Extracts out tasks that must be done by both bind()
102      * and post-bind() AndNode generation.
103      *
104      * @exception StandardException Thrown on error
105      */

106     protected void setFullTypeInfo()
107         throws StandardException
108     {
109         boolean nullableResult;
110
111         /*
112         ** Set the result type of this comparison operator based on the
113         ** operands. The result type is always SQLBoolean - the only question
114         ** is whether it is nullable or not. If either of the operands is
115         ** nullable, the result of the comparison must be nullable, too, so
116         ** we can represent the unknown truth value.
117         */

118         nullableResult = operand.getTypeServices().isNullable();
119         setType(new DataTypeDescriptor(TypeId.BOOLEAN_ID, nullableResult));
120     }
121 }
122
Popular Tags