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

java.lang.Object
  extended byorg.apache.derby.impl.sql.compile.BaseTypeCompiler
      extended byorg.apache.derby.impl.sql.compile.NumericTypeCompiler
All Implemented Interfaces:
TypeCompiler

public final class NumericTypeCompiler
extends BaseTypeCompiler

This class implements TypeId for the SQL numeric datatype.

Author:
Jeff Lichtman

Field Summary
 
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
NumericTypeCompiler()
           
 
Method Summary
 boolean comparable(TypeId otherType, boolean forEquals, ClassFactory cf)
          Determine if this type can be compared to some other type
 boolean compatible(TypeId otherType)
          Tell whether this type (numeric) is compatible with the given type.
 boolean convertible(TypeId otherType, boolean forDataTypeFunction)
          Determine if this type can be CONVERTed to some other type
protected  java.lang.String dataValueMethodName()
          Return the method name to get a Derby DataValueDescriptor object of the correct type.
 void generateDataValue(MethodBuilder mb, LocalField field)
          Generate the code necessary to produce a SQL value based on a value.
 void generateNull(MethodBuilder mb)
          Generate the code necessary to produce a SQL null of the appropriate type.
 int getCastToCharWidth(DataTypeDescriptor dts)
          Return the maximum width for this data type when cast to a char type.
 java.lang.String getCorrespondingPrimitiveTypeName()
          Get the name of the corresponding Java type.
 java.lang.String getMatchingNationalCharTypeName()
          Get the name of the matching national char type.
private  int getPrecision(java.lang.String operator, DataTypeDescriptor leftType, DataTypeDescriptor rightType)
          Get the precision of the operation involving two of the same types.
 java.lang.String getPrimitiveMethodName()
          Get the method name for getting out the corresponding primitive Java type.
private  int getScale(java.lang.String operator, DataTypeDescriptor leftType, DataTypeDescriptor rightType)
          Get the scale of the operation involving two of the same types.
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.
 java.lang.String interfaceName()
          Get the name of the interface for this type.
protected  java.lang.String nullMethodName()
           
 boolean numberComparable(TypeId otherType, boolean forEquals, ClassFactory cf)
          Tell whether this numeric type can be compared to the given type.
 boolean numberConvertible(TypeId otherType, boolean forDataTypeFunction)
          Tell whether this numeric type can be converted to the given type.
 boolean numberStorable(TypeId thisType, TypeId otherType, ClassFactory cf)
          Tell whether this numeric type can be stored into from the given type.
 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.
 boolean storable(TypeId otherType, ClassFactory cf)
          Determine if this type can have a value of another type stored into it.
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
 

Constructor Detail

NumericTypeCompiler

public NumericTypeCompiler()
Method Detail

interfaceName

public java.lang.String interfaceName()
Description copied from interface: TypeCompiler
Get the name of the interface for this type. For example, the interface for a SQLInteger is NumberDataValue. The full path name of the type is returned.

Returns:
The name of the interface for this type.
See Also:
TypeCompiler.interfaceName()

getCorrespondingPrimitiveTypeName

public java.lang.String getCorrespondingPrimitiveTypeName()
Description copied from interface: TypeCompiler
Get the name of the corresponding Java type. For numerics and booleans we will get the corresponding Java primitive type. e Each SQL type has a corresponding Java type. When a SQL value is passed to a Java method, it is translated to its corresponding Java type. For example, a SQL Integer will be mapped to a Java int, but a SQL date will be mapped to a java.sql.Date.

Returns:
The name of the corresponding Java primitive type.
See Also:
TypeCompiler.getCorrespondingPrimitiveTypeName()

getPrimitiveMethodName

public java.lang.String getPrimitiveMethodName()
Get the method name for getting out the corresponding primitive Java type.

Specified by:
getPrimitiveMethodName in interface TypeCompiler
Overrides:
getPrimitiveMethodName in class BaseTypeCompiler
Returns:
String The method call name for getting the corresponding primitive Java type.

getCastToCharWidth

public int getCastToCharWidth(DataTypeDescriptor dts)
Description copied from interface: TypeCompiler
Return the maximum width for this data type when cast to a char type.

Parameters:
dts - The associated DataTypeDescriptor for this TypeId.
Returns:
int The maximum width for this data type when cast to a char type.
See Also:
TypeCompiler.getCastToCharWidth(org.apache.derby.iapi.types.DataTypeDescriptor)

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 interface TypeCompiler
Overrides:
resolveArithmeticOperation in class BaseTypeCompiler
Throws:
StandardException - Thrown on error
See Also:
TypeCompiler.resolveArithmeticOperation(org.apache.derby.iapi.types.DataTypeDescriptor, org.apache.derby.iapi.types.DataTypeDescriptor, java.lang.String)

comparable

public boolean comparable(TypeId otherType,
                          boolean forEquals,
                          ClassFactory cf)
