annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/RiverFactory.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-artifacts/src/main/java/org/dive4elements/river/artifacts/model/RiverFactory.java@bd047b71ab37
children 4897a58c8746
rev   line source
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3143
diff changeset
1 package org.dive4elements.river.artifacts.model;
114
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
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3143
diff changeset
5 import org.dive4elements.river.backend.SessionHolder;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3143
diff changeset
6 import org.dive4elements.river.model.River;
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
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 :

http://dive4elements.wald.intevation.org