annotate backend/src/main/java/org/dive4elements/river/importer/ImportPosition.java @ 6955:94cb1845c667

(issue1452) Coalesce to zero to avoid NaN arithmetic.
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 30 Aug 2013 15:45:14 +0200
parents 4c3ccf2b0304
children 5e38e2924c07
rev   line source
5844
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5992
4c3ccf2b0304 Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5844
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5992
4c3ccf2b0304 Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
6 * documentation coming with Dive4Elements River for details.
5844
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5829
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
9 package org.dive4elements.river.importer;
185
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10
5829
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
11 import org.dive4elements.river.model.Position;
187
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
12
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
13 import org.hibernate.Session;
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
14 import org.hibernate.Query;
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
15
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
16 import java.util.List;
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
17
185
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 public class ImportPosition
186
cf8cbcb6a10d Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 185
diff changeset
19 implements Comparable<ImportPosition>
185
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 {
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 protected String value;
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22
187
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
23 protected Position peer;
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
24
185
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 public ImportPosition() {
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 }
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 public ImportPosition(String value) {
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 this.value = value;
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 }
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31
186
cf8cbcb6a10d Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 185
diff changeset
32 public int compareTo(ImportPosition other) {
cf8cbcb6a10d Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 185
diff changeset
33 return value.compareTo(other.value);
cf8cbcb6a10d Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 185
diff changeset
34 }
cf8cbcb6a10d Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 185
diff changeset
35
185
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 public String getValue() {
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 return value;
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 }
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 public void setValue(String value) {
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 this.value = value;
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 }
187
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
43
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
44 public Position getPeer() {
188
003ac16812dd Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 187
diff changeset
45 if (peer == null) {
497
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 188
diff changeset
46 Session session = ImporterSession.getInstance().getDatabaseSession();
187
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
47 Query query = session.createQuery("from Position where value=:value");
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
48 query.setString("value", value);
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
49 List<Position> positions = query.list();
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
50 if (positions.isEmpty()) {
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
51 peer = new Position(value);
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
52 session.save(peer);
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
53 }
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
54 else {
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
55 peer = positions.get(0);
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
56 }
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
57 }
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
58 return peer;
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
59 }
185
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60 }
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62

http://dive4elements.wald.intevation.org