Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/RiverFactory.java @ 4655:cd44d28d0fbc
Move the access to artifact data to the Access object
Use BedHeightAccess class to receive the data from the artifact. This abstracts
the data access from the actual artifact.
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Tue, 11 Dec 2012 09:44:04 +0100 |
parents | 29022c93027d |
children |
rev | line source |
---|---|
114
394b9580ceae
Added mockup classes for working with rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.model; |
394b9580ceae
Added mockup classes for working with rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
394b9580ceae
Added mockup classes for working with rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 import java.util.List; |
394b9580ceae
Added mockup classes for working with rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 |
315
94c176fdcb89
Removed the SessionHolder and adapted imports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
312
diff
changeset
|
5 import de.intevation.flys.backend.SessionHolder; |
132
8be4a837f20a
Added support for the flys backend and an example how to use it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
114
diff
changeset
|
6 import de.intevation.flys.model.River; |
8be4a837f20a
Added support for the flys backend and an example how to use it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
114
diff
changeset
|
7 |
312
0c6328c227f1
Added a new function to RiverFactory that retrieves a River object based on a given river name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
311
diff
changeset
|
8 import org.hibernate.Query; |
132
8be4a837f20a
Added support for the flys backend and an example how to use it.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
114
diff
changeset
|
9 import org.hibernate.Session; |
114
394b9580ceae
Added mockup classes for working with rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 |
394b9580ceae
Added mockup classes for working with rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 /** |
394b9580ceae
Added mockup classes for working with rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
394b9580ceae
Added mockup classes for working with rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 */ |
394b9580ceae
Added mockup classes for working with rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 public class RiverFactory { |
394b9580ceae
Added mockup classes for working with rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 |
394b9580ceae
Added mockup classes for working with rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 /** We don't need to instantiate concrete objects of this class. */ |
394b9580ceae
Added mockup classes for working with rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 private RiverFactory() { |
394b9580ceae
Added mockup classes for working with rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 } |
394b9580ceae
Added mockup classes for working with rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 |
394b9580ceae
Added mockup classes for working with rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 |
394b9580ceae
Added mockup classes for working with rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 /** |
394b9580ceae
Added mockup classes for working with rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 * Returns all rivers that were found in the backend. |
394b9580ceae
Added mockup classes for working with rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 * |
394b9580ceae
Added mockup classes for working with rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 * @return all rivers. |
394b9580ceae
Added mockup classes for working with rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 */ |
394b9580ceae
Added mockup classes for working with rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 public static List<River> getRivers() { |
308
084995dd1c9c
Added a session holder to hold hibernate sessions.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
146
diff
changeset
|
27 Session session = SessionHolder.HOLDER.get(); |
1631
26e19cdaed5e
Improved database session handling in services and artifacts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1075
diff
changeset
|
28 |
26e19cdaed5e
Improved database session handling in services and artifacts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1075
diff
changeset
|
29 return session.createQuery("from River order by name").list(); |
114
394b9580ceae
Added mockup classes for working with rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 } |
312
0c6328c227f1
Added a new function to RiverFactory that retrieves a River object based on a given river name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
311
diff
changeset
|
31 |
0c6328c227f1
Added a new function to RiverFactory that retrieves a River object based on a given river name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
311
diff
changeset
|
32 |
0c6328c227f1
Added a new function to RiverFactory that retrieves a River object based on a given river name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
311
diff
changeset
|
33 /** |
1075
feaf778d510e
Changed the way of collecting the data for the RiverAxisArtifact - use the database instead of a Master-Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
315
diff
changeset
|
34 * Returns a River object fetched from database based on its id. |
feaf778d510e
Changed the way of collecting the data for the RiverAxisArtifact - use the database instead of a Master-Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
315
diff
changeset
|
35 * |
feaf778d510e
Changed the way of collecting the data for the RiverAxisArtifact - use the database instead of a Master-Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
315
diff
changeset
|
36 * @param river_id The id of the desired river. |
feaf778d510e
Changed the way of collecting the data for the RiverAxisArtifact - use the database instead of a Master-Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
315
diff
changeset
|
37 * |
feaf778d510e
Changed the way of collecting the data for the RiverAxisArtifact - use the database instead of a Master-Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
315
diff
changeset
|
38 * @return the river. |
feaf778d510e
Changed the way of collecting the data for the RiverAxisArtifact - use the database instead of a Master-Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
315
diff
changeset
|
39 */ |
feaf778d510e
Changed the way of collecting the data for the RiverAxisArtifact - use the database instead of a Master-Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
315
diff
changeset
|
40 public static River getRiver(int river_id) { |
feaf778d510e
Changed the way of collecting the data for the RiverAxisArtifact - use the database instead of a Master-Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
315
diff
changeset
|
41 Session session = SessionHolder.HOLDER.get(); |
feaf778d510e
Changed the way of collecting the data for the RiverAxisArtifact - use the database instead of a Master-Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
315
diff
changeset
|
42 |
feaf778d510e
Changed the way of collecting the data for the RiverAxisArtifact - use the database instead of a Master-Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
315
diff
changeset
|
43 Query query = session.createQuery("from River where id=:river_id"); |
feaf778d510e
Changed the way of collecting the data for the RiverAxisArtifact - use the database instead of a Master-Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
315
diff
changeset
|
44 query.setParameter("river_id", river_id); |
feaf778d510e
Changed the way of collecting the data for the RiverAxisArtifact - use the database instead of a Master-Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
315
diff
changeset
|
45 |
feaf778d510e
Changed the way of collecting the data for the RiverAxisArtifact - use the database instead of a Master-Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
315
diff
changeset
|
46 List<River> rivers = query.list(); |
feaf778d510e
Changed the way of collecting the data for the RiverAxisArtifact - use the database instead of a Master-Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
315
diff
changeset
|
47 |
3143
29022c93027d
FixA: Create a cached GaugeFinderFactory to access the gauge along a river
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1631
diff
changeset
|
48 return rivers.isEmpty() ? null : rivers.get(0); |
1075
feaf778d510e
Changed the way of collecting the data for the RiverAxisArtifact - use the database instead of a Master-Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
315
diff
changeset
|
49 } |
feaf778d510e
Changed the way of collecting the data for the RiverAxisArtifact - use the database instead of a Master-Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
315
diff
changeset
|
50 |
feaf778d510e
Changed the way of collecting the data for the RiverAxisArtifact - use the database instead of a Master-Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
315
diff
changeset
|
51 |
feaf778d510e
Changed the way of collecting the data for the RiverAxisArtifact - use the database instead of a Master-Artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
315
diff
changeset
|
52 /** |
312
0c6328c227f1
Added a new function to RiverFactory that retrieves a River object based on a given river name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
311
diff
changeset
|
53 * Returns a River object fetched from database based on its name. |
0c6328c227f1
Added a new function to RiverFactory that retrieves a River object based on a given river name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
311
diff
changeset
|
54 * |
0c6328c227f1
Added a new function to RiverFactory that retrieves a River object based on a given river name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
311
diff
changeset
|
55 * @param river The name of a river. |
0c6328c227f1
Added a new function to RiverFactory that retrieves a River object based on a given river name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
311
diff
changeset
|
56 * |
0c6328c227f1
Added a new function to RiverFactory that retrieves a River object based on a given river name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
311
diff
changeset
|
57 * @return the River object. |
0c6328c227f1
Added a new function to RiverFactory that retrieves a River object based on a given river name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
311
diff
changeset
|
58 */ |
0c6328c227f1
Added a new function to RiverFactory that retrieves a River object based on a given river name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
311
diff
changeset
|
59 public static River getRiver(String river) { |
0c6328c227f1
Added a new function to RiverFactory that retrieves a River object based on a given river name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
311
diff
changeset
|
60 Session session = SessionHolder.HOLDER.get(); |
0c6328c227f1
Added a new function to RiverFactory that retrieves a River object based on a given river name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
311
diff
changeset
|
61 |
0c6328c227f1
Added a new function to RiverFactory that retrieves a River object based on a given river name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
311
diff
changeset
|
62 Query query = session.createQuery( |
0c6328c227f1
Added a new function to RiverFactory that retrieves a River object based on a given river name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
311
diff
changeset
|
63 "from River where name =:name"); |
0c6328c227f1
Added a new function to RiverFactory that retrieves a River object based on a given river name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
311
diff
changeset
|
64 query.setParameter("name", river); |
0c6328c227f1
Added a new function to RiverFactory that retrieves a River object based on a given river name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
311
diff
changeset
|
65 |
0c6328c227f1
Added a new function to RiverFactory that retrieves a River object based on a given river name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
311
diff
changeset
|
66 List<River> rivers = query.list(); |
0c6328c227f1
Added a new function to RiverFactory that retrieves a River object based on a given river name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
311
diff
changeset
|
67 |
3143
29022c93027d
FixA: Create a cached GaugeFinderFactory to access the gauge along a river
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1631
diff
changeset
|
68 return rivers.isEmpty() ? null : rivers.get(0); |
312
0c6328c227f1
Added a new function to RiverFactory that retrieves a River object based on a given river name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
311
diff
changeset
|
69 } |
114
394b9580ceae
Added mockup classes for working with rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
70 } |
394b9580ceae
Added mockup classes for working with rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
71 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |