Interface ValueConverter<J,C extends Comparable<? super C>>

Type Parameters:
J - Java field value type
C - Database column value type. Must not be the same type as <J>. Must be Comparable.
All Known Implementing Classes:
EnumOrdinalConverter, StringValueConverter, ValueConverter.NoConverter

public interface ValueConverter<J,C extends Comparable<? super C>>
Custom conversion logic between database column values (<C>) and Java field values (<J>).

A good citizen ValueConverter must:

  • Have a no-args public constructor that does not perform any CPU- or I/O-intensive operations.
  • Be thread-safe and reentrant. ValueConverter might be created and called from any thread: it is possible for toColumn() method to be called while the same instance's toJava() method is running in a different thread, and vice versa. It it therefore highly recommended for the conversion to be a pure function.
  • Be effectively stateless: changes to the internal state of the ValueConverter must not affect the result of the conversions.
  • Never acquire scarce or heavy system resources, because YOJ might create a ValueConverter at any time, and there is no way to dispose of a created ValueConverter.
  • Method Details

    • toColumn

      @NonNull C toColumn(@NonNull @NonNull Schema.JavaField field, @NonNull J v)
      Converts a field value to a database column value supported by YOJ.
      Parameters:
      field - schema field
      v - field value, guaranteed to not be null
      Returns:
      database column value corresponding to the Java field value, must not be null
      See Also:
    • toJava

      @NonNull J toJava(@NonNull @NonNull Schema.JavaField field, @NonNull C c)
      Converts a database column value to a Java field value.
      Parameters:
      field - schema field
      c - database column value, guaranteed to not be null
      Returns:
      Java field value corresponding to the database column value, must not be null
      See Also: