ingo@2808: package de.intevation.flys.importer; ingo@2808: ingo@2809: import java.util.List; ingo@2809: ingo@2808: import java.math.BigDecimal; ingo@2808: ingo@2809: import org.apache.log4j.Logger; ingo@2809: ingo@2809: import org.hibernate.Session; ingo@2809: import org.hibernate.Query; ingo@2809: ingo@2809: import de.intevation.flys.model.BedHeightSingle; ingo@2809: import de.intevation.flys.model.BedHeightSingleValue; ingo@2809: ingo@2808: ingo@2811: public class ImportBedHeightSingleValue implements ImportBedHeightValue { ingo@2808: ingo@2809: private static final Logger log = ingo@2809: Logger.getLogger(ImportBedHeightSingleValue.class); ingo@2809: ingo@2809: ingo@2808: protected ImportBedHeightSingle bedHeight; ingo@2808: ingo@2808: protected BigDecimal station; ingo@2808: protected BigDecimal height; ingo@2808: protected BigDecimal uncertainty; ingo@2808: protected BigDecimal dataGap; ingo@2808: protected BigDecimal soundingWidth; ingo@2808: protected BigDecimal width; ingo@2808: ingo@2809: protected BedHeightSingleValue peer; ingo@2809: ingo@2808: ingo@2808: public ImportBedHeightSingleValue( ingo@2808: ImportBedHeightSingle bedHeight, ingo@2808: BigDecimal station, ingo@2808: BigDecimal height, ingo@2808: BigDecimal uncertainty, ingo@2808: BigDecimal dataGap, ingo@2808: BigDecimal soundingWidth, ingo@2808: BigDecimal width ingo@2808: ) { ingo@2808: this.bedHeight = bedHeight; ingo@2808: this.station = station; ingo@2808: this.height = height; ingo@2808: this.uncertainty = uncertainty; ingo@2808: this.dataGap = dataGap; ingo@2808: this.soundingWidth = soundingWidth; ingo@2808: this.width = width; ingo@2808: } ingo@2809: ingo@2809: ingo@2809: public void storeDependencies(BedHeightSingle bedHeight) { ingo@2809: getPeer(bedHeight); ingo@2809: } ingo@2809: ingo@2809: felix@3954: /** felix@3954: * Add this value to database or return database bound Value, assuring felix@3954: * that the BedHeightSingle exists in db already. felix@3954: */ ingo@2809: public BedHeightSingleValue getPeer(BedHeightSingle bedHeight) { ingo@2809: if (peer == null) { ingo@2809: Session session = ImporterSession.getInstance().getDatabaseSession(); ingo@2809: ingo@2809: Query query = session.createQuery( ingo@2809: "from BedHeightSingleValue where " + ingo@2809: " bedHeight=:bedHeight and " + ingo@2809: " station=:station and " + ingo@2809: " height=:height and " + ingo@2809: " uncertainty=:uncertainty and " + ingo@2809: " dataGap=:dataGap and " + ingo@2809: " soundingWidth=:soundingWidth and " + ingo@2809: " width=:width"); ingo@2809: ingo@2809: query.setParameter("bedHeight", bedHeight); ingo@2809: query.setParameter("station", station); ingo@2809: query.setParameter("height", height); ingo@2809: query.setParameter("uncertainty", uncertainty); ingo@2809: query.setParameter("dataGap", dataGap); ingo@2809: query.setParameter("soundingWidth", soundingWidth); ingo@2809: query.setParameter("width", width); ingo@2809: ingo@2809: List values = query.list(); ingo@2809: if (values.isEmpty()) { ingo@2809: peer = new BedHeightSingleValue( ingo@2809: bedHeight, ingo@2809: station, ingo@2809: height, ingo@2809: uncertainty, ingo@2809: dataGap, ingo@2809: soundingWidth, ingo@2809: width ingo@2809: ); ingo@2809: session.save(peer); ingo@2809: } ingo@2809: else { ingo@2809: peer = values.get(0); ingo@2809: } ingo@2809: } ingo@2809: ingo@2809: return peer; ingo@2809: } ingo@2808: } ingo@2808: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :