1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.types.DataValueDescriptor; 25 import org.apache.derby.iapi.types.TypeId; 26 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 27 28 import org.apache.derby.iapi.error.StandardException; 29 30 import org.apache.derby.iapi.services.compiler.MethodBuilder; 31 import org.apache.derby.iapi.services.compiler.LocalField; 32 33 import org.apache.derby.impl.sql.compile.ExpressionClassBuilder; 34 35 import java.lang.reflect.Modifier ; 36 37 import org.apache.derby.iapi.services.sanity.SanityManager; 38 39 import org.apache.derby.iapi.store.access.Qualifier; 40 41 import org.apache.derby.iapi.util.ReuseFactory; 42 43 import java.sql.Date ; 44 import java.sql.Time ; 45 import java.sql.Timestamp ; 46 47 import java.util.Vector ; 48 49 66 abstract class ConstantNode extends ValueNode 67 { 68 protected DataValueDescriptor value; 69 70 77 78 87 public void init( 88 Object typeId, 89 Object nullable, 90 Object maximumWidth) 91 throws StandardException 92 { 93 94 init( 95 typeId, 96 ReuseFactory.getInteger(0), 97 ReuseFactory.getInteger(0), 98 nullable, 99 maximumWidth); 100 } 101 102 106 ConstantNode() 107 { 108 super(); 109 } 110 111 114 void setValue(DataValueDescriptor value) 115 { 116 this.value = value; 117 } 118 119 122 public DataValueDescriptor getValue() 123 { 124 return value; 125 } 126 127 133 134 public String toString() 135 { 136 if (SanityManager.DEBUG) 137 { 138 return "value: " + value + "\n" + 139 super.toString(); 140 } 141 else 142 { 143 return ""; 144 } 145 } 146 147 152 public boolean isCloneable() 153 { 154 return true; 155 } 156 157 163 public ValueNode getClone() 164 { 165 166 return this; 167 } 168 169 182 public ValueNode bindExpression( 183 FromList fromList, SubqueryList subqueryList, 184 Vector aggregateVector) 185 { 186 191 return this; 192 } 193 194 199 public boolean isConstantExpression() 200 { 201 return true; 202 } 203 204 205 public boolean constantExpression(PredicateList whereClause) 206 { 207 return true; 208 } 209 210 222 public void generateExpression 223 ( 224 ExpressionClassBuilder acb, 225 MethodBuilder mb 226 ) throws StandardException 227 { 228 229 if (isNull()) 230 { 231 acb.generateNull(mb, getTypeCompiler()); 232 } 233 else 234 { 235 generateConstant(acb, mb); 238 acb.generateDataValue(mb, getTypeCompiler(), (LocalField) null); 239 } 240 } 241 242 251 abstract void generateConstant(ExpressionClassBuilder acb, MethodBuilder mb) 252 throws StandardException; 253 254 258 public boolean isNull() 259 { 260 return (value == null || value.isNull()); 261 } 262 263 275 protected int getOrderableVariantType() 276 { 277 return Qualifier.CONSTANT; 279 } 280 281 protected boolean isEquivalent(ValueNode o) throws StandardException 282 { 283 if (isSameNodeType(o)) { 284 ConstantNode other = (ConstantNode)o; 285 286 return ( (other.getValue() == null && getValue() == null) || 288 (other.getValue() != null && 289 other.getValue().compare(getValue()) == 0) ); 290 } 291 return false; 292 } 293 } 294 | Popular Tags |