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 Object implements TypeCompiler
This is the base implementation of TypeCompiler
  • Field Details

    • correspondingTypeId

      private TypeId correspondingTypeId
  • Constructor Details

    • BaseTypeCompiler

      BaseTypeCompiler()
  • Method Details

    • getPrimitiveMethodName

      public String getPrimitiveMethodName()
      Get the method name for getting out the corresponding primitive Java type.
      Specified by:
      getPrimitiveMethodName in interface TypeCompiler
      Returns:
      String The method call name for getting the corresponding primitive Java type.
    • resolveArithmeticOperation

      public DataTypeDescriptor resolveArithmeticOperation(DataTypeDescriptor leftType, DataTypeDescriptor rightType, String operator) throws StandardException
      Description copied from interface: TypeCompiler
      Type resolution methods on binary operators
      Specified by:
      resolveArithmeticOperation in interface TypeCompiler
      Parameters:
      leftType - The type of the left parameter
      rightType - The type of the right parameter
      operator - The name of the operator (e.g. "+").
      Returns:
      The type of the result
      Throws:
      StandardException - Thrown on error
      See Also:
    • 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 interface TypeCompiler
      Parameters:
      mb - The method to put the expression in
      collationType - 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:
    • 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 interface TypeCompiler
      Parameters:
      mb - The method to put the expression in
      collationType - 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:
    • nullMethodName

      abstract 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

      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 stored
      otherType - 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 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.