1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.services.compiler.MethodBuilder; 25 26 import org.apache.derby.iapi.error.StandardException; 27 28 import org.apache.derby.iapi.sql.compile.Optimizable; 29 30 import org.apache.derby.iapi.types.BooleanDataValue; 31 import org.apache.derby.iapi.types.DataValueDescriptor; 32 import org.apache.derby.iapi.types.TypeId; 33 34 import org.apache.derby.impl.sql.compile.ExpressionClassBuilder; 35 36 import org.apache.derby.iapi.util.ReuseFactory; 37 import java.sql.Types ; 38 39 public final class BooleanConstantNode extends ConstantNode 40 { 41 44 boolean booleanValue; 45 boolean unknownValue; 46 47 54 public void init( 55 Object arg1) 56 throws StandardException 57 { 58 62 63 if (arg1 instanceof Boolean ) 64 { 65 66 super.init(TypeId.BOOLEAN_ID, 67 Boolean.FALSE, 68 ReuseFactory.getInteger(1)); 69 70 booleanValue = ((Boolean ) arg1).booleanValue(); 71 super.setValue(getDataValueFactory().getDataValue(booleanValue)); 72 } 73 else 74 { 75 super.init( 76 arg1, 77 Boolean.TRUE, 78 ReuseFactory.getInteger(0)); 79 unknownValue = true; 80 } 81 } 82 83 89 90 95 102 103 108 119 Object getConstantValueAsObject() 120 { 121 return booleanValue ? Boolean.TRUE : Boolean.FALSE; 122 } 123 124 130 String getValueAsString() 131 { 132 if (booleanValue) 133 { 134 return "true"; 135 } 136 else 137 { 138 return "false"; 139 } 140 } 141 142 147 boolean isBooleanTrue() 148 { 149 return (booleanValue && !unknownValue); 150 } 151 152 157 boolean isBooleanFalse() 158 { 159 return (!booleanValue && !unknownValue); 160 } 161 162 166 public double selectivity(Optimizable optTable) 167 { 168 if (isBooleanTrue()) 169 { 170 return 1.0; 171 } 172 else 173 { 174 return 0.0; 175 } 176 } 177 178 193 ValueNode eliminateNots(boolean underNotNode) 194 { 195 if (! underNotNode) 196 { 197 return this; 198 } 199 200 booleanValue = !booleanValue; 201 super.setValue(getDataValueFactory().getDataValue(booleanValue)); 202 203 return this; 204 } 205 206 214 void generateConstant(ExpressionClassBuilder acb, MethodBuilder mb) 215 { 216 mb.push(booleanValue); 217 } 218 219 222 public void setValue(DataValueDescriptor value) 223 { 224 super.setValue( value); 225 unknownValue = true; 226 try 227 { 228 if( value != null && value.isNotNull().getBoolean()) 229 { 230 booleanValue = value.getBoolean(); 231 unknownValue = false; 232 } 233 } 234 catch( StandardException se){} 235 } } 237 | Popular Tags |