teichmann@5844: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5844: * Software engineering by Intevation GmbH teichmann@5844: * teichmann@5992: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5844: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5992: * documentation coming with Dive4Elements River for details. teichmann@5844: */ teichmann@5844: teichmann@5829: package org.dive4elements.river.importer; sascha@1215: teichmann@5829: import org.dive4elements.river.model.HYKFlowZoneType; sascha@1215: sascha@1215: import org.hibernate.Session; sascha@1215: import org.hibernate.Query; sascha@1215: sascha@1215: import java.util.List; sascha@1215: sascha@1215: public class ImportHYKFlowZoneType sascha@1215: { sascha@1215: private String name; sascha@1215: private HYKFlowZoneType peer; sascha@1215: sascha@1215: public ImportHYKFlowZoneType() { sascha@1215: } sascha@1215: sascha@1215: public ImportHYKFlowZoneType(String name) { sascha@1215: this.name = name; sascha@1215: } sascha@1215: sascha@1215: public HYKFlowZoneType getPeer() { sascha@1215: if (peer == null) { sascha@1215: Session session = ImporterSession.getInstance() sascha@1215: .getDatabaseSession(); sascha@1215: Query query = session.createQuery( sascha@1215: "from HYKFlowZoneType where name=:name"); sascha@1215: query.setParameter("name", name); sascha@1215: List flowZoneTypes = query.list(); sascha@1215: if (flowZoneTypes.isEmpty()) { sascha@1215: peer = new HYKFlowZoneType(name); sascha@1215: session.save(peer); sascha@1215: } sascha@1215: else { sascha@1215: peer = flowZoneTypes.get(0); sascha@1215: } sascha@1215: } sascha@1215: return peer; sascha@1215: } sascha@1215: } sascha@1215: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :