[Dive4elements-commits] [PATCH 2 of 3] correct session-handling for bed height import (made by S. Teichmann)

Wald Commits scm-commit at wald.intevation.org
Wed Mar 13 19:08:25 CET 2013


# HG changeset patch
# User Tom Gottfried <tom.gottfried at intevation.de>
# Date 1363197222 -3600
# Node ID 3ddf5843ede38008a943a1bf71b7ca8a97f39d7a
# Parent  170f514a4f290cc1d30d6918dc2821e2148255c9
correct session-handling for bed height import (made by S. Teichmann)

diff -r 170f514a4f29 -r 3ddf5843ede3 flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightParser.java
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightParser.java	Wed Mar 13 18:39:28 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightParser.java	Wed Mar 13 18:53:42 2013 +0100
@@ -31,7 +31,7 @@
 import de.intevation.flys.importer.ImportTimeInterval;
 import de.intevation.flys.importer.ImportUnit;
 import de.intevation.flys.model.BedHeightType;
-
+import de.intevation.flys.importer.ImporterSession;
 
 public abstract class BedHeightParser {
 
@@ -331,7 +331,8 @@
         if (m.matches()) {
             String tmp = m.group(1).replace(";", "");
 
-            BedHeightType bht = BedHeightType.fetchBedHeightTypeForType(tmp);
+            BedHeightType bht = BedHeightType.fetchBedHeightTypeForType(
+		tmp, ImporterSession.getInstance().getDatabaseSession());
 
             if (bht != null) {
                 obj.setType(new ImportBedHeightType(bht));
diff -r 170f514a4f29 -r 3ddf5843ede3 flys-backend/src/main/java/de/intevation/flys/model/BedHeightType.java
--- a/flys-backend/src/main/java/de/intevation/flys/model/BedHeightType.java	Wed Mar 13 18:39:28 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/model/BedHeightType.java	Wed Mar 13 18:53:42 2013 +0100
@@ -63,13 +63,20 @@
         this.name = name;
     }
 
+    public static BedHeightType fetchBedHeightTypeForType(String type) {
+	return fetchBedHeightTypeForType(type, null);
+    }
 
-    public static BedHeightType fetchBedHeightTypeForType(String type) {
-        Session session = SessionHolder.HOLDER.get();
+    public static BedHeightType fetchBedHeightTypeForType(String name, Session session) {
+
+	if (session == null) {
+	    session = SessionHolder.HOLDER.get();
+	}
+
         Query query = session.createQuery(
-            "from BedHeightType where type=:type");
+            "from BedHeightType where name=:name");
 
-        query.setParameter("type", type);
+        query.setParameter("name", name);
 
         List<Object> results = query.list();
 


More information about the Dive4elements-commits mailing list