comparison flys-backend/src/main/java/de/intevation/flys/model/RiverAxis.java @ 3962:d609fd83310a

merged flys-backend
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:15:04 +0200
parents 6b1ca6ec4e3c
children b195fede1c3b
comparison
equal deleted inserted replaced
3938:c0cab28ba1ea 3962:d609fd83310a
1 package de.intevation.flys.model;
2
3 import java.io.Serializable;
4 import java.util.List;
5
6 import javax.persistence.Column;
7 import javax.persistence.Entity;
8 import javax.persistence.Id;
9 import javax.persistence.JoinColumn;
10 import javax.persistence.OneToOne;
11 import javax.persistence.Table;
12
13 import org.hibernate.Session;
14 import org.hibernate.Query;
15 import org.hibernate.annotations.Type;
16
17 import com.vividsolutions.jts.geom.LineString;
18
19 import de.intevation.flys.backend.SessionHolder;
20
21
22 /**
23 * There is a modeling problem with the RiverAxis. The initial idea was, that a
24 * river can have a riveraxis that consist of exact one geometry. Now, it has
25 * turned out, that a single geometry is not enough for a riveraxis (arm of a
26 * river, inflows, ...). As workaround, we now expect, that a river can just
27 * have a single riveraxis.
28 */
29 @Entity
30 @Table(name = "river_axes")
31 public class RiverAxis
32 implements Serializable
33 {
34 private Integer id;
35 private Integer kind;
36 private River river;
37 private LineString geom;
38
39 public static final int DEFAULT_KIND = 0;
40
41 public static final int KIND_OFFICIAL = 1;
42 public static final int KIND_OUTSOURCED = 2;
43
44 public RiverAxis() {
45 }
46
47
48 @Id
49 @Column(name = "id")
50 public Integer getId() {
51 return id;
52 }
53
54
55 public void setId(Integer id) {
56 this.id = id;
57 }
58
59
60 @OneToOne
61 @JoinColumn(name = "river_id")
62 public River getRiver() {
63 return river;
64 }
65
66
67 public void setRiver(River river) {
68 this.river = river;
69 }
70
71
72 @Column(name = "kind")
73 public Integer getKind() {
74 return kind;
75 }
76
77
78 public void setKind(Integer kind) {
79 this.kind = kind;
80 }
81
82
83 @Column(name = "geom")
84 @Type(type = "org.hibernatespatial.GeometryUserType")
85 public LineString getGeom() {
86 return geom;
87 }
88
89
90 public void setGeom(LineString geom) {
91 this.geom = geom;
92 }
93
94
95 public static List<RiverAxis> getRiverAxis(String river) {
96 return getRiverAxis(river, DEFAULT_KIND);
97 }
98
99 public static List<RiverAxis> getRiverAxis(String river, int kind) {
100 Session session = SessionHolder.HOLDER.get();
101
102 Query query = session.createQuery(
103 "from RiverAxis where river.name =:river AND kind =:kind");
104 query.setParameter("river", river);
105 query.setParameter("kind", kind);
106
107 List<RiverAxis> list = query.list();
108
109 return list.isEmpty() ? null : list;
110 }
111 }
112 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org