Class SQLToJavaValueNode
- java.lang.Object
-
- org.apache.derby.impl.sql.compile.QueryTreeNode
-
- org.apache.derby.impl.sql.compile.JavaValueNode
-
- org.apache.derby.impl.sql.compile.SQLToJavaValueNode
-
- All Implemented Interfaces:
Visitable
class SQLToJavaValueNode extends JavaValueNode
This node type converts a value in the SQL domain to a value in the Java domain.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) LocalField
returnsNullOnNullState
If set then this SQL value is being passed into a SQL function declared RETURNS NULL ON NULL input.(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_CREATE_MODIFY, AUTOINCREMENT_CYCLE, AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX
-
-
Constructor Summary
Constructors Constructor Description SQLToJavaValueNode(ValueNode value, ContextManager cm)
Constructor for a SQLToJavaValueNode
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
acceptChildren(Visitor v)
Accept the visitor for all visitable children of this node.(package private) JavaValueNode
bindExpression(FromList fromList, SubqueryList subqueryList, java.util.List<AggregateNode> aggregates)
Bind this expression.(package private) boolean
categorize(JBitSet referencedTabs, boolean simplePredsOnly)
Categorize this predicate.(package private) void
generateExpression(ExpressionClassBuilder acb, MethodBuilder mb)
Generate code to get the Java value out of a SQL value.private 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..private void
generateSQLValue(ExpressionClassBuilder acb, MethodBuilder mb)
Generate the SQLvalue that this node wraps.(package private) java.lang.Object
getConstantValueAsObject()
(package private) DataTypeDescriptor
getDataType()
Get the resolved data type of this node.(package private) java.lang.String
getJavaTypeName()
Returns the name of the java class type that this node coerces to.(package private) JSQLType
getJSQLType()
Get the JSQLType that corresponds to this node.(package private) int
getOrderableVariantType()
Return the variant type for the underlying expression.(package private) java.lang.String
getPrimitiveTypeName()
Returns the name of the java primitive type that this node coerces to.private 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(package private) void
preprocess(int numTables, FromList outerFromList, SubqueryList outerSubqueryList, PredicateList outerPredicateList)
Preprocess an expression tree.(package private) void
printSubNodes(int depth)
Prints the sub-nodes of this object.(package private) JavaValueNode
remapColumnReferencesToExpressions()
Remap all ColumnReferences in this tree to be clones of the underlying expression.-
Methods inherited from class org.apache.derby.impl.sql.compile.JavaValueNode
castToPrimitive, checkReliability, generate, generateReceiver, generateReceiver, getCollationType, getReceiverExpression, isPrimitiveType, mapToTypeID, markForCallStatement, markReturnValueDiscarded, mustCastToPrimitive, returnValueDiscarded, returnValueToSQLDomain, setCollationType, setJavaTypeName, valueReturnedToSQLDomain
-
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
accept, addTag, addUDTUsagePriv, addUDTUsagePriv, bindOffsetFetch, bindRowMultiSet, bindUserCatalogType, bindUserType, checkReliability, checkReliability, convertDefaultNode, copyTagsFrom, createTypeDependency, debugFlush, debugPrint, disablePrivilegeCollection, formatNodeString, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContext, getContextManager, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getLongProperty, getNullNode, getOffsetOrderedNodes, getOptimizerFactory, getOptimizerTracer, getParameterTypes, getSchemaDescriptor, getSchemaDescriptor, getStatementType, getTableDescriptor, getTypeCompiler, getUDTDesc, isAtomic, isPrivilegeCollectionRequired, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, makeTableName, nodeHeader, optimizerTracingIsOn, orReliability, parseSearchCondition, parseStatement, printLabel, referencesSessionSchema, resolveTableToSynonym, setBeginOffset, setEndOffset, setRefActionInfo, stackPrint, taggedWith, toString, treePrint, treePrint, verifyClassExist
-
-
-
-
Field Detail
-
value
ValueNode value
-
returnsNullOnNullState
LocalField returnsNullOnNullState
If set then this SQL value is being passed into a SQL function declared RETURNS NULL ON NULL input. In this case this node performs NULL checking logic in addition simple translation from the SQL domain to the Java domain. Thus if this is set then this node can not be removed when it is paired with a JavaToSQLValueNode. This field is set at generate time of the enclosing StaticMethodCallNode.
-
-
Constructor Detail
-
SQLToJavaValueNode
SQLToJavaValueNode(ValueNode value, ContextManager cm)
Constructor for a SQLToJavaValueNode- Parameters:
value
- A ValueNode representing a SQL value to convert to the Java domain.cm
- The context manager
-
-
Method Detail
-
printSubNodes
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 classQueryTreeNode
- Parameters:
depth
- The depth of this node in the tree
-
getJavaTypeName
java.lang.String getJavaTypeName() throws StandardException
Returns the name of the java class type that this node coerces to.- Overrides:
getJavaTypeName
in classJavaValueNode
- Returns:
- name of java class type
- Throws:
StandardException
-
getPrimitiveTypeName
java.lang.String getPrimitiveTypeName() throws StandardException
Returns the name of the java primitive type that this node coerces to.- Overrides:
getPrimitiveTypeName
in classJavaValueNode
- Returns:
- name of java primitive type
- Throws:
StandardException
- Thrown on error
-
getJSQLType
JSQLType getJSQLType() throws StandardException
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 classJavaValueNode
- Returns:
- the corresponding JSQLType
- Throws:
StandardException
-
bindExpression
JavaValueNode bindExpression(FromList fromList, SubqueryList subqueryList, java.util.List<AggregateNode> aggregates) 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 classJavaValueNode
- Parameters:
fromList
- The FROM list for the query this expression is in, for binding columns.subqueryList
- The subquery list being built as we find SubqueryNodesaggregates
- The aggregate list 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.List<org.apache.derby.impl.sql.compile.AggregateNode>)
-
getDataType
DataTypeDescriptor getDataType() throws StandardException
Description copied from class:JavaValueNode
Get the resolved data type of this node. May be overridden by descendants.- Overrides:
getDataType
in classJavaValueNode
- Throws:
StandardException
-
remapColumnReferencesToExpressions
JavaValueNode remapColumnReferencesToExpressions() throws StandardException
Remap all ColumnReferences in this tree to be clones of the underlying expression.- Specified by:
remapColumnReferencesToExpressions
in classJavaValueNode
- Returns:
- JavaValueNode The remapped expression tree.
- Throws:
StandardException
- Thrown on error- See Also:
ValueNode.remapColumnReferencesToExpressions()
-
categorize
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 classJavaValueNode
- Parameters:
referencedTabs
- JBitSet with bit map of referenced FromTablessimplePredsOnly
- 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
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 classJavaValueNode
- Parameters:
numTables
- Number of tables in the DML StatementouterFromList
- FromList from outer query blockouterSubqueryList
- SubqueryList from outer query blockouterPredicateList
- PredicateList from outer query block- 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
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 classJavaValueNode
- Returns:
- The variant type for the underlying expression.
- Throws:
StandardException
- thrown on error
-
generateExpression
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 classJavaValueNode
- Parameters:
acb
- The ExpressionClassBuilder for the class being builtmb
- The method the expression will go into- Throws:
StandardException
- Thrown on error
-
generateSQLValue
private void generateSQLValue(ExpressionClassBuilder acb, MethodBuilder mb) throws StandardException
Generate the SQLvalue that this node wraps.- Parameters:
acb
- The ExpressionClassBuilder for the class being builtmb
- The method the expression will go into- Throws:
StandardException
- Thrown on error
-
generateJavaValue
private 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 builtmbex
- The method the expression will go into- 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
private 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 classJavaValueNode
- Throws:
StandardException
- Thrown on error- See Also:
ValueNode.getConstantValueAsObject()
-
acceptChildren
void acceptChildren(Visitor v) throws StandardException
Accept the visitor for all visitable children of this node.- Overrides:
acceptChildren
in classQueryTreeNode
- Parameters:
v
- the visitor- Throws:
StandardException
- on error
-
-