Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/RiverFactory.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 | 26e19cdaed5e |
children | 29022c93027d |
line wrap: on
line source
package de.intevation.flys.artifacts.model; import java.util.List; import de.intevation.flys.backend.SessionHolder; import de.intevation.flys.model.River; import org.hibernate.Query; import org.hibernate.Session; /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class RiverFactory { /** We don't need to instantiate concrete objects of this class. */ private RiverFactory() { } /** * Returns all rivers that were found in the backend. * * @return all rivers. */ public static List<River> getRivers() { Session session = SessionHolder.HOLDER.get(); return session.createQuery("from River order by name").list(); } /** * Returns a River object fetched from database based on its id. * * @param river_id The id of the desired river. * * @return the river. */ public static River getRiver(int river_id) { Session session = SessionHolder.HOLDER.get(); Query query = session.createQuery("from River where id=:river_id"); query.setParameter("river_id", river_id); List<River> rivers = query.list(); return (rivers != null && rivers.size() > 0) ? rivers.get(0) : null; } /** * 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 :