Mercurial > dive4elements > river
changeset 312:0c6328c227f1
Added a new function to RiverFactory that retrieves a River object based on a given river name.
flys-artifacts/trunk@1696 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 14 Apr 2011 13:26:29 +0000 |
parents | ea3a438a7021 |
children | 89bd0417418f |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/RiverFactory.java |
diffstat | 2 files changed, 28 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Thu Apr 14 13:15:16 2011 +0000 +++ b/flys-artifacts/ChangeLog Thu Apr 14 13:26:29 2011 +0000 @@ -1,3 +1,9 @@ +2011-04-14 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/model/RiverFactory.java: + Added a function that returns a River object based on a given river + name. + 2011-04-14 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/flys/artifacts/model/RiverFactory.java,
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/RiverFactory.java Thu Apr 14 13:15:16 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/RiverFactory.java Thu Apr 14 13:26:29 2011 +0000 @@ -5,6 +5,8 @@ import de.intevation.flys.model.River; + +import org.hibernate.Query; import org.hibernate.Session; /** @@ -27,5 +29,25 @@ return (List<River>)session .createQuery("from River order by name").list(); } + + + /** + * Returns a River object fetched from database based on its name. + * + * @param river The name of a river. + * + * @return the River object. + */ + public static River getRiver(String river) { + Session session = SessionHolder.HOLDER.get(); + + Query query = session.createQuery( + "from River where name =:name"); + query.setParameter("name", river); + + List<River> rivers = query.list(); + + return (rivers != null && rivers.size() > 0) ? rivers.get(0) : null; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :