Mercurial > dive4elements > river
annotate flys-backend/src/main/java/de/intevation/flys/importer/ImportPosition.java @ 2347:0acf28a3d28a
Removed the Unit from Wsts - added a WstUnit column to rivers.
flys-backend/trunk@2884 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 04 Oct 2011 15:28:19 +0000 |
parents | 67fd63e4ef66 |
children |
rev | line source |
---|---|
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.importer; |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
187
ecf90018563b
Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
3 import de.intevation.flys.model.Position; |
ecf90018563b
Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
4 |
ecf90018563b
Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
5 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
|
6 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
|
7 |
ecf90018563b
Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
8 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
|
9 |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 public class ImportPosition |
186
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
11 implements Comparable<ImportPosition> |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 { |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 protected String value; |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 |
187
ecf90018563b
Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
15 protected Position peer; |
ecf90018563b
Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
16 |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 public ImportPosition() { |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 } |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 public ImportPosition(String value) { |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 this.value = value; |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 } |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 |
186
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
24 public int compareTo(ImportPosition other) { |
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
25 return value.compareTo(other.value); |
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
26 } |
cf8cbcb6a10d
Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
185
diff
changeset
|
27 |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 public String getValue() { |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 return 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 |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 public void setValue(String value) { |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 this.value = value; |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 } |
187
ecf90018563b
Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
35 |
ecf90018563b
Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
36 public Position getPeer() { |
188
003ac16812dd
Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
187
diff
changeset
|
37 if (peer == null) { |
497
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
188
diff
changeset
|
38 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
|
39 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
|
40 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
|
41 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
|
42 if (positions.isEmpty()) { |
ecf90018563b
Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
43 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
|
44 session.save(peer); |
ecf90018563b
Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
45 } |
ecf90018563b
Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
46 else { |
ecf90018563b
Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
47 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
|
48 } |
ecf90018563b
Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
49 } |
ecf90018563b
Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
50 return peer; |
ecf90018563b
Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
186
diff
changeset
|
51 } |
185
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 } |
a60edcfe5f53
Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 // 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
|
54 |