flipkart-incubator / databuilderframework

A data driven execution engine
33 stars 29 forks source link

DataSet Passed to builder should be immutable #31

Closed Kaustavd closed 5 years ago

Kaustavd commented 5 years ago

One of the primary use case of builder is to do state management of entity which is being represented as data. For this one builder access same data which is being produced by the same. In case builder prematurely exits for some reasons(exceptions) partial commit happens which is not correct. IMO ideally immutable copy should be passed to handle this scenarios

santanusinha commented 5 years ago

Immutable copies are really difficult in java as it does not have proper const correctness. A solution would be use cglib type immutable proxies for the data being input in dataset. This would cause potentially serious performance penalties to block against wrong usage and generate a Runtime exception. (It is wrong modelling to modify some data in dataset, a builder should copy and generate new objects, not modify them). Will think about this, but i do not think there is a very clean solution out there.

santanusinha commented 5 years ago

Also your data classes should only have final attributes. That way, there is no risk of mutations by others. Serialization and Deserialization of such classes now work fine with jackson either with @JsonProperty annotation in constructor or by using the parameter names module for jackson. This is the only scalable and performant solution to this problem.