comparison 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
comparison
equal deleted inserted replaced
5264:731030b69c7e 5273:db196abd16ca
1 package de.intevation.flys.model; 1 package de.intevation.flys.model;
2 2
3 import java.io.Serializable; 3 import java.io.Serializable;
4
5 import java.util.List;
4 6
5 import javax.persistence.Entity; 7 import javax.persistence.Entity;
6 import javax.persistence.Id; 8 import javax.persistence.Id;
7 import javax.persistence.Table; 9 import javax.persistence.Table;
8 import javax.persistence.GeneratedValue; 10 import javax.persistence.GeneratedValue;
10 import javax.persistence.SequenceGenerator; 12 import javax.persistence.SequenceGenerator;
11 import javax.persistence.GenerationType; 13 import javax.persistence.GenerationType;
12 14
13 import org.apache.log4j.Logger; 15 import org.apache.log4j.Logger;
14 16
17 import org.hibernate.Query;
18 import org.hibernate.Session;
19
20 import de.intevation.flys.backend.SessionHolder;
15 21
16 @Entity 22 @Entity
17 @Table(name = "bed_height_type") 23 @Table(name = "bed_height_type")
18 public class BedHeightType 24 public class BedHeightType
19 implements Serializable 25 implements Serializable
20 { 26 {
21 private static Logger log = Logger.getLogger(BedHeightType.class); 27 private static Logger log = Logger.getLogger(BedHeightType.class);
22 28
23 private Integer id; 29 private Integer id;
24 private String name; 30 private String name;
25 private String description;
26 31
27 32
28 public BedHeightType() { 33 public BedHeightType() {
29 } 34 }
30 35
31 public BedHeightType(String name, String description) { 36 public BedHeightType(String name) {
32 this.name = name; 37 this.name = name;
33 this.description = description;
34 } 38 }
35 39
36 @Id 40 @Id
37 @SequenceGenerator( 41 @SequenceGenerator(
38 name = "SEQUENCE_BED_HEIGHT_TYPE_ID_SEQ", 42 name = "SEQUENCE_BED_HEIGHT_TYPE_ID_SEQ",
57 61
58 public void setName(String name) { 62 public void setName(String name) {
59 this.name = name; 63 this.name = name;
60 } 64 }
61 65
62 @Column(name = "description")
63 public String getDescription() {
64 return description;
65 }
66 66
67 public void setDescription(String description) { 67 public static BedHeightType fetchBedHeightTypeForType(String type) {
68 this.description = description; 68 Session session = SessionHolder.HOLDER.get();
69 } 69 Query query = session.createQuery(
70 "from BedHeightType where type=:type");
70 71
72 query.setParameter("type", type);
71 73
72 public static String getBedHeightName(String description) { 74 List<Object> results = query.list();
73 if (description.equals("Flächenpeilung")) { 75
74 return "FP"; 76 return results.isEmpty() ? null : (BedHeightType)results.get(0);
75 }
76 else if ("Querprofile".equals(description)) {
77 return "QP";
78 }
79 else if ("Querprofil".equals(description)) {
80 return "QP";
81 }
82 else if ("TIN".equals(description)) {
83 return "TIN";
84 }
85 else if ("Flächen- u. Querprofilpeilungen".equals(description)) {
86 return "FP-QP";
87 }
88 else {
89 log.warn("Unknown bed height type: " + description);
90 return null;
91 }
92 } 77 }
93 } 78 }
94 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 79 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org