annotate flys-backend/src/main/java/de/intevation/hibernate/MapResultTransformer.java @ 5509:627584bc0586

Datacage: Added <dc:filter> element. This allows cleaner way to narrow the datasets. Example: <dc:context> <dc:statement> SELECT DISTINCT name AS hws_name, official AS hws_official, kind_id AS hws_kind FROM hws_lines WHERE river_id = ${river_id} </dc:statement> <dc:if test="dc:has-result()"> <lines> <dc:macro name="hws-lines"> <dc:elements> <hws factory="hwsfactory" name="{$hws_name}"/> </dc:elements> </dc:macro> <dc:filter expr="$hws_official=1"> <dc:if test="dc:has-result()"> <official> <dc:filter expr="$hws_kind=1"> <dc:if test="dc:has-result()"> <Durchlass><dc:call-macro name="hws-lines"></Durchlass> </dc:if> </dc:filter> <dc:filter expr="$hws_kind=2"> <dc:if test="dc:has-result()"> <Damm><dc:call-macro name="hws-lines"></Damm> </dc:if> </dc:filter> <dc:filter expr="$hws_kind=3"> <dc:if test="dc:has-result()"> <Graben><dc:call-macro name="hws-lines"></Graben> </dc:if> </dc:filter> </official> </dc:if> </dc:filter> </lines> </dc:if> </dc:context>
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 28 Mar 2013 16:51:15 +0100
parents 3d3e40d9d6d7
children 18619c1e7c2a
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 {
3342
3d3e40d9d6d7 MapResultTransformer: Added static INSTANCE because its stateless.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3341
diff changeset
11 public static final MapResultTransformer INSTANCE =
3d3e40d9d6d7 MapResultTransformer: Added static INSTANCE because its stateless.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3341
diff changeset
12 new MapResultTransformer();
3d3e40d9d6d7 MapResultTransformer: Added static INSTANCE because its stateless.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3341
diff changeset
13
3341
51f037483071 Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 public MapResultTransformer() {
51f037483071 Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 }
51f037483071 Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16
51f037483071 Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 @Override
51f037483071 Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 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
19 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
20 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
21 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
22 }
51f037483071 Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 return map;
51f037483071 Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 }
51f037483071 Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 }
51f037483071 Backend: Strategy to directly transform native SQL results into Maps.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org