mapping select results to a map using pk->object

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

mapping select results to a map using pk->object

Andrius Juozapaitis
Hey,

One common scenario I have in the application I am creating, is the
need to quickly access the objects from the results by their primary
key. At the moment, I achieve this by simply iterating the list with
the results (say, List<DatabaseEntity>) and creating such a map (for
example, Map<Integer, DatabaseEntity>) in my utility class. This means
additional memory and cpu cycles, not to mention code duplication. I
am pretty sure I didn't see anything like this in the mybatis code,
but just wanted to confirm that  am on the right track. Any hints
there?

regards,
Andrius
Reply | Threaded
Open this post in threaded view
|

Re: mapping select results to a map using pk->object

Larry Meadors
You could do it with a ResultHandler in a single pass.

Larry


On Mon, Sep 13, 2010 at 7:03 AM, Andrius Juozapaitis <[hidden email]> wrote:

> Hey,
>
> One common scenario I have in the application I am creating, is the
> need to quickly access the objects from the results by their primary
> key. At the moment, I achieve this by simply iterating the list with
> the results (say, List<DatabaseEntity>) and creating such a map (for
> example, Map<Integer, DatabaseEntity>) in my utility class. This means
> additional memory and cpu cycles, not to mention code duplication. I
> am pretty sure I didn't see anything like this in the mybatis code,
> but just wanted to confirm that  am on the right track. Any hints
> there?
>
> regards,
> Andrius
>