It'd be great to specify result transformation logic in Lambda-style when running on Java 8:
session.createQuery( "SELECT foo, bar FROM Baz" )
.transformResultTuples( (tuple, aliases) -> { return tuple[0] + " " + tuple[1]; } )
.list();
That requires an interface with a single abstract method ("functional interface") describing the Lambda type. The current ResultTransformer interface has two methods, so it cannot be used as is. Proposal: Deprecate ResultTransformer and add two new, separate contracts as replacement: ResultRowTransformer and ResultListTransformer. Query#setResultTransformer() would be superseded by two new methods: transformResultTuples() and transformResultList(). Note that this change is fully compatible with previous Java versions: One still can pass an (anonymous) implementation of one or both of the contracts when stuck to Java 6/7:
session.createQuery( "SELECT foo, bar FROM Baz" )
.transformResultTuples( new ResultRowTransformer() {
public Object transformTuple(Object[] tuple, String[] aliases) {
return return tuple[0] + " " + tuple[1];
}
} )
.list();
It's just a tad more verbose. |