Description copied from interface: TypeCompiler
Determine if this type can be compared to some other type

Parameters:
otherType - The CompilationType of the other type to compare this type to
forEquals - True if this is an = or <> comparison, false otherwise.
cf - A ClassFactory
Returns:
true if the types can be compared, false if comparisons between the types are not allowed
See Also:
TypeCompiler.comparable(org.apache.derby.iapi.types.TypeId, boolean, org.apache.derby.iapi.services.loader.ClassFactory)

convertible

public boolean convertible(TypeId otherType,
                           boolean forDataTypeFunction)
Description copied from interface: TypeCompiler
Determine if this type can be CONVERTed to some other type

Parameters:
otherType - The CompilationType of the other type to compare this type to
forDataTypeFunction - true if this is a type function that requires more liberal behavior (e.g DOUBLE can convert a char but you cannot cast a CHAR to double.
Returns:
true if the types can be converted, false if conversion is not allowed
See Also:
TypeCompiler.convertible(org.apache.derby.iapi.types.TypeId, boolean)

compatible

public boolean compatible(TypeId otherType)
Tell whether this type (numeric) is compatible with the given type.

Parameters:
otherType - The TypeId of the other type.
Returns:
true if the types are compatible, false if not compatible

storable

public boolean storable(TypeId otherType,
                        ClassFactory cf)
Description copied from interface: TypeCompiler
Determine if this type can have a value of another type stored into it. Note that direction is relevant here: the test is that the otherType is storable into this type.

Parameters:
otherType - The TypeId of the other type to compare this type to
cf - A ClassFactory
Returns:
true if the other type can be stored in a column of this type.
See Also:
TypeCompiler.storable(org.apache.derby.iapi.types.TypeId, org.apache.derby.iapi.services.loader.ClassFactory)

dataValueMethodName

protected java.lang.String dataValueMethodName()
Return the method name to get a Derby DataValueDescriptor object of the correct type. This implementation returns "getDataValue".

Overrides:
dataValueMethodName in class BaseTypeCompiler

nullMethodName

protected java.lang.String nullMethodName()
Specified by:
nullMethodName in class BaseTypeCompiler

getPrecision

private int getPrecision(java.lang.String operator,
                         DataTypeDescriptor leftType,
                         DataTypeDescriptor rightType)
Get the precision of the operation involving two of the same types. Only meaningful for decimals, which override this.

Parameters:
operator - a string representing the operator, null means no operator, just a type merge
leftType - the left type
rightType - the left type
Returns:
the resultant precision

getScale

private int getScale(java.lang.String operator,
                     DataTypeDescriptor leftType,
                     DataTypeDescriptor rightType)
Get the scale of the operation involving two of the same types. Since we don't really have a good way to pass the resultant scale and precision around at execution time, we will model that BigDecimal does by default. This is good in most cases, though we would probably like to use something more sophisticated for division.

Parameters:
operator - a string representing the operator, null means no operator, just a type merge
leftType - the left type
rightType - the left type
Returns:
the resultant precision

generateDataValue

public void generateDataValue(MethodBuilder mb,
                              LocalField field)
Description copied from interface: TypeCompiler
Generate the code necessary to produce a SQL value based on a value. The value's type is assumed to match the type of this TypeId. For example, a TypeId for the SQL int type should be given an value that evaluates to a Java int or Integer. If the type of the value is incorrect, the generated code will not work. The stack must contain data value factory value

Specified by:
generateDataValue in interface TypeCompiler
Overrides:
generateDataValue in class BaseTypeCompiler
See Also:
TypeCompiler.generateDataValue(org.apache.derby.iapi.services.compiler.MethodBuilder, org.apache.derby.iapi.services.compiler.LocalField)

getMatchingNationalCharTypeName

public java.lang.String getMatchingNationalCharTypeName()
Description copied from interface: TypeCompiler
Get the name of the matching national char type.

Specified by:
getMatchingNationalCharTypeName in interface TypeCompiler
Returns:
The name of the matching national char type.
See Also:
TypeCompiler.getMatchingNationalCharTypeName()

generateNull

public void generateNull(MethodBuilder mb)
Description copied from interface: TypeCompiler
Generate the code necessary to produce a SQL null of the appropriate type. The stack must contain a DataValueFactory and a null or a value of the correct type (interfaceName()).

Specified by:
generateNull in interface TypeCompiler
Parameters:
mb - The method to put the expression in
See Also:
TypeCompiler.generateNull(org.apache.derby.iapi.services.compiler.MethodBuilder)

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 stored
otherType - The TypeId of the value to be stored in
Returns:
true if thisType is storable in otherType

numberComparable

public boolean numberComparable(TypeId otherType,
                                boolean forEquals,
                                ClassFactory cf)
Tell whether this numeric type can be compared to the given type.

Parameters:
otherType - The TypeId of the other type.

numberConvertible

public 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

public 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 type
otherType - 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.

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.