Class DefaultQueryParameterCreator

java.lang.Object
de.calamanari.adl.sql.DefaultQueryParameterCreator
All Implemented Interfaces:
QueryParameterCreator, Serializable

public class DefaultQueryParameterCreator extends Object implements QueryParameterCreator
The DefaultQueryParameterCreator takes the base type (AdlType.getBaseType()) of an argument's type and tries to create a QueryParameter applicable to the base type (AdlSqlType.getBaseType()) of the requested SQL-type.

This default implementation is only applicable to base types DefaultAdlType (input) resp. DefaultAdlSqlType (output).

Note: Part of this implementation are a couple of type alignments (see isTypeCombinationSupported(AdlType, AdlSqlType)) to allow lenient handling of differences wherever possible.

Author:
Karl Eilebrecht
See Also:
  • Method Details

    • getInstance

      public static final DefaultQueryParameterCreator getInstance()
      Returns:
      the only instance of this creator
    • createParameter

      public DefaultQueryParameter createParameter(String id, de.calamanari.adl.cnv.tps.ArgMetaInfo argMetaInfo, String argValue, de.calamanari.adl.irl.MatchOperator matchOperator, AdlSqlType adlSqlType)
      This is the preferred method to create a valid parameter to ensure compatibility with the target column.
      Specified by:
      createParameter in interface QueryParameterCreator
      Parameters:
      id - the temporary id of the new parameter, see QueryParameter, NOT NULL (use QueryParameterCreator.createParameter(ArgMetaInfo, String, MatchOperator, AdlSqlType) instead)
      argMetaInfo - describes the source argument type
      argValue - value to be passed as parameter of a query
      matchOperator - context
      adlSqlType - requested type
      Returns:
      parameter for PreparedStatement execution
      Throws:
      de.calamanari.adl.cnv.tps.AdlFormattingException - in case of incompatibilities and errors
    • isTypeCombinationSupported

      public boolean isTypeCombinationSupported(de.calamanari.adl.cnv.tps.AdlType sourceType, AdlSqlType targetType)
      Description copied from interface: QueryParameterCreator
      This method tells whether an argument of the given sourceType can be mapped to the targetType to create a valid SQL-parameter.
      It is meant for detecting configuration errors early.

      Important: This method only tells that a conversion from the source type to the target 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.
      Specified by:
      isTypeCombinationSupported in interface QueryParameterCreator
      Parameters:
      sourceType - argument type from the logical data model
      targetType - column type
      Returns:
      true if the combination is supported by this creator, otherwise false
    • createParameter

      public QueryParameter createParameter(de.calamanari.adl.cnv.tps.ArgMetaInfo argMetaInfo, String argValue, de.calamanari.adl.irl.MatchOperator matchOperator, AdlSqlType adlSqlType)
      Description copied from interface: QueryParameterCreator
      Takes an argument from an expression with AdlType information as its input to create a QueryParameter to be applied to a PreparedStatement at a later time.

      Specified by:
      createParameter in interface QueryParameterCreator
      Parameters:
      argMetaInfo - describes the source argument type
      argValue - value to be passed as parameter of a query
      matchOperator - context information: the operation the parameter is required for
      adlSqlType - requested type (target column)
      Returns:
      parameter for PreparedStatement execution
    • resetIdSequence

      public static void resetIdSequence()
      Resets the ID-sequence (for parameters) to its initial value (for testing purposes to get reproducible results)