annotate backend/src/main/java/org/dive4elements/river/importer/ImportAttribute.java @ 5838:5aa05a7a34b7

Rename modules to more fitting names.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 15:23:37 +0200
parents flys-backend/src/main/java/org/dive4elements/river/importer/ImportAttribute.java@18619c1e7c2a
children 4dd33b86dc61
rev   line source
5829
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
1 package org.dive4elements.river.importer;
185
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
5829
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
3 import org.dive4elements.river.model.Attribute;
187
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 ImportAttribute
186
cf8cbcb6a10d Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 185
diff changeset
11 implements Comparable<ImportAttribute>
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 Attribute 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 ImportAttribute() {
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
186
cf8cbcb6a10d Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 185
diff changeset
20 public ImportAttribute(String value) {
cf8cbcb6a10d Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 185
diff changeset
21 this.value = value;
cf8cbcb6a10d Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 185
diff changeset
22 }
cf8cbcb6a10d Added parser to read *.KM files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 185
diff changeset
23
185
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 public String getValue() {
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 return value;
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 void setValue(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(ImportAttribute 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 @Override
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 public boolean equals(Object other) {
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 if (other == this) return true;
189
bc3747a371cc First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 188
diff changeset
39 if (!(other instanceof ImportAttribute)) return false;
bc3747a371cc First part of parsing main values.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 188
diff changeset
40 return value.equals(((ImportAttribute)other).value);
185
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 }
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 @Override
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 public int hashCode() {
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 return value.hashCode();
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 }
187
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
47
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
48 public Attribute getPeer() {
188
003ac16812dd Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 187
diff changeset
49 if (peer == null) {
497
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 189
diff changeset
50 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
51 Query query = session.createQuery("from Attribute where value=:value");
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
52 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
53 List<Attribute> attributes = query.list();
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
54 if (attributes.isEmpty()) {
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
55 peer = new Attribute(value);
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
56 session.save(peer);
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 else {
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
59 peer = attributes.get(0);
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
60 }
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
61 }
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
62 return peer;
ecf90018563b Importer: Bound Attributes and Positions to there backend peers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 186
diff changeset
63 }
185
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64 }
a60edcfe5f53 Added new helper models for import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org