1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 25 import org.apache.derby.iapi.types.DataTypeDescriptor; 26 import org.apache.derby.iapi.types.TypeId; 27 import org.apache.derby.iapi.sql.compile.TypeCompiler; 28 import org.apache.derby.iapi.reference.SQLState; 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.iapi.error.StandardException; 34 35 import org.apache.derby.impl.sql.compile.ExpressionClassBuilder; 36 37 import org.apache.derby.iapi.sql.compile.Visitable; 38 import org.apache.derby.iapi.sql.compile.Visitor; 39 40 import org.apache.derby.iapi.services.sanity.SanityManager; 41 42 import java.lang.reflect.Modifier ; 43 44 import org.apache.derby.iapi.util.JBitSet; 45 46 import java.util.Vector ; 47 48 51 52 public class JavaToSQLValueNode extends ValueNode 53 { 54 JavaValueNode javaNode; 55 56 61 public void init(Object value) 62 { 63 this.javaNode = (JavaValueNode) value; 64 } 65 66 71 public void setClause(int clause) 72 { 73 super.setClause(clause); 74 javaNode.setClause(clause); 75 } 76 77 92 public ValueNode preprocess(int numTables, 93 FromList outerFromList, 94 SubqueryList outerSubqueryList, 95 PredicateList outerPredicateList) 96 throws StandardException 97 { 98 javaNode.preprocess(numTables, 99 outerFromList, outerSubqueryList, 100 outerPredicateList); 101 102 return this; 103 } 104 105 114 115 public void generateExpression(ExpressionClassBuilder acb, 116 MethodBuilder mb) 117 throws StandardException 118 { 119 TypeId resultType; 120 String resultTypeName; 121 122 127 javaNode.returnValueToSQLDomain(); 128 129 130 boolean hasReceiver = javaNode.generateReceiver(acb, mb); 131 132 137 if (hasReceiver) 138 { 139 144 String nullValueClass = getTypeCompiler().interfaceName(); 145 LocalField nullValueField = 146 acb.newFieldDeclaration(Modifier.PRIVATE, nullValueClass); 147 153 154 mb.conditionalIfNull(); 155 mb.getField(nullValueField); 156 acb.generateNullWithExpress(mb, getTypeCompiler()); 157 158 159 164 mb.startElseCode(); 165 } 166 167 resultType = getTypeId(); 168 TypeCompiler tc = getTypeCompiler(); 169 170 resultTypeName = tc.interfaceName(); 171 172 173 LocalField field = acb.newFieldDeclaration(Modifier.PRIVATE, resultTypeName); 174 175 176 javaNode.generateExpression(acb, mb); 177 178 179 acb.generateDataValue(mb, tc, field); 180 181 185 if (hasReceiver) 186 { 187 mb.completeConditional(); 188 } 189 } 190 191 197 198 public void printSubNodes(int depth) 199 { 200 if (SanityManager.DEBUG) 201 { 202 super.printSubNodes(depth); 203 204 printLabel(depth, "javaNode: "); 205 javaNode.treePrint(depth + 1); 206 } 207 } 208 209 214 215 public JavaValueNode getJavaValueNode() 216 { 217 return javaNode; 218 } 219 220 223 public void disablePrivilegeCollection() 224 { 225 super.disablePrivilegeCollection(); 226 if (javaNode != null) 227 javaNode.disablePrivilegeCollection(); 228 } 229 230 244 245 public ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, 246 Vector aggregateVector) 247 throws StandardException 248 { 249 javaNode.checkReliability(this); 252 253 254 javaNode = javaNode.bindExpression(fromList, subqueryList, aggregateVector); 255 256 DataTypeDescriptor dts = DataTypeDescriptor.getSQLDataTypeDescriptor(javaNode.getJavaTypeName()); 257 if (dts == null) 258 { 259 throw StandardException.newException(SQLState.LANG_NO_CORRESPONDING_S_Q_L_TYPE, 260 javaNode.getJavaTypeName()); 261 } 262 263 setType(dts); 264 265 return this; 266 } 267 268 276 public ValueNode remapColumnReferencesToExpressions() 277 throws StandardException 278 { 279 javaNode = javaNode.remapColumnReferencesToExpressions(); 280 return this; 281 } 282 283 308 public boolean categorize(JBitSet referencedTabs, boolean simplePredsOnly) 309 throws StandardException 310 { 311 return javaNode.categorize(referencedTabs, simplePredsOnly); 312 } 313 314 327 protected int getOrderableVariantType() throws StandardException 328 { 329 return javaNode.getOrderableVariantType(); 330 } 331 332 340 public Visitable accept(Visitor v) 341 throws StandardException 342 { 343 Visitable returnNode = v.visit(this); 344 345 if (v.skipChildren(this)) 346 { 347 return returnNode; 348 } 349 350 if (javaNode != null && !v.stopTraversal()) 351 { 352 javaNode = (JavaValueNode)javaNode.accept(v); 353 } 354 355 return returnNode; 356 } 357 358 361 protected boolean isEquivalent(ValueNode o) 362 { 363 return false; 365 } 366 } 367 | Popular Tags |