-
Notifications
You must be signed in to change notification settings - Fork 682
Add API for property specific converters [DATACMNS-1036] #1484
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
Oliver Drotbohm commented
interface PPC<T, S, P extends PersistentProperty<P>> { …}
interface PPCPlugin extends Plugin<P> { … }
class Conversions implements PPCPlugin {
PropertyPath path;
<K, L extends S> PPCSupport assignTo(PPC converter, Class<K> type, Function<K, L> consumer) {
Recorder recorder = MIR.forProxyOfType(type).record(consumer);
this.path = PropertyPath.of(type, recorder.getPropertyPath());
}
supports(PP property) {
if (path.getSegment() != null) {
path.getOwner == property.getOwner
path.getSegment == property.getName;
} else {
path.getOwner = property.getType
}
}
}
PluginRegistry<PPC<…>, PersistentProperty<?>> registry;
PPC converter = registry.getPluginFor(property, () -> new DefaultPPC());
class MyEncodingConverter extends PPCSupport<String, String, …> {
read(…);
write(…);
}
class Config {
@Bean
Conversions foo() {
return ConversionsBuilder.forConverter(new MyEncodingConverter())
.assignByProperty(Employee.class, Employee::getPassword, e -> e.getEmail().getValue())
.assingByType(Password.class));
}
}
} |
If I might have a suggestion, the converter would be superior even to the JPA version if the context (the POJO being converted, the field being converted, etc) would be also available and not just the values. JPA (only values): For example the second can be used to check for annotations on the field (or values of other fields), and the conversion can be dynamic based on that. @RequiredArgsConstructor
class EncryptingTranslatorFactory implements TranslatorFactory<String, String> {
@NonNull
private final EncryptionService encryptionService;
@Override
public Translator<String, String> create(TypeKey<String> tk, CreateContext ctx, Path path) {
if (tk.isAnnotationPresent(Sensitive.class)) {
if (tk.getTypeAsClass() != String.class) {
throw new IllegalStateException("@Sensitive is only supported for String at the moment!");
}
return <...>;
} else {
return null;
}
}
} |
Introduce a builder API to register PropertyValueConverters using simple (Bi)Functions. Additional methods on ValueConversionContext to enable advanced use cases in converter implementation. Tweak generics of VCC to be able to expose store-specific PersistentProperty implementations via the context. See #1484 Original pull request: #2566.
Increase visibility of converter builders. Refine generics naming towards DV/SV instead of A/B to easier identify store-native values and domains-specific values in the API. Refactor PropertyValueConversions.hasValueConverter into a non-default method. Tweak documentation. See #1484 Original pull request: #2566.
Introduce a builder API to register PropertyValueConverters using simple (Bi)Functions. Additional methods on ValueConversionContext to enable advanced use cases in converter implementation. Tweak generics of VCC to be able to expose store-specific PersistentProperty implementations via the context. See #1484 Original pull request: #2566.
Increase visibility of converter builders. Refine generics naming towards DV/SV instead of A/B to easier identify store-native values and domains-specific values in the API. Refactor PropertyValueConversions.hasValueConverter into a non-default method. Tweak documentation. See #1484 Original pull request: #2566.
Oliver Drotbohm opened DATACMNS-1036 and commented
The current conversion subsystem can only deal with type based converters. We should add API to allow users to register converters for a specific
PersistentProperty
Issue Links:
DATACASS-668 Provide a way to custom convert some properties of an entity
("is depended on by")
DATAJDBC-379 Disable auto-apply custom converts
("is depended on by")
DATAJDBC-450 Storing non root entities in serialized form
DATAMONGO-889 Missing field and property annotations do not allow conditional conversion
5 votes, 5 watchers
The text was updated successfully, but these errors were encountered: