annotate flys-backend/src/main/java/de/intevation/flys/model/DGM.java @ 5136:ec3430d12d2e

merged.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 28 Feb 2013 12:48:27 +0100
parents a2600507761e
children 908848b74d7e
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;
5098
a2600507761e Add sequences to the new tables that use sequences
Andre Heinecke <aheinecke@intevation.de>
parents: 5059
diff changeset
9 import javax.persistence.GeneratedValue;
a2600507761e Add sequences to the new tables that use sequences
Andre Heinecke <aheinecke@intevation.de>
parents: 5059
diff changeset
10 import javax.persistence.GenerationType;
1236
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 import javax.persistence.Id;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12 import javax.persistence.JoinColumn;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13 import javax.persistence.OneToOne;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14 import javax.persistence.Table;
5098
a2600507761e Add sequences to the new tables that use sequences
Andre Heinecke <aheinecke@intevation.de>
parents: 5059
diff changeset
15 import javax.persistence.SequenceGenerator;
1236
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 org.hibernate.Session;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18 import org.hibernate.Query;
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 import de.intevation.flys.backend.SessionHolder;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23 @Entity
1240
2ef8b67bd68a Replaced SERIALs with SEQUENCES in PostgreSQL spatial schema.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1236
diff changeset
24 @Table(name = "dem")
1236
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 public class DGM implements Serializable {
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 Integer id;
5059
2d68969bd2dc Add srid column to dem model
Andre Heinecke <aheinecke@intevation.de>
parents: 1257
diff changeset
28 private Integer srid;
1236
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30 private River river;
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 BigDecimal lower;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33 private BigDecimal upper;
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 private String path;
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 public DGM() {
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39 }
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40
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 public void setId(Integer id) {
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43 this.id = id;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44 }
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46 @Id
5098
a2600507761e Add sequences to the new tables that use sequences
Andre Heinecke <aheinecke@intevation.de>
parents: 5059
diff changeset
47 @SequenceGenerator(
a2600507761e Add sequences to the new tables that use sequences
Andre Heinecke <aheinecke@intevation.de>
parents: 5059
diff changeset
48 name = "SEQUENCE_DEM_ID_SEQ",
a2600507761e Add sequences to the new tables that use sequences
Andre Heinecke <aheinecke@intevation.de>
parents: 5059
diff changeset
49 sequenceName = "DEM_ID_SEQ",
a2600507761e Add sequences to the new tables that use sequences
Andre Heinecke <aheinecke@intevation.de>
parents: 5059
diff changeset
50 allocationSize = 1)
a2600507761e Add sequences to the new tables that use sequences
Andre Heinecke <aheinecke@intevation.de>
parents: 5059
diff changeset
51 @GeneratedValue(
a2600507761e Add sequences to the new tables that use sequences
Andre Heinecke <aheinecke@intevation.de>
parents: 5059
diff changeset
52 strategy = GenerationType.SEQUENCE,
a2600507761e Add sequences to the new tables that use sequences
Andre Heinecke <aheinecke@intevation.de>
parents: 5059
diff changeset
53 generator = "SEQUENCE_DEM_ID_SEQ")
1236
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54 @Column(name = "id")
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55 public Integer getId() {
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56 return id;
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 setRiver(River river) {
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60 this.river = river;
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 @OneToOne
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 @JoinColumn(name = "river_id")
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65 public River getRiver() {
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66 return river;
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
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69 public void setLower(BigDecimal lower) {
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70 this.lower = lower;
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
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73 @Column(name = "lower")
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74 public BigDecimal getLower() {
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 return lower;
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
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78 public void setUpper(BigDecimal upper) {
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79 this.upper = upper;
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
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82 @Column(name = "upper")
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83 public BigDecimal getUpper() {
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
84 return upper;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85 }
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
86
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
87 public void setPath(String path) {
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
88 this.path = path;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
89 }
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
90
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91 @Column(name = "path")
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92 public String getPath() {
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
93 return path;
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
94 }
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95
5059
2d68969bd2dc Add srid column to dem model
Andre Heinecke <aheinecke@intevation.de>
parents: 1257
diff changeset
96 public void setSrid(int srid) {
2d68969bd2dc Add srid column to dem model
Andre Heinecke <aheinecke@intevation.de>
parents: 1257
diff changeset
97 this.srid = srid;
2d68969bd2dc Add srid column to dem model
Andre Heinecke <aheinecke@intevation.de>
parents: 1257
diff changeset
98 }
2d68969bd2dc Add srid column to dem model
Andre Heinecke <aheinecke@intevation.de>
parents: 1257
diff changeset
99
2d68969bd2dc Add srid column to dem model
Andre Heinecke <aheinecke@intevation.de>
parents: 1257
diff changeset
100 @Column(name = "srid")
2d68969bd2dc Add srid column to dem model
Andre Heinecke <aheinecke@intevation.de>
parents: 1257
diff changeset
101 public int getSrid() {
2d68969bd2dc Add srid column to dem model
Andre Heinecke <aheinecke@intevation.de>
parents: 1257
diff changeset
102 return srid;
2d68969bd2dc Add srid column to dem model
Andre Heinecke <aheinecke@intevation.de>
parents: 1257
diff changeset
103 }
1236
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
104
1257
85bcf8f34abb Added a function to query a DGM by Id.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1240
diff changeset
105 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
106 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
107
85bcf8f34abb Added a function to query a DGM by Id.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1240
diff changeset
108 Query query = session.createQuery(
85bcf8f34abb Added a function to query a DGM by Id.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1240
diff changeset
109 "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
110 query.setParameter("id", id);
85bcf8f34abb Added a function to query a DGM by Id.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1240
diff changeset
111
85bcf8f34abb Added a function to query a DGM by Id.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1240
diff changeset
112 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
113
85bcf8f34abb Added a function to query a DGM by Id.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1240
diff changeset
114 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
115 }
85bcf8f34abb Added a function to query a DGM by Id.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1240
diff changeset
116
85bcf8f34abb Added a function to query a DGM by Id.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1240
diff changeset
117
1236
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
118 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
119 Session session = SessionHolder.HOLDER.get();
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 Query query = session.createQuery(
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
122 "from DGM where river.name =:river and " +
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
123 "lower <=:lower and upper >=:lower and " +
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
124 "lower <=:upper and upper >=:upper");
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
125 query.setParameter("river", river);
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
126 query.setParameter("lower", new BigDecimal(lower));
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
127 query.setParameter("upper", new BigDecimal(upper));
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
128
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
129 List<DGM> result = query.list();
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
130
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
131 return result.isEmpty() ? null : result.get(0);
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
132 }
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
133 }
324cb486db9f Added relation and hibernate classes for DGMs.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
134 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org