java.lang.Object
org.litebridgedb.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.<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
-
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
-