There are often times when I have need for a RowCallbackHandler, because in processing the result set I don’t map each row to a single type, nor each result set to a single data structure. Instead, I may map the majority rows to a specific Java bean, and add the remainder to a list for post-processing.
In these cases, I need a callback with return type void, and the only callback which satisfies this is RowCallbackHandler.
But I don’t come across many examples of this, and I have to admit, it’s aesthetically nicer to use JDBC and loop through a ResultSet, than to use the clunky Spring callbacks. Is RowCallbackHandler more common than I think? I’m curious what people have to say…
Edit: Some people have asked for my data model. Okay, there’s a
table and an
table. If there’s an edge between nodes A and B, that edge can signify two things:
- A and B are disjoint nodes that interact
- A is a member of B, or vice versa
In the second case, I need to add these group nodes to a list. They can’t be mapped to a Java bean yet, because they don’t signify interactions between disjoint nodes.
Perhaps what I should be doing, instead, is to have 2 queries, one that retrieves case (1), another that retrieves case (2). Case (1) could be mapped to a Java bean, case (2) to a List.
If this is indeed better, then maybe
is a bad code smell?