Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/ImportAnnotationType.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/ImportAnnotationType.java@18619c1e7c2a |
children | 4dd33b86dc61 |
comparison
equal
deleted
inserted
replaced
5837:d9901a08d0a6 | 5838:5aa05a7a34b7 |
---|---|
1 package org.dive4elements.river.importer; | |
2 | |
3 import org.dive4elements.river.model.AnnotationType; | |
4 | |
5 import org.hibernate.Session; | |
6 import org.hibernate.Query; | |
7 | |
8 import java.util.List; | |
9 | |
10 public class ImportAnnotationType | |
11 implements Comparable<ImportAnnotationType> | |
12 { | |
13 protected String name; | |
14 protected AnnotationType peer; | |
15 | |
16 public ImportAnnotationType() { | |
17 } | |
18 | |
19 public ImportAnnotationType(String name) { | |
20 this.name = name; | |
21 } | |
22 | |
23 public int compareTo(ImportAnnotationType other) { | |
24 return name.compareTo(other.name); | |
25 } | |
26 | |
27 public String getName() { | |
28 return name; | |
29 } | |
30 | |
31 public void setName(String name) { | |
32 this.name = name; | |
33 } | |
34 | |
35 | |
36 public AnnotationType getPeer() { | |
37 if (peer == null) { | |
38 Session session = ImporterSession.getInstance().getDatabaseSession(); | |
39 Query query = session.createQuery( | |
40 "from AnnotationType where name=:name"); | |
41 query.setParameter("name", name); | |
42 List<AnnotationType> types = query.list(); | |
43 if (types.isEmpty()) { | |
44 peer = new AnnotationType(name); | |
45 session.save(peer); | |
46 } | |
47 else { | |
48 peer = types.get(0); | |
49 } | |
50 } | |
51 return peer; | |
52 } | |
53 } | |
54 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |