teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
teichmann@5863: * Software engineering by Intevation GmbH
teichmann@5863: *
teichmann@5994: * This file is Free Software under the GNU AGPL (>=v3)
teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the
teichmann@5994: * documentation coming with Dive4Elements River for details.
teichmann@5863: */
teichmann@5863:
teichmann@5831: package org.dive4elements.river.artifacts.model;
ingo@318:
ingo@318: import java.util.List;
ingo@318:
teichmann@5831: import org.dive4elements.river.backend.SessionHolder;
teichmann@5831: import org.dive4elements.river.model.River;
teichmann@5831: import org.dive4elements.river.model.Wst;
ingo@318:
ingo@318: import org.hibernate.Query;
ingo@318: import org.hibernate.Session;
ingo@318:
ingo@318: /**
ingo@318: * @author Ingo Weinzierl
ingo@318: */
ingo@318: public class WstFactory {
ingo@318:
sascha@622: public static final int DEFAULT_KIND = 0;
sascha@622:
ingo@318: /** We don't need to instantiate concrete objects of this class. */
ingo@318: private WstFactory() {
ingo@318: }
ingo@318:
ingo@318:
ingo@318: /**
ingo@318: * Returns the Wst object for a given river.
ingo@318: *
ingo@318: * @param river The river.
ingo@318: *
ingo@318: * @return the Wst of river.
ingo@318: */
ingo@318: public static Wst getWst(River river) {
sascha@622: return getWst(river, DEFAULT_KIND);
sascha@622: }
sascha@622:
sascha@622: public static Wst getWst(River river, int kind) {
ingo@318: Session session = SessionHolder.HOLDER.get();
ingo@318:
ingo@318: Query query = session.createQuery(
sascha@622: "from Wst where river=:river and kind = :kind");
ingo@318: query.setParameter("river", river);
sascha@622: query.setInteger("kind", kind);
ingo@318:
sascha@622: List wsts = query.list();
ingo@318:
sascha@622: return wsts.isEmpty() ? null : wsts.get(0);
ingo@318: }
ingo@318: }
ingo@318: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :