Package tech.ydb.yoj.databind.converter
Interface ValueConverter<J,C extends Comparable<? super C>>
- Type Parameters:
J- Java field value typeC- Database column value type. Must not be the same type as<J>. Must beComparable.
- 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.
ValueConvertermight be created and called from any thread: it is possible fortoColumn()method to be called while the same instance'stoJava()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
ValueConvertermust not affect the result of the conversions. - Never acquire scarce or heavy system resources, because YOJ might create a
ValueConverterat any time, and there is no way to dispose of a createdValueConverter.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final classRepresents "no custom converter is defined" for@CustomValueTypeannotation inside a@Columnannotation. -
Method Summary
Modifier and TypeMethodDescriptiontoColumn(@NonNull Schema.JavaField field, J v) Converts a field value to adatabase column valuesupported by YOJ.toJava(@NonNull Schema.JavaField field, C c) Converts a database column value to a Java field value.
-
Method Details
-
toColumn
Converts a field value to adatabase column valuesupported by YOJ.- Parameters:
field- schema fieldv- field value, guaranteed to not benull- Returns:
- database column value corresponding to the Java field value, must not be
null - See Also:
-
toJava
Converts a database column value to a Java field value.- Parameters:
field- schema fieldc- database column value, guaranteed to not benull- Returns:
- Java field value corresponding to the database column value, must not be
null - See Also:
-