Class BaseTypeCompiler
- java.lang.Object
-
- org.apache.derby.impl.sql.compile.BaseTypeCompiler
-
- All Implemented Interfaces:
TypeCompiler
- Direct Known Subclasses:
BitTypeCompiler
,BooleanTypeCompiler
,CharTypeCompiler
,CLOBTypeCompiler
,DateTypeCompiler
,LOBTypeCompiler
,NumericTypeCompiler
,RefTypeCompiler
,TimestampTypeCompiler
,TimeTypeCompiler
,UserDefinedTypeCompiler
,XMLTypeCompiler
abstract class BaseTypeCompiler extends java.lang.Object implements TypeCompiler
This is the base implementation of TypeCompiler
-
-
Field Summary
Fields Modifier and Type Field Description private TypeId
correspondingTypeId
-
Fields inherited from interface org.apache.derby.iapi.sql.compile.TypeCompiler
AVG_OP, BOOLEAN_MAXWIDTH_AS_CHAR, DEFAULT_DECIMAL_PRECISION, DEFAULT_DECIMAL_SCALE, DIVIDE_OP, DOUBLE_MAXWIDTH_AS_CHAR, INT_MAXWIDTH_AS_CHAR, LONGINT_MAXWIDTH_AS_CHAR, MAX_DECIMAL_PRECISION_SCALE, MINUS_OP, MOD_OP, PLUS_OP, REAL_MAXWIDTH_AS_CHAR, SMALLINT_MAXWIDTH_AS_CHAR, SUM_OP, TIMES_OP, TINYINT_MAXWIDTH_AS_CHAR
-
-
Constructor Summary
Constructors Constructor Description BaseTypeCompiler()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) java.lang.String
dataValueMethodName()
Return the method name to get a Derby DataValueDescriptor object of the correct type and set it to a specific value.void
generateDataValue(MethodBuilder mb, int collationType, LocalField field)
The caller will have pushed a DataValueFactory and value of that can be converted to the correct type, e.g. int for a SQL INTEGER.void
generateNull(MethodBuilder mb, int collationType)
The caller will have pushed a DataValueFactory and a null or a value of the correct type (interfaceName()).java.lang.String
getPrimitiveMethodName()
Get the method name for getting out the corresponding primitive Java type.protected int
getStoredFormatIdFromTypeId()
Get the StoredFormatId from the corresponding TypeId.protected TypeCompiler
getTypeCompiler(TypeId typeId)
Get the TypeCompiler that corresponds to the given TypeId.protected TypeId
getTypeId()
Get the TypeId that corresponds to this TypeCompiler.(package private) abstract java.lang.String
nullMethodName()
Return the method name to get a Derby DataValueDescriptor object of the correct type set to SQL NULL.(package private) boolean
numberConvertible(TypeId otherType, boolean forDataTypeFunction)
Tell whether this numeric type can be converted to the given type.(package private) boolean
numberStorable(TypeId thisType, TypeId otherType, ClassFactory cf)
Tell whether this numeric type can be stored into from the given type.(package private) boolean
pushCollationForDataValue(int collationType)
Return true if the collationType is to be passed to the methods generated by generateNull and generateDataValue.DataTypeDescriptor
resolveArithmeticOperation(DataTypeDescriptor leftType, DataTypeDescriptor rightType, java.lang.String operator)
Type resolution methods on binary operators(package private) void
setTypeId(TypeId typeId)
Set the TypeCompiler that corresponds to the given TypeId.protected boolean
userTypeStorable(TypeId thisType, TypeId otherType, ClassFactory cf)
Determine whether thisType is storable in otherType due to otherType being a user type.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.derby.iapi.sql.compile.TypeCompiler
compatible, convertible, getCastToCharWidth, getCorrespondingPrimitiveTypeName, interfaceName, storable
-
-
-
-
Field Detail
-
correspondingTypeId
private TypeId correspondingTypeId
-
-
Method Detail
-
getPrimitiveMethodName
public java.lang.String getPrimitiveMethodName()
Get the method name for getting out the corresponding primitive Java type.- Specified by:
getPrimitiveMethodName
in interfaceTypeCompiler
- Returns:
- String The method call name for getting the corresponding primitive Java type.
-
resolveArithmeticOperation
public DataTypeDescriptor resolveArithmeticOperation(DataTypeDescriptor leftType, DataTypeDescriptor rightType, java.lang.String operator) throws StandardException
Description copied from interface:TypeCompiler
Type resolution methods on binary operators- Specified by:
resolveArithmeticOperation
in interfaceTypeCompiler
- Parameters:
leftType
- The type of the left parameterrightType
- The type of the right parameteroperator
- The name of the operator (e.g. "+").- Returns:
- The type of the result
- Throws:
StandardException
- Thrown on error- See Also:
TypeCompiler.resolveArithmeticOperation(org.apache.derby.iapi.types.DataTypeDescriptor, org.apache.derby.iapi.types.DataTypeDescriptor, java.lang.String)
-
generateNull
public void generateNull(MethodBuilder mb, int collationType)
The caller will have pushed a DataValueFactory and a null or a value of the correct type (interfaceName()). Thus upon entry the stack looks like on of: ...,dvf,ref ...,dvf,null This method then sets up to call the required method on DataValueFactory using the nullMethodName(). The value left on the stack will be a DataValueDescriptor of the correct type: ...,dvd- Specified by:
generateNull
in interfaceTypeCompiler
- Parameters:
mb
- The method to put the expression incollationType
- For character DVDs, this will be used to determine what Collator should be associated with the DVD which in turn will decide whether to generate CollatorSQLcharDVDs or SQLcharDVDs.- See Also:
TypeCompiler.generateNull(MethodBuilder, int)
-
generateDataValue
public void generateDataValue(MethodBuilder mb, int collationType, LocalField field)
The caller will have pushed a DataValueFactory and value of that can be converted to the correct type, e.g. int for a SQL INTEGER. Thus upon entry the stack looks like: ...,dvf,value If field is not null then it is used as the holder of the generated DataValueDescriptor to avoid object creations on multiple passes through this code. The field may contain null or a valid value. This method then sets up to call the required method on DataValueFactory using the dataValueMethodName(). The value left on the stack will be a DataValueDescriptor of the correct type: If the field contained a valid value then generated code will return that value rather than a newly created object. If field was not-null then the generated code will set the value of field to be the return from the DataValueFactory method call. Thus if the field was empty (set to null) when this code is executed it will contain the newly generated value, otherwise it will be reset to the same value. ...,dvd- Specified by:
generateDataValue
in interfaceTypeCompiler
- Parameters:
mb
- The method to put the expression incollationType
- For character DVDs, this will be used to determine what Collator should be associated with the DVD which in turn will decide whether to generate CollatorSQLcharDVDs or SQLcharDVDs. For other types of DVDs, this parameter will be ignored.field
- LocalField- See Also:
TypeCompiler.generateDataValue(MethodBuilder, int, LocalField)
-
nullMethodName
abstract java.lang.String nullMethodName()
Return the method name to get a Derby DataValueDescriptor object of the correct type set to SQL NULL. The method named will be called with one argument: a holder object if pushCollationForDataValue() returns false, otherwise two arguments, the second being the collationType.
-
dataValueMethodName
java.lang.String dataValueMethodName()
Return the method name to get a Derby DataValueDescriptor object of the correct type and set it to a specific value. The method named will be called with two arguments, a value to set the returned value to and a holder object if pushCollationForDataValue() returns false. Otherwise three arguments, the third being the collationType. This implementation returns "getDataValue" to map to the overloaded methods DataValueFactory.getDataValue(type, dvd type)
-
pushCollationForDataValue
boolean pushCollationForDataValue(int collationType)
Return true if the collationType is to be passed to the methods generated by generateNull and generateDataValue.- Parameters:
collationType
- Collation type of character values.- Returns:
- true collationType will be pushed, false collationType will be ignored.
-
userTypeStorable
protected boolean userTypeStorable(TypeId thisType, TypeId otherType, ClassFactory cf)
Determine whether thisType is storable in otherType due to otherType being a user type.- Parameters:
thisType
- The TypeId of the value to be storedotherType
- The TypeId of the value to be stored in- Returns:
- true if thisType is storable in otherType
-
numberConvertible
boolean numberConvertible(TypeId otherType, boolean forDataTypeFunction)
Tell whether this numeric type can be converted to the given type.- Parameters:
otherType
- The TypeId of the other type.forDataTypeFunction
- was this called from a scalarFunction like CHAR() or DOUBLE()
-
numberStorable
boolean numberStorable(TypeId thisType, TypeId otherType, ClassFactory cf)
Tell whether this numeric type can be stored into from the given type.- Parameters:
thisType
- The TypeId of this typeotherType
- The TypeId of the other type.cf
- A ClassFactory
-
getTypeId
protected TypeId getTypeId()
Get the TypeId that corresponds to this TypeCompiler.
-
getTypeCompiler
protected TypeCompiler getTypeCompiler(TypeId typeId)
Get the TypeCompiler that corresponds to the given TypeId.
-
setTypeId
void setTypeId(TypeId typeId)
Set the TypeCompiler that corresponds to the given TypeId.
-
getStoredFormatIdFromTypeId
protected int getStoredFormatIdFromTypeId()
Get the StoredFormatId from the corresponding TypeId.- Returns:
- The StoredFormatId from the corresponding TypeId.
-
-