Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Support for results transformer (e.g. group by) #17
There should be an easy way of defining (generic) transformers over a whole result set. For example to group results by.
Under the hood this boils down to ResultTransformer interface that functions as a callback that gets a Projectable and returns the digested results:
Samppa Saarela (samppa-saarela) on 2011-09-14
Basic functionality is now committed to master:
which is implemented by
This is not yet integrated to Projectable (e.g. SQLQuery), but it is usable none the less with a slight variation to above:
Collection groups = new GroupByTransformer(post.id, post.name, comment.id).transform(qry);
A more efficient grouping implementation would be GroupByOrdered which would require that the resuts are ordered by the group id...
I'm working on a bit more elegant solution keeping BeanMapper in mind. The idea is to use fluent syntax to build up a group-definition that converts results straight into correct collection types.
With model Post(id, name) 1--N Comment(id, text)
Map<Integer, Group2> results =
Group2 group = results.get(1);