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; ingo@2808: ingo@2809: import java.util.List; ingo@2809: ingo@2808: import org.apache.log4j.Logger; mschaefer@8974: import org.dive4elements.river.model.BedHeightType; mschaefer@8974: import org.hibernate.Query; ingo@2809: import org.hibernate.Session; ingo@2809: ingo@2808: ingo@2808: public class ImportBedHeightType { ingo@2808: ingo@2808: private static final Logger log = mschaefer@8974: Logger.getLogger(ImportBedHeightType.class); ingo@2808: ingo@2808: protected String name; ingo@2808: ingo@2809: protected BedHeightType peer; ingo@2809: mschaefer@8974: public ImportBedHeightType(final BedHeightType peer) { teichmann@5273: this.peer = peer; mschaefer@8974: this.name = peer.getName(); teichmann@5273: } ingo@2808: teichmann@5273: mschaefer@8974: public ImportBedHeightType(final String name) { ingo@2808: this.name = name; ingo@2808: } ingo@2808: ingo@2808: ingo@2809: public void storeDependencies() { teichmann@5273: getPeer(); ingo@2809: } ingo@2809: ingo@2809: ingo@2809: public BedHeightType getPeer() { mschaefer@8974: if (this.peer != null) mschaefer@8974: return this.peer; mschaefer@8974: final Session session = ImporterSession.getInstance().getDatabaseSession(); mschaefer@8974: final Query query = session.createQuery("FROM BedHeightType WHERE (trim(name)=:name) AND (trim(description)=:description)"); mschaefer@8974: query.setParameter("name", this.name); mschaefer@8974: final List types = query.list(); mschaefer@8974: if (types.isEmpty()) { mschaefer@8974: this.peer = new BedHeightType(this.name); mschaefer@8974: session.save(this.peer); mschaefer@8974: } else { mschaefer@8974: this.peer = types.get(0); ingo@2808: } mschaefer@8974: return this.peer; ingo@2808: } ingo@2808: } ingo@2808: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :