Package de.calamanari.adl.sql
Class DefaultQueryParameterCreator
java.lang.Object
de.calamanari.adl.sql.DefaultQueryParameterCreator
- All Implemented Interfaces:
QueryParameterCreator,Serializable
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 Summary
Modifier and TypeMethodDescriptioncreateParameter(de.calamanari.adl.cnv.tps.ArgMetaInfo argMetaInfo, String argValue, de.calamanari.adl.irl.MatchOperator matchOperator, AdlSqlType adlSqlType) Takes an argument from an expression withAdlTypeinformation as its input to create aQueryParameterto be applied to aPreparedStatementat a later time.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.static final DefaultQueryParameterCreatorbooleanisTypeCombinationSupported(de.calamanari.adl.cnv.tps.AdlType sourceType, AdlSqlType targetType) 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.static voidResets the ID-sequence (for parameters) to its initial value (for testing purposes to get reproducible results)
-
Method Details
-
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:
createParameterin interfaceQueryParameterCreator- Parameters:
id- the temporary id of the new parameter, seeQueryParameter, NOT NULL (useQueryParameterCreator.createParameter(ArgMetaInfo, String, MatchOperator, AdlSqlType)instead)argMetaInfo- describes the source argument typeargValue- value to be passed as parameter of a querymatchOperator- contextadlSqlType- 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:QueryParameterCreatorThis 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.
AdlSqlTypes shall be incompatible (return false) to anyAdlSqlType(even itself) to ensure SQL-types cannot be abused for the logical data model.- Specified by:
isTypeCombinationSupportedin interfaceQueryParameterCreator- Parameters:
sourceType- argument type from the logical data modeltargetType- 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:QueryParameterCreatorTakes an argument from an expression withAdlTypeinformation as its input to create aQueryParameterto be applied to aPreparedStatementat a later time.- Specified by:
createParameterin interfaceQueryParameterCreator- Parameters:
argMetaInfo- describes the source argument typeargValue- value to be passed as parameter of a querymatchOperator- context information: the operation the parameter is required foradlSqlType- 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)
-