diff flys-backend/src/main/java/de/intevation/flys/model/BedHeightType.java @ 5273:db196abd16ca

Use lookup table from bedd_height from database in importer.
author Sascha L. Teichmann <teichmann@intevation.de>
date Wed, 13 Mar 2013 16:39:08 +0100
parents 3de4ac5ccee8
children 3ddf5843ede3
line wrap: on
line diff
--- a/flys-backend/src/main/java/de/intevation/flys/model/BedHeightType.java	Wed Mar 13 10:06:26 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/model/BedHeightType.java	Wed Mar 13 16:39:08 2013 +0100
@@ -2,6 +2,8 @@
 
 import java.io.Serializable;
 
+import java.util.List;
+
 import javax.persistence.Entity;
 import javax.persistence.Id;
 import javax.persistence.Table;
@@ -12,6 +14,10 @@
 
 import org.apache.log4j.Logger;
 
+import org.hibernate.Query;
+import org.hibernate.Session;
+
+import de.intevation.flys.backend.SessionHolder;
 
 @Entity
 @Table(name = "bed_height_type")
@@ -22,15 +28,13 @@
 
     private Integer id;
     private String  name;
-    private String  description;
 
 
     public BedHeightType() {
     }
 
-    public BedHeightType(String name, String description) {
-        this.name        = name;
-        this.description = description;
+    public BedHeightType(String name) {
+        this.name = name;
     }
 
     @Id
@@ -59,36 +63,17 @@
         this.name = name;
     }
 
-    @Column(name = "description")
-    public String getDescription() {
-        return description;
-    }
-
-    public void setDescription(String description) {
-        this.description = description;
-    }
-
 
-    public static String getBedHeightName(String description) {
-        if (description.equals("Flächenpeilung")) {
-            return "FP";
-        }
-        else if ("Querprofile".equals(description)) {
-            return "QP";
-        }
-        else if ("Querprofil".equals(description)) {
-            return "QP";
-        }
-        else if ("TIN".equals(description)) {
-            return "TIN";
-        }
-        else if ("Flächen- u. Querprofilpeilungen".equals(description)) {
-            return "FP-QP";
-        }
-        else {
-            log.warn("Unknown bed height type: " + description);
-            return null;
-        }
+    public static BedHeightType fetchBedHeightTypeForType(String type) {
+        Session session = SessionHolder.HOLDER.get();
+        Query query = session.createQuery(
+            "from BedHeightType where type=:type");
+
+        query.setParameter("type", type);
+
+        List<Object> results = query.list();
+
+        return results.isEmpty() ? null : (BedHeightType)results.get(0);
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org