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@2809: import org.apache.log4j.Logger; mschaefer@8974: import org.dive4elements.river.model.LocationSystem; mschaefer@8974: import org.hibernate.Query; ingo@2809: import org.hibernate.Session; ingo@2808: ingo@2808: ingo@2808: public class ImportLocationSystem { ingo@2808: ingo@2809: private static final Logger log = mschaefer@8974: Logger.getLogger(ImportLocationSystem.class); ingo@2809: ingo@2809: ingo@2808: protected String name; ingo@2808: protected String description; ingo@2808: ingo@2809: protected LocationSystem peer; ingo@2809: ingo@2808: mschaefer@8974: public ImportLocationSystem(final String name, final String description) { ingo@2808: this.name = name; ingo@2808: this.description = description; ingo@2808: } ingo@2809: ingo@2809: public void storeDependencies() { mschaefer@8974: log.info("store LocationSystem '" + this.name + "'"); mschaefer@8974: final LocationSystem ls = getPeer(); ingo@2809: mschaefer@8974: final Session session = ImporterSession.getInstance().getDatabaseSession(); ingo@2809: session.flush(); ingo@2809: } ingo@2809: ingo@2809: public LocationSystem 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 LocationSystem WHERE (trim(name)=:name) AND (trim(description)=:description)"); mschaefer@8974: query.setParameter("name", this.name); mschaefer@8974: query.setParameter("description", this.description); mschaefer@8974: final List lss = query.list(); mschaefer@8974: if (lss.isEmpty()) { mschaefer@8974: this.peer = new LocationSystem(this.name, this.description); mschaefer@8974: session.save(this.peer); mschaefer@8974: } else { mschaefer@8974: this.peer = lss.get(0); ingo@2809: } mschaefer@8974: return this.peer; ingo@2809: } ingo@2808: } ingo@2808: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :