org.apache.derby.impl.sql.compile
Class SQLToJavaValueNode

java.lang.Object
  extended byorg.apache.derby.impl.sql.compile.QueryTreeNode
      extended byorg.apache.derby.impl.sql.compile.JavaValueNode
          extended byorg.apache.derby.impl.sql.compile.SQLToJavaValueNode
All Implemented Interfaces:
Visitable

public class SQLToJavaValueNode
extends JavaValueNode

This node type converts a value in the SQL domain to a value in the Java domain.


Field Summary
(package private)  LocalField returnsNullOnNullState
           
(package private)  ValueNode value
           
 
Fields inherited from class org.apache.derby.impl.sql.compile.JavaValueNode
forCallStatement, jsqlType
 
Fields inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX, beginOffset, endOffset
 
Constructor Summary
SQLToJavaValueNode()
           
 
Method Summary
 Visitable accept(Visitor v)
          Accept a visitor, and call v.visit() on child nodes as necessary.
 JavaValueNode bindExpression(FromList fromList, SubqueryList subqueryList, java.util.Vector aggregateVector)
          Bind this expression.
 boolean categorize(JBitSet referencedTabs, boolean simplePredsOnly)
          Categorize this predicate.
 void generateExpression(ExpressionClassBuilder acb, MethodBuilder mb)
          Generate code to get the Java value out of a SQL value.
 void generateJavaValue(ExpressionClassBuilder acb, MethodBuilder mbex)
          Generate code to cast the SQLValue to a Java value.
private  void generateReturnsNullOnNullCheck(MethodBuilder mb)
          Generate the code for the returns Null on Null input check..
 void generateSQLValue(ExpressionClassBuilder acb, MethodBuilder mb)
          Generate the SQLvalue that this node wraps.
(package private)  java.lang.Object getConstantValueAsObject()
           
 java.lang.String getJavaTypeName()
          Returns the name of the java class type that this node coerces to.
 JSQLType getJSQLType()
          Get the JSQLType that corresponds to this node.
protected  int getOrderableVariantType()
          Return the variant type for the underlying expression.
 java.lang.String getPrimitiveTypeName()
          Returns the name of the java primitive type that this node coerces to.
 java.lang.String getSQLValueInterfaceName()
          Get the type name of the SQLValue we generate.
(package private)  ValueNode getSQLValueNode()
          Get the SQL ValueNode that is being converted to a JavaValueNode
 void init(java.lang.Object value)
          Constructor for a SQLToJavaValueNode
 void preprocess(int numTables, FromList outerFromList, SubqueryList outerSubqueryList, PredicateList outerPredicateList)
          Preprocess an expression tree.
 void printSubNodes(int depth)
          Prints the sub-nodes of this object.
 JavaValueNode remapColumnReferencesToExpressions()
          Remap all ColumnReferences in this tree to be clones of the underlying expression.
 void setClause(int clause)
          Set the clause that this node appears in.
 
Methods inherited from class org.apache.derby.impl.sql.compile.JavaValueNode
castToPrimitive, checkReliability, generate, generateReceiver, generateReceiver, getReceiverExpression, isPrimitiveType, mapToTypeID, markForCallStatement, markReturnValueDiscarded, mustCastToPrimitive, returnValueDiscarded, returnValueToSQLDomain, setJavaTypeName, valueReturnedToSQLDomain
 
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
bind, convertDefaultNode, debugFlush, debugPrint, executeSchemaName, executeStatementName, formatNodeString, foundString, generate, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContextManager, getCursorInfo, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getNodeFactory, getNodeType, getNullNode, getParameterTypes, getRowEstimate, getSchemaDescriptor, getSchemaDescriptor, getSPSName, getStatementType, getTableDescriptor, getTypeCompiler, init, init, init, init, init, init, init, init, init, init, init, init, init, isAtomic, isInstanceOf, isSessionSchema, isSessionSchema, makeConstantAction, makeResultDescription, makeTableName, needsSavepoint, nodeHeader, optimize, parseQueryText, printLabel, referencesSessionSchema, resolveTableToSynonym, setBeginOffset, setContextManager, setEndOffset, setNodeType, setRefActionInfo, toString, treePrint, treePrint, verifyClassExist
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

value

ValueNode value

returnsNullOnNullState

LocalField returnsNullOnNullState
Constructor Detail

SQLToJavaValueNode

public SQLToJavaValueNode()
Method Detail

init

public void init(java.lang.Object value)
Constructor for a SQLToJavaValueNode

Overrides:
init in class QueryTreeNode
Parameters:
value - A ValueNode representing a SQL value to convert to the Java domain.

printSubNodes

public void printSubNodes(int depth)
Prints the sub-nodes of this object. See QueryTreeNode.java for how tree printing is supposed to work.

Overrides:
printSubNodes in class QueryTreeNode
Parameters:
depth - The depth of this node in the tree
Returns:
Nothing

getJavaTypeName

public java.lang.String getJavaTypeName()
Returns the name of the java class type that this node coerces to.

Overrides:
getJavaTypeName in class JavaValueNode
Returns:
name of java class type

getPrimitiveTypeName

public java.lang.String getPrimitiveTypeName()
                                      throws StandardException
Returns the name of the java primitive type that this node coerces to.

Overrides:
getPrimitiveTypeName in class JavaValueNode
Returns:
name of java primitive type
Throws:
StandardException - Thrown on error

getJSQLType

public JSQLType getJSQLType()
Get the JSQLType that corresponds to this node. Could be a SQLTYPE, a Java primitive, or a Java class. Overrides method in JavaValueNode.

Overrides:
getJSQLType in class JavaValueNode
Returns:
the corresponding JSQLType

setClause

public void setClause(int clause)
Set the clause that this node appears in.

Overrides:
setClause in class JavaValueNode
Parameters:
clause - The clause that this node appears in.
Returns:
Nothing.

bindExpression

public JavaValueNode bindExpression(FromList fromList,
                                    SubqueryList subqueryList,
                                    java.util.Vector aggregateVector)
                             throws StandardException
Bind this expression. This means binding the sub-expressions, as well as figuring out what the return type is for this expression.

Specified by:
bindExpression in class JavaValueNode
Parameters:
fromList - The FROM list for the query this expression is in, for binding columns.
subqueryList - The subquery list being built as we find SubqueryNodes
aggregateVector - The aggregate vector being built as we find AggregateNodes
Returns:
this
Throws:
StandardException - Thrown on error
See Also:
ValueNode.bindExpression(org.apache.derby.impl.sql.compile.FromList, org.apache.derby.impl.sql.compile.SubqueryList, java.util.Vector)

remapColumnReferencesToExpressions

public JavaValueNode remapColumnReferencesToExpressions()
                                                 throws StandardException
Remap all ColumnReferences in this tree to be clones of the underlying expression.

Specified by:
remapColumnReferencesToExpressions in class JavaValueNode
Returns:
JavaValueNode The remapped expression tree.
Throws:
StandardException - Thrown on error
See Also:
ValueNode.remapColumnReferencesToExpressions()

categorize

public boolean categorize(JBitSet referencedTabs,
                          boolean simplePredsOnly)
                   throws StandardException
Categorize this predicate. Initially, this means building a bit map of the referenced tables for each predicate. If the source of this ColumnReference (at the next underlying level) is not a ColumnReference or a VirtualColumnNode then this predicate will not be pushed down. For example, in: select * from (select 1 from s) a (x) where x = 1 we will not push down x = 1. NOTE: It would be easy to handle the case of a constant, but if the inner SELECT returns an arbitrary expression, then we would have to copy that tree into the pushed predicate, and that tree could contain subqueries and method calls. RESOLVE - revisit this issue once we have views.

Specified by:
categorize in class JavaValueNode
Parameters:
referencedTabs - JBitSet with bit map of referenced FromTables
simplePredsOnly - Whether or not to consider method calls, field references and conditional nodes when building bit map
Returns:
boolean Whether or not source.expression is a ColumnReference or a VirtualColumnNode.
Throws:
StandardException - Thrown on error
See Also:
ValueNode.categorize(org.apache.derby.iapi.util.JBitSet, boolean)

