changeset 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 509af52db23b
children 3d3e40d9d6d7
files flys-backend/ChangeLog flys-backend/src/main/java/de/intevation/hibernate/MapResultTransformer.java
diffstat 2 files changed, 28 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/ChangeLog	Thu Jul 12 09:01:43 2012 +0000
+++ b/flys-backend/ChangeLog	Thu Jul 12 14:51:23 2012 +0000
@@ -1,3 +1,8 @@
+2012-07-12	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/hibernate/MapResultTransformer.java:
+	  Strategy to directly transform native SQL results into Maps.
+
 2012-07-11	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	Fix for flys/issue359
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-backend/src/main/java/de/intevation/hibernate/MapResultTransformer.java	Thu Jul 12 14:51:23 2012 +0000
@@ -0,0 +1,23 @@
+package de.intevation.hibernate;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.hibernate.transform.BasicTransformerAdapter;
+
+public class MapResultTransformer
+extends      BasicTransformerAdapter
+{
+    public MapResultTransformer() {
+    }
+
+    @Override
+    public Object transformTuple(Object [] tuple, String [] aliases) {
+        Map<String, Object> map = new HashMap<String, Object>();
+        for (int i = 0; i < tuple.length; ++i) {
+            map.put(aliases[i], tuple[i]);
+        }
+        return map;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org