I have a class called FooFunctionRepository
with the method void save(Function<Foo, Foo> fooFunction)
which save in a map the given function and creates a snapshot (not always) of Foo
object, so when I want to fetch an object Foo
by id I don't have to parse the list of functions and "recalculate" the object state, I just fetch the last snapshot and then apply the saved functions after snapshot was taken.
var repository = new FooFunctionRepository();
var fooId = UUID.randomUUID();
repository.save(fooId, none -> new Foo());
repository.save(fooId, foo -> foo.withAmount(new BigDecimal(50)));
repository.save(fooId, foo -> foo.withAmount(foo.getAmount().add(BigDecimal.TEN)));
repository.save(fooId, foo -> foo.withStatus("shipped"));
I have to replace the in memory map Map<UUID, Function<Foo, Foo>
from repository with a database table. My question is how to save the lambda let's say using Hibernate? Or should I replace the function with a DTO? But how the DTO is going to know what to change in my object?
Aucun commentaire:
Enregistrer un commentaire