annotate flys-backend/src/main/java/de/intevation/flys/model/DGM.java @ 5091:e836b2bd683e dami

Add imports required for getLines method
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 25 Feb 2013 12:21:57 +0100
parents 2d68969bd2dc
children a2600507761e
rev   line source
1236
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.model;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
3 import java.io.Serializable;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
4 import java.util.List;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
5 import java.math.BigDecimal;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
6
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
7 import javax.persistence.Column;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
8 import javax.persistence.Entity;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9 import javax.persistence.Id;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10 import javax.persistence.JoinColumn;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 import javax.persistence.OneToOne;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12 import javax.persistence.Table;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14 import org.hibernate.Session;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 import org.hibernate.Query;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17 import de.intevation.flys.backend.SessionHolder;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20 @Entity
1240
2ef8b67bd68a Replaced SERIALs with SEQUENCES in PostgreSQL spatial schema.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1236
diff changeset
21 @Table(name = "dem")
1236
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 public class DGM implements Serializable {
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24 private Integer id;
5059
2d68969bd2dc Add srid column to dem model
Andre Heinecke <aheinecke@intevation.de>
parents: 1257
diff changeset
25 private Integer srid;
1236
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27 private River river;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29 private BigDecimal lower;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30 private BigDecimal upper;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32 private String path;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 public DGM() {
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36 }
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39 public void setId(Integer id) {
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 this.id = id;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41 }
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43 @Id
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44 @Column(name = "id")
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45 public Integer getId() {
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46 return id;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47 }
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49 public void setRiver(River river) {
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50 this.river = river;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 }
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53 @OneToOne
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54 @JoinColumn(name = "river_id")
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55 public River getRiver() {
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56 return river;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57 }
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59 public void setLower(BigDecimal lower) {
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60 this.lower = lower;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61 }
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63 @Column(name = "lower")
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 public BigDecimal getLower() {
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65 return lower;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66 }
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68 public void setUpper(BigDecimal upper) {
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69 this.upper = upper;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70 }
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72 @Column(name = "upper")
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73 public BigDecimal getUpper() {
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74 return upper;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 }
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
77 public void setPath(String path) {
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78 this.path = path;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79 }
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
80
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
81 @Column(name = "path")
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82 public String getPath() {
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83 return path;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
84 }
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85
5059
2d68969bd2dc Add srid column to dem model
Andre Heinecke <aheinecke@intevation.de>
parents: 1257
diff changeset
86 public void setSrid(int srid) {
2d68969bd2dc Add srid column to dem model
Andre Heinecke <aheinecke@intevation.de>
parents: 1257
diff changeset
87 this.srid = srid;
2d68969bd2dc Add srid column to dem model
Andre Heinecke <aheinecke@intevation.de>
parents: 1257
diff changeset
88 }
2d68969bd2dc Add srid column to dem model
Andre Heinecke <aheinecke@intevation.de>
parents: 1257
diff changeset
89
2d68969bd2dc Add srid column to dem model
Andre Heinecke <aheinecke@intevation.de>
parents: 1257
diff changeset
90 @Column(name = "srid")
2d68969bd2dc Add srid column to dem model
Andre Heinecke <aheinecke@intevation.de>
parents: 1257
diff changeset
91 public int getSrid() {
2d68969bd2dc Add srid column to dem model
Andre Heinecke <aheinecke@intevation.de>
parents: 1257
diff changeset
92 return srid;
2d68969bd2dc Add srid column to dem model
Andre Heinecke <aheinecke@intevation.de>
parents: 1257
diff changeset
93 }
1236
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
94
1257
85bcf8f34abb Added a function to query a DGM by Id.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1240
diff changeset
95 public static DGM getDGM(int id) {
85bcf8f34abb Added a function to query a DGM by Id.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1240
diff changeset
96 Session session = SessionHolder.HOLDER.get();
85bcf8f34abb Added a function to query a DGM by Id.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1240
diff changeset
97
85bcf8f34abb Added a function to query a DGM by Id.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1240
diff changeset
98 Query query = session.createQuery(
85bcf8f34abb Added a function to query a DGM by Id.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1240
diff changeset
99 "from DGM where Id =:id");
85bcf8f34abb Added a function to query a DGM by Id.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1240
diff changeset
100 query.setParameter("id", id);
85bcf8f34abb Added a function to query a DGM by Id.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1240
diff changeset
101
85bcf8f34abb Added a function to query a DGM by Id.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1240
diff changeset
102 List<DGM> result = query.list();
85bcf8f34abb Added a function to query a DGM by Id.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1240
diff changeset
103
85bcf8f34abb Added a function to query a DGM by Id.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1240
diff changeset
104 return result.isEmpty() ? null : result.get(0);
85bcf8f34abb Added a function to query a DGM by Id.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1240
diff changeset
105 }
85bcf8f34abb Added a function to query a DGM by Id.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1240
diff changeset
106
85bcf8f34abb Added a function to query a DGM by Id.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1240
diff changeset
107
1236
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
108 public static DGM getDGM(String river, double lower, double upper) {
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
109 Session session = SessionHolder.HOLDER.get();
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
110
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111 Query query = session.createQuery(
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
112 "from DGM where river.name =:river and " +
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
113 "lower <=:lower and upper >=:lower and " +
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
114 "lower <=:upper and upper >=:upper");
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
115 query.setParameter("river", river);
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
116 query.setParameter("lower", new BigDecimal(lower));
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
117 query.setParameter("upper", new BigDecimal(upper));
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
118
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
119 List<DGM> result = query.list();
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
120
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
121 return result.isEmpty() ? null : result.get(0);
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
122 }
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
123 }
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
124 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org