comparison flys-backend/src/main/java/de/intevation/flys/model/CrossSectionTrack.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 8e2fe935ddf1
children d42249d91f47
comparison
equal deleted inserted replaced
3818:dc18457b1cef 3820:8a75cf0841b1
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.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.Query;
15 import org.hibernate.Session;
16 import org.hibernate.annotations.Type;
17
18 import com.vividsolutions.jts.geom.LineString;
19
20 import de.intevation.flys.backend.SessionHolder;
21
22
23 @Entity
24 @Table(name = "cross_section_tracks")
25 public class CrossSectionTrack
26 implements Serializable
27 {
28 private Integer id;
29 private River river;
30 private LineString geom;
31 private BigDecimal km;
32 private BigDecimal z;
33
34 public CrossSectionTrack() {
35 }
36
37
38 @Id
39 @Column(name = "id")
40 public Integer getId() {
41 return id;
42 }
43
44
45 public void setId(Integer id) {
46 this.id = id;
47 }
48
49
50 @OneToOne
51 @JoinColumn(name = "river_id")
52 public River getRiver() {
53 return river;
54 }
55
56
57 public void setRiver(River river) {
58 this.river = river;
59 }
60
61
62 @Column(name = "geom")
63 @Type(type = "org.hibernatespatial.GeometryUserType")
64 public LineString getGeom() {
65 return geom;
66 }
67
68
69 public void setGeom(LineString geom) {
70 this.geom = geom;
71 }
72
73
74 @Column(name = "km")
75 public BigDecimal getKm() {
76 return km;
77 }
78
79
80 public void setKm(BigDecimal km) {
81 this.km = km;
82 }
83
84
85 @Column(name = "z")
86 public BigDecimal getZ() {
87 return z;
88 }
89
90
91 public void setZ(BigDecimal z) {
92 this.z = z;
93 }
94
95
96 public static List<CrossSectionTrack> getCrossSectionTrack(
97 String river)
98 {
99 Session session = SessionHolder.HOLDER.get();
100
101 Query query = session.createQuery(
102 "from CrossSectionTrack where river.name =:river");
103 query.setParameter("river", river);
104
105 return query.list();
106 }
107
108
109 /**
110 * Returns the nearest CrossSectionTrack of <i>river</i> to a given
111 * <i>km</i>.
112 *
113 * @param river The name of a river.
114 * @param km The kilometer value.
115 *
116 * @return the nearest CrossSectionTrack to <i>km</i> of river <i>river</i>.
117 */
118 public static CrossSectionTrack getCrossSectionTrack(
119 String river,
120 double km
121 ) {
122 Session session = SessionHolder.HOLDER.get();
123
124 Query query = session.createQuery(
125 "from CrossSectionTrack where river.name =:river " +
126 "order by abs( km - :mykm)");
127 query.setParameter("river", river);
128 query.setParameter("mykm", new BigDecimal(km));
129
130 List<CrossSectionTrack> cst = query.list();
131
132 return cst != null && !cst.isEmpty() ? cst.get(0) : null;
133 }
134 }
135 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org