preprocess

public void preprocess(int numTables,
                       FromList outerFromList,
                       SubqueryList outerSubqueryList,
                       PredicateList outerPredicateList)
                throws StandardException
Preprocess an expression tree. We do a number of transformations here (including subqueries, IN lists, LIKE and BETWEEN) plus subquery flattening. NOTE: This is done before the outer ResultSetNode is preprocessed.

Specified by:
preprocess in class JavaValueNode
Parameters:
numTables - Number of tables in the DML Statement
outerFromList - FromList from outer query block
outerSubqueryList - SubqueryList from outer query block
outerPredicateList - PredicateList from outer query block
Returns:
Nothing.
Throws:
StandardException - Thrown on error
See Also:
ValueNode.preprocess(int, org.apache.derby.impl.sql.compile.FromList, org.apache.derby.impl.sql.compile.SubqueryList, org.apache.derby.impl.sql.compile.PredicateList)

getOrderableVariantType

protected int getOrderableVariantType()
                               throws StandardException
Return the variant type for the underlying expression. The variant type can be: VARIANT - variant within a scan (method calls and non-static field access) SCAN_INVARIANT - invariant within a scan (column references from outer tables) QUERY_INVARIANT - invariant within the life of a query (constant expressions)

Overrides:
getOrderableVariantType in class JavaValueNode
Returns:
The variant type for the underlying expression.
Throws:
StandardException - thrown on error

generateExpression

public void generateExpression(ExpressionClassBuilder acb,
                               MethodBuilder mb)
                        throws StandardException
Generate code to get the Java value out of a SQL value. Every SQL type has a corresponding Java type. The getObject() method on the SQL type gets the right Java type. The generated code will be: () ((DataValueDescriptor) .getObject()) where comes from the getCorrespondingJavaTypeName() method of the value's TypeId.

Specified by:
generateExpression in class JavaValueNode
Parameters:
acb - The ExpressionClassBuilder for the class being built
mb - The method the expression will go into
Returns:
The compiled Expression
Throws:
StandardException - Thrown on error

generateSQLValue

public void generateSQLValue(ExpressionClassBuilder acb,
                             MethodBuilder mb)
                      throws StandardException
Generate the SQLvalue that this node wraps.

Parameters:
acb - The ExpressionClassBuilder for the class being built
mb - The method the expression will go into
Throws:
StandardException - Thrown on error

generateJavaValue

public void generateJavaValue(ExpressionClassBuilder acb,
                              MethodBuilder mbex)
                       throws StandardException
Generate code to cast the SQLValue to a Java value.

Parameters:
acb - The ExpressionClassBuilder for the class being built
Throws:
StandardException - Thrown on error

generateReturnsNullOnNullCheck

private void generateReturnsNullOnNullCheck(MethodBuilder mb)
Generate the code for the returns Null on Null input check.. Stack must contain the DataDescriptorValue.


getSQLValueInterfaceName

public java.lang.String getSQLValueInterfaceName()
                                          throws StandardException
Get the type name of the SQLValue we generate.

Returns:
name of interface corresponding to SQLValue
Throws:
StandardException - Thrown on error

getSQLValueNode

ValueNode getSQLValueNode()
Get the SQL ValueNode that is being converted to a JavaValueNode

Returns:
The underlying SQL ValueNode

getConstantValueAsObject

java.lang.Object getConstantValueAsObject()
                                    throws StandardException
Overrides:
getConstantValueAsObject in class JavaValueNode
Throws:
StandardException - Thrown on error
See Also:
ValueNode.getConstantValueAsObject()

accept

public Visitable accept(Visitor v)
                 throws StandardException
Accept a visitor, and call v.visit() on child nodes as necessary.

Specified by:
accept in interface Visitable
Overrides:
accept in class QueryTreeNode
Parameters:
v - the visitor
Throws:
StandardException - on error

Built on Mon 2007-06-04 09:58:47+0400, from revision ???

Apache Derby V10.1 Engine Documentation - Copyright © 1997,2005 The Apache Software Foundation or its licensors, as applicable.