Interface AdlSqlType

All Superinterfaces:
de.calamanari.adl.cnv.tps.AdlType, Serializable
All Known Implementing Classes:
AdlSqlTypeDecorator, DefaultAdlSqlType

public interface AdlSqlType extends de.calamanari.adl.cnv.tps.AdlType
This sub-type of AdlType is especially made for SQL conversion.

If the given set of DefaultAdlSqlTypes is insufficient or any special case handling is required, type behavior can be adjusted. By decorating types (e.g., withQueryParameterApplicator(QueryParameterApplicator)) implementors can adapt any type to any column type in the database.

Be careful when introducing entirely new types (besides DefaultAdlSqlType and their decorations) as the implementation of the other classes may directly depend on concrete types. See also DefaultQueryParameterCreator and DefaultQueryParameterApplicator.

AdlSqlTypes must not be used to configure the logical data model.

Important: The formatters (AdlType.getFormatter()) of these instances are actually not used to format the values of a query for execution because for safety reasons we rely on PreparedStatements. Instead, the formatters of AdlSqlTypes are meant for producing (functional) statements for debugging and logging purposes.
See also: QueryParameterApplicator.applyUnsafe(StringBuilder, de.calamanari.adl.sql.QueryParameter, int).

Author:
Karl Eilebrecht
  • Method Details

    • getJavaSqlType

      int getJavaSqlType()
      Returns:
      this is the underlying SQL-type for this type, see Types (mainly for reference and debugging)
    • getQueryParameterCreator

      QueryParameterCreator getQueryParameterCreator()
      Returns:
      the component that can convert a given expression argument of any given AdlType into an SQL-query parameter compliant to this type. NOT NULL.
    • getQueryParameterApplicator

      QueryParameterApplicator getQueryParameterApplicator()
      Returns:
      the component that can set a parameter (sql-value) on a statement, NOT NULL
    • getBaseType

      default AdlSqlType getBaseType()
      Specified by:
      getBaseType in interface de.calamanari.adl.cnv.tps.AdlType
    • withNativeTypeCaster

      default AdlSqlType withNativeTypeCaster(String name, de.calamanari.adl.cnv.tps.NativeTypeCaster nativeTypeCaster)
      Specified by:
      withNativeTypeCaster in interface de.calamanari.adl.cnv.tps.AdlType
    • withNativeTypeCaster

      default AdlSqlType withNativeTypeCaster(de.calamanari.adl.cnv.tps.NativeTypeCaster nativeTypeCaster)
      Specified by:
      withNativeTypeCaster in interface de.calamanari.adl.cnv.tps.AdlType
    • withFormatter

      default AdlSqlType withFormatter(String name, de.calamanari.adl.cnv.tps.ArgValueFormatter formatter)
      Specified by:
      withFormatter in interface de.calamanari.adl.cnv.tps.AdlType
    • withFormatter

      default AdlSqlType withFormatter(de.calamanari.adl.cnv.tps.ArgValueFormatter formatter)
      Specified by:
      withFormatter in interface de.calamanari.adl.cnv.tps.AdlType
    • withQueryParameterCreator

      default AdlSqlType withQueryParameterCreator(String name, QueryParameterCreator queryParameterCreator)
      Allows adding a new QueryParameterCreator to an existing type to refine the behavior of the composed AdlSqlType

      Specifying a custom name may be useful if you know that the effectively identical type setup would otherwise occur multiple times with different names (edge-case). Usually, the auto-generated wrapper names should be preferred.

      Parameters:
      name - unique name (or null to auto-generate a unique one)
      queryParameterCreator -
      Returns:
      composed type or this instance if the provided formatter was null
    • withQueryParameterCreator

      default AdlSqlType withQueryParameterCreator(QueryParameterCreator queryParameterCreator)
      Allows adding a new QueryParameterCreator to an existing type to refine the behavior of the composed AdlSqlType
      Parameters:
      queryParameterCreator -
      Returns:
      composed type
    • withQueryParameterApplicator

      default AdlSqlType withQueryParameterApplicator(String name, QueryParameterApplicator queryParameterApplicator)
      Allows adding a new QueryParameterApplicator to an existing type to refine the behavior of the composed AdlSqlType

      Specifying a custom name may be useful if you know that the effectively identical type setup would otherwise occur multiple times with different names (edge-case). Usually, the auto-generated wrapper names should be preferred.

      Parameters:
      name - unique name (or null to auto-generate a unique one)
      queryParameterApplicator -
      Returns:
      composed type or this instance if the provided formatter was null
    • withQueryParameterApplicator

      default AdlSqlType withQueryParameterApplicator(QueryParameterApplicator queryParameterApplicator)
      Allows adding a new QueryParameterApplicator to an existing type to refine the behavior of the composed AdlSqlType
      Parameters:
      queryParameterApplicator -
      Returns:
      composed type
    • isCompatibleWith

      default boolean isCompatibleWith(de.calamanari.adl.cnv.tps.AdlType type)
      Tells whether there is a chance that a value of the given argument type can be translated into an sql paramter of this type.

      Important: This method only tells that a conversion from the given type to this type might be possible. It can still happen that a particular value will be rejected at runtime.

      Examples:

      • A string to integer conversion is only possible if the input value is the textual representation of an integer. This method should return true
      • It is principally impossible to turn a boolean into a date. This method should return false.
      By definition, AdlSqlTypes shall be incompatible (return false) to any AdlSqlType (even itself) to ensure SQL-types cannot be abused for the logical data model.
      Parameters:
      type - to be tested for compatibility with this type
      Returns:
      true if there are any values of the given type that can be converted into this type