-
Notifications
You must be signed in to change notification settings - Fork 18
Custom byte array and number conversion logic #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
…re tests!!!] #24: EXPERIMENTAL: Custom converters to bridge between YOJ-supported field value types and totally custom user types
…ld value types and custom user types See the `@CustomValueType` annotation and the `ValueConverter` interface for more information.
…ld value types and custom user types See the `@CustomValueType` annotation and the `ValueConverter` interface for more information.
…ld value types and custom user types See the `@CustomValueType` annotation and the `ValueConverter` interface for more information.
Prototyping in #22 |
#22 merged, now we can use this experimental feature and improve it in future versions :-) |
Bug: This was not detected because my test custom-value type implemented Failing test: @Test
public void failingTest() {
var ve = new VersionedEntity(new VersionedEntity.Id("heyhey"), new Version(100_500L));
db.tx(() -> db.versionedEntities().insert(ve));
// Throws ClassCastException on eq() call
assertThat(db.tx(() -> db.versionedEntities().query()
.where("version").eq(ve.version())
.findOne()
)).isEqualTo(ve);
} Entity and cvt: public record VersionedEntity(
Id id,
Version version
) implements RecordEntity<VersionedEntity> {
public record Id(String value) implements Entity.Id<VersionedEntity> {
}
}
@CustomValueType(
columnValueType = FieldValueType.INTEGER,
columnClass = Long.class,
converter = Version.Converter.class
)
public record Version(long value) {
public static final class Converter implements ValueConverter<Version, Long> {
@Override
public @NonNull Long toColumn(@NonNull JavaField field, Version v) {
return v.value();
}
@Override
public @NonNull Version toJava(@NonNull JavaField field, @NonNull Long value) {
return new Version(value);
}
}
} |
- Add `@Deprecated(forRemoval=true)` and "will be removed in YOJ 3.0.0" warnings to `FieldValueType` pitfalls (`BINARY`, `isSortable()` etc.) - Remove `@CustomValueType.columnValueType` because it can always be deduced from `@CustomValueType.columnClass` instead. - Disallow *recursive* custom value types (that is, types whose converter in turn produce custom value types). - Allow preconverted values to be of a subclass of the column class. This is valuable if columnClass is a enum class, because Java makes anonymous inner classes of enums. Remove fast-path for postconverted values because it is never used by any real code (preconvert fast-path is used by `FieldValue`). - Add "map enum by ordinal" custom value type converter as a demonstration. Custom value types might become a viable alternatives for `@Column(dbQualifier="...")`.
Now we have meta-annotation support for |
- Cache custom value types in `Schema.JavaField` - Remove legacy string value type conversion logic, only use `StringValueConverter` "under the hood" - Log attempts to use deprecated methods in `FieldValueType` - Improve documentation and add `@ObjectColumn` annotation to express `@Column(flatten=false)` more clearly
🎉 As of YOJ 2.2.10, custom value conversion logic is considered fairly well-tested and is OK performance wise, but API changes are still likely. |
🎉 As of YOJ 2.5.x, the custom value conversion logic has stabilized; further API changes are unlikely. Custom conversion APIs will (most likely) stop being |
Value conversion logic is essentially feature-complete; no API changes are anticipated, closing this ticket. As promised in the previous comment, custom conversion APIs will stop being experimental in YOJ 3.0.0. |
Uh oh!
There was an error while loading. Please reload this page.
Add converter logic & annotations to make your custom types convertible to a basic repertoire of YOJ types hard-coded in
FieldValueType
.Note that at this time there is no attempt to make such types fully workable for complex scenarios, e.g. in-memory listing with filtering.
The text was updated successfully, but these errors were encountered: