Class ConfigurableTypeConverter

java.lang.Object
org.litebridgedb.convert.ConfigurableTypeConverter
All Implemented Interfaces:
TypeConverter
Direct Known Subclasses:
DefaultTypeConverter

public class ConfigurableTypeConverter extends Object implements TypeConverter
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 Details

    • ConfigurableTypeConverter

      public ConfigurableTypeConverter()
  • Method Details

    • convert

      public @Nullable Object convert(@Nullable Object value, int dbDataType)
      Converts a value to a database-specific representation (or vice-versa) based on the Types code.
      Specified by:
      convert in interface TypeConverter
      Parameters:
      value - the value to convert, may be null
      dbDataType - the Types code for the database data type
      Returns:
      the converted value, or null if the input was null
      Throws:
      IllegalArgumentException - if no converter is found for the specified SQL type
    • convert

      public <T> @Nullable T convert(@Nullable Object value, Class<T> type)
      Converts a value to a specific Java type.
      Specified by:
      convert in interface TypeConverter
      Type Parameters:
      T - the target Java type
      Parameters:
      value - the value to convert, may be null
      type - the target Java type
      Returns:
      the converted value, or null if the input was null
      Throws:
      IllegalArgumentException - if no converter is found for the specified Java type
    • register

      public void register(Converter<?> converter)
      Registers a new converter.
      Parameters:
      converter - the converter to register
    • register

      public <T> void register(Class<T> type, ConverterFunction<T> converterFunction)
      Registers a converter for a specific Java type using a functional interface.
      Type Parameters:
      T - the target Java type
      Parameters:
      type - the target Java type
      converterFunction - the conversion logic
    • register

      public <T> void register(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.
      Type Parameters:
      T - the target Java type
      Parameters:
      type - the target Java type
      sqlTypes - an array of Types codes associated with this converter
      converterFunction - the conversion logic
    • unregister

      public void unregister(Class<?> type)
      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 - the Types code to unregister