1 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.BooleanDataValue; 27 import org.apache.derby.iapi.types.TypeId; 28 29 import org.apache.derby.iapi.sql.compile.C_NodeTypes; 30 31 import org.apache.derby.iapi.error.StandardException; 32 import org.apache.derby.iapi.services.compiler.MethodBuilder; 33 import org.apache.derby.iapi.services.compiler.LocalField; 34 35 import org.apache.derby.iapi.services.sanity.SanityManager; 36 import org.apache.derby.iapi.reference.ClassName; 37 import org.apache.derby.iapi.reference.SQLState; 38 import org.apache.derby.iapi.types.DataTypeDescriptor; 39 40 import java.lang.reflect.Modifier ; 41 import org.apache.derby.impl.sql.compile.ExpressionClassBuilder; 42 import org.apache.derby.impl.sql.compile.ActivationClassBuilder; 43 import org.apache.derby.iapi.services.classfile.VMOpcode; 44 45 import java.util.Vector ; 46 47 abstract class BinaryLogicalOperatorNode extends BinaryOperatorNode 48 { 49 boolean shortCircuitValue; 50 51 60 61 public void init( 62 Object leftOperand, 63 Object rightOperand, 64 Object methodName) 65 { 66 67 super.init(leftOperand, rightOperand, methodName, methodName, 68 ClassName.BooleanDataValue, ClassName.BooleanDataValue); 69 } 70 71 84 85 public ValueNode bindExpression( 86 FromList fromList, SubqueryList subqueryList, 87 Vector aggregateVector) 88 throws StandardException 89 { 90 if (leftOperand.isParameterNode() || rightOperand.isParameterNode()) 92 throw StandardException.newException(SQLState.LANG_NON_BOOLEAN_WHERE_CLAUSE, "PARAMETER" ); 93 if ((leftOperand instanceof UnaryOperatorNode) && 95 ((UnaryOperatorNode)leftOperand).isUnaryMinusOrPlusWithParameter()) 96 throw StandardException.newException(SQLState.LANG_NON_BOOLEAN_WHERE_CLAUSE, "PARAMETER" ); 97 if ((rightOperand instanceof UnaryOperatorNode) && 98 ((UnaryOperatorNode)rightOperand).isUnaryMinusOrPlusWithParameter()) 99 throw StandardException.newException(SQLState.LANG_NON_BOOLEAN_WHERE_CLAUSE, "PARAMETER" ); 100 101 super.bindExpression(fromList, subqueryList, aggregateVector); 102 103 return this; 104 } 105 106 113 boolean verifyEliminateNots() 114 { 115 if (SanityManager.ASSERT) 116 { 117 return (leftOperand.verifyEliminateNots() && 118 rightOperand.verifyEliminateNots()); 119 } 120 else 121 { 122 return true; 123 } 124 } 125 126 137 138 public void generateExpression(ExpressionClassBuilder acb, 139 MethodBuilder mb) 140 throws StandardException 141 { 142 157 158 163 164 leftOperand.generateExpression(acb, mb); 165 167 mb.dup(); 170 mb.push(shortCircuitValue); 172 mb.callMethod(VMOpcode.INVOKEINTERFACE, (String ) null, "equals", "boolean", 1); 174 176 197 198 mb.conditionalIf(); 199 200 mb.callMethod(VMOpcode.INVOKEINTERFACE, (String ) null, "getImmutable", 202 ClassName.BooleanDataValue, 0); 203 204 206 mb.startElseCode(); 207 208 216 217 219 rightOperand.generateExpression(acb, mb); 220 221 mb.upCast(ClassName.BooleanDataValue); 223 224 mb.callMethod(VMOpcode.INVOKEINTERFACE, (String ) null, methodName, ClassName.BooleanDataValue, 1); 225 227 mb.completeConditional(); 228 230 } 231 232 DataTypeDescriptor resolveLogicalBinaryOperator( 233 DataTypeDescriptor leftType, 234 DataTypeDescriptor rightType) 235 throws StandardException 236 { 237 if ( ( ! (leftType.getTypeId().isBooleanTypeId()) ) || 238 ( ! (rightType.getTypeId().isBooleanTypeId()) ) ) 239 { 240 throw StandardException.newException(SQLState.LANG_BINARY_LOGICAL_NON_BOOLEAN); 241 } 242 243 return new DataTypeDescriptor(leftType, 244 leftType.isNullable() || rightType.isNullable()); 245 } 246 } 247 | Popular Tags |