comparison flys-backend/src/main/java/de/intevation/flys/model/DGM.java @ 3820:8a75cf0841b1 pre2.7-2012-03-16

merged flys-backend/pre2.7-2012-03-16
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:59 +0200
parents 85bcf8f34abb
children 2d68969bd2dc
comparison
equal deleted inserted replaced
3818:dc18457b1cef 3820:8a75cf0841b1
1 package de.intevation.flys.model;
2
3 import java.io.Serializable;
4 import java.util.List;
5 import java.math.BigDecimal;
6
7 import javax.persistence.Column;
8 import javax.persistence.Entity;
9 import javax.persistence.Id;
10 import javax.persistence.JoinColumn;
11 import javax.persistence.OneToOne;
12 import javax.persistence.Table;
13
14 import org.hibernate.Session;
15 import org.hibernate.Query;
16
17 import de.intevation.flys.backend.SessionHolder;
18
19
20 @Entity
21 @Table(name = "dem")
22 public class DGM implements Serializable {
23
24 private Integer id;
25
26 private River river;
27
28 private BigDecimal lower;
29 private BigDecimal upper;
30
31 private String path;
32
33
34 public DGM() {
35 }
36
37
38 public void setId(Integer id) {
39 this.id = id;
40 }
41
42 @Id
43 @Column(name = "id")
44 public Integer getId() {
45 return id;
46 }
47
48 public void setRiver(River river) {
49 this.river = river;
50 }
51
52 @OneToOne
53 @JoinColumn(name = "river_id")
54 public River getRiver() {
55 return river;
56 }
57
58 public void setLower(BigDecimal lower) {
59 this.lower = lower;
60 }
61
62 @Column(name = "lower")
63 public BigDecimal getLower() {
64 return lower;
65 }
66
67 public void setUpper(BigDecimal upper) {
68 this.upper = upper;
69 }
70
71 @Column(name = "upper")
72 public BigDecimal getUpper() {
73 return upper;
74 }
75
76 public void setPath(String path) {
77 this.path = path;
78 }
79
80 @Column(name = "path")
81 public String getPath() {
82 return path;
83 }
84
85
86 public static DGM getDGM(int id) {
87 Session session = SessionHolder.HOLDER.get();
88
89 Query query = session.createQuery(
90 "from DGM where Id =:id");
91 query.setParameter("id", id);
92
93 List<DGM> result = query.list();
94
95 return result.isEmpty() ? null : result.get(0);
96 }
97
98
99 public static DGM getDGM(String river, double lower, double upper) {
100 Session session = SessionHolder.HOLDER.get();
101
102 Query query = session.createQuery(
103 "from DGM where river.name =:river and " +
104 "lower <=:lower and upper >=:lower and " +
105 "lower <=:upper and upper >=:upper");
106 query.setParameter("river", river);
107 query.setParameter("lower", new BigDecimal(lower));
108 query.setParameter("upper", new BigDecimal(upper));
109
110 List<DGM> result = query.list();
111
112 return result.isEmpty() ? null : result.get(0);
113 }
114 }
115 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org