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

java.lang.Object
  extended byorg.apache.derby.impl.sql.compile.QueryTreeNode
      extended byorg.apache.derby.impl.sql.compile.ValueNode
          extended byorg.apache.derby.impl.sql.compile.ConstantNode
              extended byorg.apache.derby.impl.sql.compile.UserTypeConstantNode
All Implemented Interfaces:
Visitable

public class UserTypeConstantNode
extends ConstantNode

User type constants. These are created by built-in types that use user types as their implementation. This could also potentially be used by an optimizer that wanted to store plans for frequently-used parameter values. This is also used to represent nulls in user types, which occurs when NULL is inserted into or supplied as the update value for a usertype column.

Author:
ames

Field Summary
(package private)  java.lang.Object value
           
 
Fields inherited from class org.apache.derby.impl.sql.compile.ValueNode
clause, dataTypeServices, IN_HAVING_CLAUSE, IN_SELECT_LIST, IN_UNKNOWN_CLAUSE, IN_WHERE_CLAUSE, transformed
 
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
UserTypeConstantNode()
           
 
Method Summary
 ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, java.util.Vector aggregateVector)
          Bind this expression.
 boolean constantExpression(PredicateList whereClause)
          Return whether or not this expression tree represents a constant value.
(package private)  void generateConstant(ExpressionClassBuilder acb, MethodBuilder mb)
          Should never be called for UserTypeConstantNode because we have our own generateExpression().
 void generateExpression(ExpressionClassBuilder acb, MethodBuilder mb)
          For a UserTypeConstantNode, we have to store away the object somewhere and have a way to get it back at runtime.
 ValueNode getClone()
          Return a clone of this node.
 java.lang.Object getConstantValueAsObject()
          Return an Object representing the bind time value of this expression tree.
 java.lang.Object getObjectValue()
          Return the object value of this user defined type.
protected  int getOrderableVariantType()
          Return the variant type for the underlying expression.
 DataValueDescriptor getStorableValue()
          Return the value of this user defined type as a Storable
 DataValueDescriptor getValue()
          Get the value in this ConstantNode
 void init(java.lang.Object arg1)
          Initializer for a typed null node or a date, time, or timestamp value
 void init(java.lang.Object typeId, java.lang.Object nullable, java.lang.Object maximumWidth)
          Initializer for non-numeric types
 boolean isCloneable()
          Return whether or not this expression tree is cloneable.
 boolean isConstantExpression()
          Return whether or not this expression tree represents a constant expression.
 boolean isNull()
          Return whether or not this node represents a typed null constant.
 void setObjectValue(java.lang.Object newValue)
          Sets the object value of this user defined type
(package private)  void setValue(DataValueDescriptor value)
          Set the value in this ConstantNode.
 java.lang.String toString()
          Convert this object to a String.
 
Methods inherited from class org.apache.derby.impl.sql.compile.ValueNode
bindExpression, categorize, changeToCNF, checkIsBoolean, checkReliability, checkReliability, checkTopPredicatesForEqualsConditions, copyFields, eliminateNots, genEqualsFalseTree, generate, generateFilter, genIsNullTree, genSQLJavaSQLTree, getClause, getColumnName, getDataValueFactory, getSchemaName, getSourceResultColumn, getTableName, getTablesReferenced, getTransformed, getTypeCompiler, getTypeId, getTypeServices, init, isBinaryEqualsOperatorNode, isBooleanFalse, isBooleanTrue, isParameterNode, isRelationalOperator, optimizableEqualityNode, preprocess, putAndsOnTop, remapColumnReferencesToExpressions, selectivity, setClause, setDescriptor, setTransformed, setType, updatableByCursor, verifyChangeToCNF, verifyEliminateNots, verifyPutAndsOnTop
 
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
accept, 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, isAtomic, isInstanceOf, isSessionSchema, isSessionSchema, makeConstantAction, makeResultDescription, makeTableName, needsSavepoint, nodeHeader, optimize, parseQueryText, printLabel, printSubNodes, referencesSessionSchema, resolveTableToSynonym, setBeginOffset, setContextManager, setEndOffset, setNodeType, setRefActionInfo, treePrint, treePrint, verifyClassExist
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

value

java.lang.Object value
Constructor Detail

UserTypeConstantNode

public UserTypeConstantNode()
Method Detail

init

public void init(java.lang.Object arg1)
          throws StandardException
Initializer for a typed null node or a date, time, or timestamp value

Overrides:
init in class QueryTreeNode
Parameters:
arg1 - The TypeId for the type of the node
Throws:
StandardException - thrown on failure

getObjectValue

public java.lang.Object getObjectValue()
Return the object value of this user defined type.

Returns:
the value of this constant. can't use getValue() for this. getValue() returns the DataValueDescriptor for the built-in types that are implemented as user types (date, time, timestamp)

isNull

public boolean isNull()
Return whether or not this node represents a typed null constant.

Overrides:
isNull in class ConstantNode

getStorableValue

public DataValueDescriptor getStorableValue()
                                     throws StandardException
Return the value of this user defined type as a Storable

Returns:
the value of this constant as a UserType
Throws:
StandardException - thrown on failure

setObjectValue

public void setObjectValue(java.lang.Object newValue)
Sets the object value of this user defined type


getConstantValueAsObject

public java.lang.Object getConstantValueAsObject()
Return an Object representing the bind time value of this expression tree. If the expression tree does not evaluate to a constant at bind time then we return null. This is useful for bind time resolution of VTIs. RESOLVE: What do we do for primitives?

Overrides:
getConstantValueAsObject in class ValueNode
Returns:
An Object representing the bind time value of this expression tree. (null if not a bind time constant.)

generateExpression

public void generateExpression(ExpressionClassBuilder acb,
                               MethodBuilder mb)
                        throws StandardException
For a UserTypeConstantNode, we have to store away the object somewhere and have a way to get it back at runtime. These objects are serializable. This gives us at least two options: 1) serialize it out into a byte array field, and serialize it back in when needed, from the field. 2) have an array of objects in the prepared statement and a #, to find the object directly. Because it is serializable, it will store with the rest of the executable just fine. Choice 2 gives better performance -- the ser/deser cost is paid on database access for the statement, not for each execution of it. However, it requires some infrastructure support from prepared statements. For now, we take choice 3, and make some assumptions about available methods on the user type. This choice has the shortcoming that it will not work for arbitrary user types. REVISIT and implement choice 2 when a general solution is needed.

A null is generated as a Null value cast to the type of the constant node.

Overrides:
generateExpression in class ConstantNode
Parameters:
acb - The ExpressionClassBuilder for the class being built
mb - The method the expression will go into
Returns:
The compiled Expression, if the constant is a null value, null if the constant is not a null value (confusing, huh?)
Throws:
StandardException - Thrown on error

generateConstant

void generateConstant(ExpressionClassBuilder acb,
                      MethodBuilder mb)
                throws StandardException
Should never be called for UserTypeConstantNode because we have our own generateExpression().

Specified by:
generateConstant in class ConstantNode
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

init

public void init(java.lang.Object typeId,
                 java.lang.Object nullable,
                 java.lang.Object maximumWidth)
          throws StandardException
Initializer for non-numeric types

Overrides:
init in class QueryTreeNode
Parameters:
typeId - The Type ID of the datatype
nullable - True means the constant is nullable
maximumWidth - The maximum number of bytes in the data value
Throws:
StandardException

setValue

void setValue(DataValueDescriptor value)
Set the value in this ConstantNode.


getValue

public DataValueDescriptor getValue()
Get the value in this ConstantNode


toString

public java.lang.String toString()
Convert this object to a String. See comments in QueryTreeNode.java for how this should be done for tree printing.

Overrides:
toString in class ValueNode
Returns:
This object as a String

isCloneable

public boolean isCloneable()
Return whether or not this expression tree is cloneable.

Overrides:
isCloneable in class ValueNode
Returns:
boolean Whether or not this expression tree is cloneable.

getClone

public ValueNode getClone()
Return a clone of this node.

Overrides:
getClone in class ValueNode
Returns:
ValueNode A clone of this node.

bindExpression

public ValueNode bindExpression(FromList fromList,
                                SubqueryList subqueryList,
                                java.util.Vector aggregateVector)
Bind this expression. This means binding the sub-expressions, as well as figuring out what the return type is for this expression. In this case, there are no sub-expressions, and the return type is already known, so this is just a stub.

Overrides:
bindExpression in class ValueNode
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:
The new top of the expression tree.

isConstantExpression

public boolean isConstantExpression()
Return whether or not this expression tree represents a constant expression.

Overrides:
isConstantExpression in class ValueNode
Returns:
Whether or not this expression tree represents a constant expression.

constantExpression

public boolean constantExpression(PredicateList whereClause)
Description copied from class: ValueNode
Return whether or not this expression tree represents a constant value. In this case, "constant" means that it will always evaluate to the same thing, even if it includes columns. A column is constant if it is compared to a constant expression.

Overrides:
constantExpression in class ValueNode
Returns:
True means this expression tree represents a constant value.
See Also:
ValueNode.constantExpression(org.apache.derby.impl.sql.compile.PredicateList)

getOrderableVariantType

protected int getOrderableVariantType()
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 VARIANT - immutable

Overrides:
getOrderableVariantType in class ValueNode
Returns:
The variant type for the underlying expression.

Built on Tue 2006-10-10 19:23:47+0200, from revision exported

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