ingo@2827: package de.intevation.flys.importer; ingo@2827: ingo@2827: import java.math.BigDecimal; ingo@2827: import java.sql.SQLException; ingo@2827: import java.util.List; ingo@2827: ingo@2827: import org.hibernate.Session; ingo@2827: import org.hibernate.Query; ingo@2827: import org.hibernate.exception.ConstraintViolationException; ingo@2827: ingo@2827: import de.intevation.flys.model.FlowVelocityModel; ingo@2827: import de.intevation.flys.model.FlowVelocityModelValue; ingo@2827: ingo@2827: ingo@2827: public class ImportFlowVelocityModelValue { ingo@2827: ingo@2827: private BigDecimal station; ingo@2828: private BigDecimal q; ingo@2827: private BigDecimal totalChannel; ingo@2827: private BigDecimal mainChannel; ingo@2827: private BigDecimal shearStress; ingo@2827: ingo@2827: private FlowVelocityModelValue peer; ingo@2827: ingo@2827: ingo@2827: public ImportFlowVelocityModelValue( ingo@2827: BigDecimal station, ingo@2828: BigDecimal q, ingo@2827: BigDecimal totalChannel, ingo@2827: BigDecimal mainChannel, ingo@2827: BigDecimal shearStress ingo@2827: ) { ingo@2827: this.station = station; ingo@2828: this.q = q; ingo@2827: this.totalChannel = totalChannel; ingo@2827: this.mainChannel = mainChannel; ingo@2827: this.shearStress = shearStress; ingo@2827: } ingo@2827: ingo@2827: ingo@2827: public void storeDependencies(FlowVelocityModel model) ingo@2827: throws SQLException, ConstraintViolationException ingo@2827: { ingo@2827: getPeer(model); ingo@2827: } ingo@2827: ingo@2827: ingo@2827: public FlowVelocityModelValue getPeer(FlowVelocityModel model) { ingo@2827: if (peer == null) { ingo@2827: Session session = ImporterSession.getInstance().getDatabaseSession(); ingo@2827: ingo@2827: Query query = session.createQuery( ingo@2827: "from FlowVelocityModelValue where " + ingo@2833: " flowVelocity=:model and " + ingo@2827: " station=:station" ingo@2827: ); ingo@2827: ingo@2827: query.setParameter("model", model); ingo@2827: query.setParameter("station", station); ingo@2827: ingo@2827: List values = query.list(); ingo@2827: ingo@2827: if (values.isEmpty()) { ingo@2827: peer = new FlowVelocityModelValue( ingo@2828: model, station, q, totalChannel, mainChannel, shearStress); ingo@2827: ingo@2827: session.save(peer); ingo@2827: } ingo@2827: else { ingo@2827: peer = values.get(0); ingo@2827: } ingo@2827: } ingo@2827: ingo@2827: return peer; ingo@2827: } ingo@2827: } ingo@2827: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :