Top Description Fields Constructors Methods
org.apache.derby.impl.sql.compile

pack-priv Class UserTypeConstantNode

extends ConstantNode
Class Inheritance
Imports
java.lang.reflect.Modifier, java.sql.Date, .Time, .Timestamp, .Types, org.apache.derby.catalog.TypeDescriptor, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.services.classfile.VMOpcode, org.apache.derby.iapi.services.compiler.LocalField, .MethodBuilder, org.apache.derby.iapi.services.context.ContextManager, org.apache.derby.iapi.services.io.StoredFormatIds, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.sql.compile.TypeCompiler, org.apache.derby.iapi.types.DataValueDescriptor, .SQLDate, .SQLTime, .SQLTimestamp, .TypeId

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 user type column.

Field Summary

Modifier and TypeField and Description
pack-priv Object
Inherited from org.apache.derby.impl.sql.compile.ConstantNode:
value

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv
pack-priv
pack-priv
pack-priv
UserTypeConstantNode(DataValueDescriptor
Must contain a Date, Time or Timestamp value
dvd
,
ContextManager
context manager
cm
)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
generateConstant(ExpressionClassBuilder
The ExpressionClassBuilder for the class being built
acb
,
MethodBuilder
The method the expression will go into
mb
)

Implements abstract org.apache.derby.impl.sql.compile.ConstantNode.generateConstant.

Should never be called for UserTypeConstantNode because we have our own generateExpression().

pack-priv void
generateExpression(ExpressionClassBuilder
The ExpressionClassBuilder for the class being built
acb
,
MethodBuilder
The method the expression will go into
mb
)

Overrides org.apache.derby.impl.sql.compile.ConstantNode.generateExpression.

For a UserTypeConstantNode, we have to store away the object somewhere and have a way to get it back at runtime.

pack-priv Object

Returns:

An Object representing the bind time value of this expression tree. (null if not a bind time constant.)
getConstantValueAsObject
()

Overrides org.apache.derby.impl.sql.compile.ValueNode.getConstantValueAsObject.

Return an Object representing the bind time value of this expression tree.

public Object

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)
getObjectValue
()

Return the object value of this user defined type.

private static TypeId
private static int
pack-priv boolean
isNull()

Overrides org.apache.derby.impl.sql.compile.ConstantNode.isNull.

Return whether or not this node represents a typed null constant.

Inherited from org.apache.derby.impl.sql.compile.ConstantNode:
bindExpressionconstantExpressiongetClonegetOrderableVariantTypegetValueisCloneableisConstantExpressionisEquivalentsetValuetoString

Field Detail

valback to summary
pack-priv Object val

Constructor Detail

UserTypeConstantNodeback to summary
pack-priv UserTypeConstantNode(TypeId t, ContextManager cm) throws StandardException
UserTypeConstantNodeback to summary
pack-priv UserTypeConstantNode(Date d, ContextManager cm) throws StandardException
UserTypeConstantNodeback to summary
pack-priv UserTypeConstantNode(Time t, ContextManager cm) throws StandardException
UserTypeConstantNodeback to summary
pack-priv UserTypeConstantNode(Timestamp t, ContextManager cm) throws StandardException
UserTypeConstantNodeback to summary
pack-priv UserTypeConstantNode(DataValueDescriptor dvd, ContextManager cm) throws StandardException
Parameters
dvd:DataValueDescriptor

Must contain a Date, Time or Timestamp value

cm:ContextManager

context manager

Method Detail

generateConstantback to summary
pack-priv void generateConstant(ExpressionClassBuilder acb, MethodBuilder mb) throws StandardException

Implements abstract org.apache.derby.impl.sql.compile.ConstantNode.generateConstant.

Should never be called for UserTypeConstantNode because we have our own generateExpression().

Parameters
acb:ExpressionClassBuilder

The ExpressionClassBuilder for the class being built

mb:MethodBuilder

The method the expression will go into

Exceptions
StandardException:
Thrown on error
generateExpressionback to summary
pack-priv void generateExpression(ExpressionClassBuilder acb, MethodBuilder mb) throws StandardException

Overrides org.apache.derby.impl.sql.compile.ConstantNode.generateExpression.

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.

Parameters
acb:ExpressionClassBuilder

The ExpressionClassBuilder for the class being built

mb:MethodBuilder

The method the expression will go into

Annotations
@Override
Exceptions
StandardException:
Thrown on error
getConstantValueAsObjectback to summary
pack-priv Object getConstantValueAsObject()

Overrides org.apache.derby.impl.sql.compile.ValueNode.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?

Returns:Object

An Object representing the bind time value of this expression tree. (null if not a bind time constant.)

Annotations
@Override
getObjectValueback to summary
public Object getObjectValue()

Return the object value of this user defined type.

Returns:Object

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)

getTypeIdback to summary
private static TypeId getTypeId(DataValueDescriptor dvd)
getWidthback to summary
private static int getWidth(DataValueDescriptor dvd)
isNullback to summary
pack-priv boolean isNull()

Overrides org.apache.derby.impl.sql.compile.ConstantNode.isNull.

Return whether or not this node represents a typed null constant.

Annotations
@Override