Mercurial > dive4elements > river
annotate flys-backend/src/main/java/de/intevation/hibernate/MapResultTransformer.java @ 3341:51f037483071
Backend: Strategy to directly transform native SQL results into Maps.
flys-backend/trunk@4955 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 12 Jul 2012 14:51:23 +0000 |
parents | |
children | 3d3e40d9d6d7 |
rev | line source |
---|---|
3341
51f037483071
Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.hibernate; |
51f037483071
Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
51f037483071
Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import java.util.HashMap; |
51f037483071
Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 import java.util.Map; |
51f037483071
Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 |
51f037483071
Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 import org.hibernate.transform.BasicTransformerAdapter; |
51f037483071
Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 |
51f037483071
Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 public class MapResultTransformer |
51f037483071
Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 extends BasicTransformerAdapter |
51f037483071
Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 { |
51f037483071
Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 public MapResultTransformer() { |
51f037483071
Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 } |
51f037483071
Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 |
51f037483071
Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 @Override |
51f037483071
Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 public Object transformTuple(Object [] tuple, String [] aliases) { |
51f037483071
Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 Map<String, Object> map = new HashMap<String, Object>(); |
51f037483071
Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 for (int i = 0; i < tuple.length; ++i) { |
51f037483071
Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 map.put(aliases[i], tuple[i]); |
51f037483071
Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 } |
51f037483071
Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 return map; |
51f037483071
Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 } |
51f037483071
Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 } |
51f037483071
Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |