java.lang.Object
org.litebridge.convert.ConfigurableTypeConverter
- All Implemented Interfaces:
TypeConverter
- Direct Known Subclasses:
DefaultTypeConverter
A concrete implementation of
TypeConverter that allows manual registration and unregistration of converters.
This class provides a flexible way to manage Converter instances for both Java types and SQL types.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@Nullable ObjectConverts a value to a database-specific representation (or vice-versa) based on theTypescode.<T> @Nullable TConverts a value to a specific Java type.Class<?> getClassForSqlType(int sqlDataType) Retrieves the JavaClasscorresponding to the specified SQL data type.intgetSqlDataType(Class<?> fieldType) Determines the SQL data type corresponding to the provided Java class.<T> voidregister(Class<T> type, int[] sqlTypes, ConverterFunction<T> converterFunction) Registers a converter for a specific Java type and its associated SQL types using a functional interface.<T> voidregister(Class<T> type, ConverterFunction<T> converterFunction) Registers a converter for a specific Java type using a functional interface.voidRegisters a new converter.voidunregister(int sqlType) Removes a converter for a specific SQL type.voidunregister(Class<?> type) Removes a converter for a specific Java type.
-
Constructor Details
-
ConfigurableTypeConverter
public ConfigurableTypeConverter()
-
-
Method Details
-
convert
Converts a value to a database-specific representation (or vice-versa) based on theTypescode.- Specified by:
convertin interfaceTypeConverter- Parameters:
value- the value to convert, may benulldbDataType- theTypescode for the database data type- Returns:
- the converted value, or
nullif the input wasnull - Throws:
IllegalArgumentException- if no converter is found for the specified SQL type
-
convert
Converts a value to a specific Java type.- Specified by:
convertin interfaceTypeConverter- Type Parameters:
T- the target Java type- Parameters:
value- the value to convert, may benulltype- the target Java type- Returns:
- the converted value, or
nullif the input wasnull - Throws:
IllegalArgumentException- if no converter is found for the specified Java type
-
getSqlDataType
Description copied from interface:TypeConverterDetermines the SQL data type corresponding to the provided Java class.- Specified by:
getSqlDataTypein interfaceTypeConverter- Parameters:
fieldType- the JavaClassobject representing the field type to be mapped to a SQL data type- Returns:
- an integer representing the SQL data type, typically a constant defined in
Types - Throws:
IllegalArgumentException- if no SQL data type mapping is found for the given Java class
-
getClassForSqlType
Description copied from interface:TypeConverterRetrieves the JavaClasscorresponding to the specified SQL data type.- Specified by:
getClassForSqlTypein interfaceTypeConverter- Parameters:
sqlDataType- the database-specific SQL data type as an integer code, typically a constant defined inTypes- Returns:
- the Java
Classthat represents the SQL data type, ornullif no mapping is found - Throws:
IllegalArgumentException- if no class mapping is found for the given SQL data type
-
register
Registers a new converter.- Parameters:
converter- the converter to register
-
register
Registers a converter for a specific Java type using a functional interface.- Type Parameters:
T- the target Java type- Parameters:
type- the target Java typeconverterFunction- the conversion logic
-
register
Registers a converter for a specific Java type and its associated SQL types using a functional interface.- Type Parameters:
T- the target Java type- Parameters:
type- the target Java typesqlTypes- an array ofTypescodes associated with this converterconverterFunction- the conversion logic
-
unregister
Removes a converter for a specific Java type.- Parameters:
type- the Java type to unregister
-
unregister
public void unregister(int sqlType) Removes a converter for a specific SQL type.- Parameters:
sqlType- theTypescode to unregister
-