Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstFactory.java @ 1839:c3b44da22a3a
Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
flys-artifacts/trunk@3175 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Mon, 07 Nov 2011 12:37:41 +0000 |
parents | 02ca2ff96dee |
children |
rev | line source |
---|---|
318
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.model; |
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 import java.util.List; |
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 |
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
5 import de.intevation.flys.backend.SessionHolder; |
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 import de.intevation.flys.model.River; |
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 import de.intevation.flys.model.Wst; |
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 |
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 import org.hibernate.Query; |
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 import org.hibernate.Session; |
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 |
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 /** |
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 */ |
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 public class WstFactory { |
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 |
622
02ca2ff96dee
flys/issue84: Forget to select wst kind.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
318
diff
changeset
|
17 public static final int DEFAULT_KIND = 0; |
02ca2ff96dee
flys/issue84: Forget to select wst kind.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
318
diff
changeset
|
18 |
318
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 /** We don't need to instantiate concrete objects of this class. */ |
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 private WstFactory() { |
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 } |
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 |
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 |
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 /** |
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 * Returns the Wst object for a given river. |
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 * |
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 * @param river The river. |
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 * |
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 * @return the Wst of <i>river</i>. |
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 */ |
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 public static Wst getWst(River river) { |
622
02ca2ff96dee
flys/issue84: Forget to select wst kind.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
318
diff
changeset
|
32 return getWst(river, DEFAULT_KIND); |
02ca2ff96dee
flys/issue84: Forget to select wst kind.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
318
diff
changeset
|
33 } |
02ca2ff96dee
flys/issue84: Forget to select wst kind.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
318
diff
changeset
|
34 |
02ca2ff96dee
flys/issue84: Forget to select wst kind.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
318
diff
changeset
|
35 public static Wst getWst(River river, int kind) { |
318
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
36 Session session = SessionHolder.HOLDER.get(); |
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 |
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
38 Query query = session.createQuery( |
622
02ca2ff96dee
flys/issue84: Forget to select wst kind.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
318
diff
changeset
|
39 "from Wst where river=:river and kind = :kind"); |
318
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 query.setParameter("river", river); |
622
02ca2ff96dee
flys/issue84: Forget to select wst kind.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
318
diff
changeset
|
41 query.setInteger("kind", kind); |
318
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 |
622
02ca2ff96dee
flys/issue84: Forget to select wst kind.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
318
diff
changeset
|
43 List<Wst> wsts = query.list(); |
318
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 |
622
02ca2ff96dee
flys/issue84: Forget to select wst kind.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
318
diff
changeset
|
45 return wsts.isEmpty() ? null : wsts.get(0); |
318
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 } |
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 } |
8a4360ccbe1c
Added a WstFactory to return Wst objects.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |