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