comparison flys-backend/src/main/java/de/intevation/flys/model/DischargeZone.java @ 2877:f0a67bc0e777 2.7

merged flys-backend/2.7
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:31 +0200
parents 5a89c2b05e6d
children cc6323401643
comparison
equal deleted inserted replaced
2793:6310b1582f2d 2877:f0a67bc0e777
1 package de.intevation.flys.model;
2
3 import java.io.Serializable;
4 import java.math.BigDecimal;
5 import java.util.List;
6
7 import javax.persistence.Entity;
8 import javax.persistence.Id;
9 import javax.persistence.Table;
10 import javax.persistence.GeneratedValue;
11 import javax.persistence.Column;
12 import javax.persistence.SequenceGenerator;
13 import javax.persistence.GenerationType;
14 import javax.persistence.JoinColumn;
15 import javax.persistence.OneToOne;
16
17 import org.hibernate.Session;
18 import org.hibernate.Query;
19
20 import org.apache.log4j.Logger;
21
22 import de.intevation.flys.backend.SessionHolder;
23
24
25 @Entity
26 @Table(name = "discharge_zone")
27 public class DischargeZone
28 implements Serializable
29 {
30 private static Logger logger = Logger.getLogger(DischargeZone.class);
31
32
33 private Integer id;
34
35 private River river;
36
37 private String gaugeName;
38
39 private BigDecimal value;
40
41 private String lowerDischarge;
42 private String upperDischarge;
43
44
45 public DischargeZone() {
46 }
47
48
49 public DischargeZone(
50 River river,
51 String gaugeName,
52 BigDecimal value,
53 String lowerDischarge,
54 String upperDischarge
55 ) {
56 this.river = river;
57 this.gaugeName = gaugeName;
58 this.value = value;
59 this.lowerDischarge = lowerDischarge;
60 this.upperDischarge = upperDischarge;
61 }
62
63 @Id
64 @SequenceGenerator(
65 name = "SEQUENCE_DISCHARGE_ZONE_ID_SEQ",
66 sequenceName = "DISCHARGE_ZONE_ID_SEQ",
67 allocationSize = 1)
68 @GeneratedValue(
69 strategy = GenerationType.SEQUENCE,
70 generator = "SEQUENCE_DISCHARGE_ZONE_ID_SEQ")
71 @Column(name = "id")
72 public Integer getId() {
73 return id;
74 }
75
76 public void setId(Integer id) {
77 this.id = id;
78 }
79
80 @OneToOne
81 @JoinColumn(name = "river_id" )
82 public River getRiver() {
83 return river;
84 }
85
86 public void setRiver(River river) {
87 this.river = river;
88 }
89
90 @Column(name = "value")
91 public BigDecimal getValue() {
92 return value;
93 }
94
95 public void setValue(BigDecimal value) {
96 this.value = value;
97 }
98
99 @Column(name = "gauge_name")
100 public String getGaugeName() {
101 return gaugeName;
102 }
103
104 public void setGaugeName(String gaugeName) {
105 this.gaugeName = gaugeName;
106 }
107
108 @Column(name = "lower_discharge")
109 public String getLowerDischarge() {
110 return lowerDischarge;
111 }
112
113 public void setLowerDischarge(String lowerDischarge) {
114 this.lowerDischarge = lowerDischarge;
115 }
116
117 @Column(name = "upper_discharge")
118 public String getUpperDischarge() {
119 return upperDischarge;
120 }
121
122 public void setUpperDischarge(String upperDischarge) {
123 this.upperDischarge = upperDischarge;
124 }
125
126
127 public static List<DischargeZone> getDischargeZones(River river) {
128 Session session = SessionHolder.HOLDER.get();
129
130 Query query = session.createQuery(
131 "from DischargeZone where river=:river");
132
133 query.setParameter("river", river);
134
135 return query.list();
136 }
137
138
139 public static DischargeZone getDischargeZoneById(int id) {
140 Session session = SessionHolder.HOLDER.get();
141
142 Query query = session.createQuery(
143 "from DischargeZone where id=:id");
144
145 query.setParameter("id", id);
146
147 List<DischargeZone> zones = query.list();
148
149 return zones.isEmpty() ? null : zones.get(0);
150 }
151 }
152 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org