You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While trying to create a resultmap that has a collection as a constructor parameter I stumbled with issue #101 .
I can understand the problems that are exposed there and they are certainly not minor.
But I was wondering if instead a feature that would allow to add elements one by one by calling a method would be more doable.
public class A {
final private List<B> relatedBs;
public A() {
relatedBs = new ArrayList<>();
}
public void addB(B b) {
relatedBs.add(b);
// Do whatever you want for each add B
}
public List<B> getBs() {
// Or do a clone if you want to return a defensive copy
return this.relatedBs;
}
}
Then you could specify somehting like "<incrementalCollection>" in your xml or just add another attribute to "<collection>" to configure this behaviour. I would probably go for the first approach as it makes intention much clearer.
Obviously your internal collection is not in fact inmutable, but it doesn't pretend it is either and could be quite useful while still attaching to the idea of having just "POJO"s and no special types.
Maybe you could even add an additional attribute to specify a "completed" method that myBatis would call when the resultset is completely loaded (that's probably the idea of the callback that was already mentioned in #101 ).
That way a regular user could just use a "collection" or an "incrementalCollection" and probably receive the object when it is already complete, a user wanting do some processing as she gets data can also manage it easily and, if the "completed" callback is added, she could even do his logic there to "freeze" the collection.
The text was updated successfully, but these errors were encountered:
While trying to create a resultmap that has a collection as a constructor parameter I stumbled with issue #101 .
I can understand the problems that are exposed there and they are certainly not minor.
But I was wondering if instead a feature that would allow to add elements one by one by calling a method would be more doable.
Then you could specify somehting like "<incrementalCollection>" in your xml or just add another attribute to "<collection>" to configure this behaviour. I would probably go for the first approach as it makes intention much clearer.
Obviously your internal collection is not in fact inmutable, but it doesn't pretend it is either and could be quite useful while still attaching to the idea of having just "POJO"s and no special types.
Maybe you could even add an additional attribute to specify a "completed" method that myBatis would call when the resultset is completely loaded (that's probably the idea of the callback that was already mentioned in #101 ).
That way a regular user could just use a "collection" or an "incrementalCollection" and probably receive the object when it is already complete, a user wanting do some processing as she gets data can also manage it easily and, if the "completed" callback is added, she could even do his logic there to "freeze" the collection.
The text was updated successfully, but these errors were encountered: