Mercurial > dive4elements > river
diff flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightEpochValue.java @ 2810:04eeb45df27b
Implemented model classes and importer classes for bed height epochs.
flys-backend/trunk@4222 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 12 Apr 2012 12:50:49 +0000 |
parents | |
children | 8926571e47fb |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportBedHeightEpochValue.java Thu Apr 12 12:50:49 2012 +0000 @@ -0,0 +1,75 @@ +package de.intevation.flys.importer; + +import java.util.List; + +import java.math.BigDecimal; + +import org.apache.log4j.Logger; + +import org.hibernate.Session; +import org.hibernate.Query; + +import de.intevation.flys.model.BedHeightEpoch; +import de.intevation.flys.model.BedHeightEpochValue; + + +public class ImportBedHeightEpochValue { + + private static final Logger log = + Logger.getLogger(ImportBedHeightEpochValue.class); + + + private BigDecimal station; + private BigDecimal height; + + private BedHeightEpochValue peer; + + + public ImportBedHeightEpochValue() { + } + + + public ImportBedHeightEpochValue(BigDecimal station, BigDecimal height) { + this.station = station; + this.height = height; + } + + + public void storeDependencies(BedHeightEpoch bedHeight) { + getPeer(bedHeight); + } + + + public BedHeightEpochValue getPeer(BedHeightEpoch bedHeight) { + if (peer == null) { + Session session = ImporterSession.getInstance().getDatabaseSession(); + + Query query = session.createQuery( + "from BedHeightEpochValue where " + + " bedHeight=:bedHeight and " + + " station=:station and " + + " height=:height"); + + query.setParameter("bedHeight", bedHeight); + query.setParameter("station", station); + query.setParameter("height", height); + + List<BedHeightEpochValue> values = query.list(); + + if (values.isEmpty()) { + peer = new BedHeightEpochValue( + bedHeight, + station, + height + ); + session.save(peer); + } + else { + peer = values.get(0); + } + } + + return peer; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :