Interface AdlSqlType
- All Superinterfaces:
de.calamanari.adl.cnv.tps.AdlType,Serializable
- All Known Implementing Classes:
AdlSqlTypeDecorator,DefaultAdlSqlType
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 Summary
Modifier and TypeMethodDescriptiondefault AdlSqlTypeintdefault booleanisCompatibleWith(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.default AdlSqlTypewithFormatter(de.calamanari.adl.cnv.tps.ArgValueFormatter formatter) default AdlSqlTypewithFormatter(String name, de.calamanari.adl.cnv.tps.ArgValueFormatter formatter) default AdlSqlTypewithNativeTypeCaster(de.calamanari.adl.cnv.tps.NativeTypeCaster nativeTypeCaster) default AdlSqlTypewithNativeTypeCaster(String name, de.calamanari.adl.cnv.tps.NativeTypeCaster nativeTypeCaster) default AdlSqlTypewithQueryParameterApplicator(QueryParameterApplicator queryParameterApplicator) Allows adding a newQueryParameterApplicatorto an existing type to refine the behavior of the composedAdlSqlTypedefault AdlSqlTypewithQueryParameterApplicator(String name, QueryParameterApplicator queryParameterApplicator) Allows adding a newQueryParameterApplicatorto an existing type to refine the behavior of the composedAdlSqlTypedefault AdlSqlTypewithQueryParameterCreator(QueryParameterCreator queryParameterCreator) Allows adding a newQueryParameterCreatorto an existing type to refine the behavior of the composedAdlSqlTypedefault AdlSqlTypewithQueryParameterCreator(String name, QueryParameterCreator queryParameterCreator) Allows adding a newQueryParameterCreatorto an existing type to refine the behavior of the composedAdlSqlTypeMethods inherited from interface de.calamanari.adl.cnv.tps.AdlType
getFormatter, getNativeTypeCaster, name, supportsContains, supportsLessThanGreaterThan
-
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
AdlTypeinto 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
- Specified by:
getBaseTypein interfacede.calamanari.adl.cnv.tps.AdlType
-
withNativeTypeCaster
default AdlSqlType withNativeTypeCaster(String name, de.calamanari.adl.cnv.tps.NativeTypeCaster nativeTypeCaster) - Specified by:
withNativeTypeCasterin interfacede.calamanari.adl.cnv.tps.AdlType
-
withNativeTypeCaster
default AdlSqlType withNativeTypeCaster(de.calamanari.adl.cnv.tps.NativeTypeCaster nativeTypeCaster) - Specified by:
withNativeTypeCasterin interfacede.calamanari.adl.cnv.tps.AdlType
-
withFormatter
default AdlSqlType withFormatter(String name, de.calamanari.adl.cnv.tps.ArgValueFormatter formatter) - Specified by:
withFormatterin interfacede.calamanari.adl.cnv.tps.AdlType
-
withFormatter
- Specified by:
withFormatterin interfacede.calamanari.adl.cnv.tps.AdlType
-
withQueryParameterCreator
default AdlSqlType withQueryParameterCreator(String name, QueryParameterCreator queryParameterCreator) Allows adding a newQueryParameterCreatorto an existing type to refine the behavior of the composedAdlSqlTypeSpecifying 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
Allows adding a newQueryParameterCreatorto an existing type to refine the behavior of the composedAdlSqlType- Parameters:
queryParameterCreator-- Returns:
- composed type
-
withQueryParameterApplicator
default AdlSqlType withQueryParameterApplicator(String name, QueryParameterApplicator queryParameterApplicator) Allows adding a newQueryParameterApplicatorto an existing type to refine the behavior of the composedAdlSqlTypeSpecifying 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
Allows adding a newQueryParameterApplicatorto an existing type to refine the behavior of the composedAdlSqlType- 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.
AdlSqlTypes shall be incompatible (return false) to anyAdlSqlType(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
-