Popularity of RowCallbackHandler with JdbcTemplate

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 nodes
table and an edges
table. If there’s an edge between nodes A and B, that edge can signify two things:

  1. A and B are disjoint nodes that interact
  2. 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 RowCallbackHandler
is a bad code smell?

Hello, buddy!稿源:Hello, buddy! (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 综合编程 » Popularity of RowCallbackHandler with JdbcTemplate

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录