Mercurial > dive4elements > river
view flys-backend/src/main/java/de/intevation/flys/importer/ImportWstColumn.java @ 201:3169b559ca3c
Build models for wsts, wst columns and q ranges and store them in the backend.
flys-backend/trunk@1549 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 23 Mar 2011 15:22:32 +0000 |
parents | a33c065b95eb |
children | 29a408f80a89 |
line wrap: on
line source
package de.intevation.flys.importer; import de.intevation.flys.model.Wst; import de.intevation.flys.model.WstColumn; import de.intevation.flys.model.River; import org.hibernate.Session; import org.hibernate.Query; import java.util.List; import java.util.ArrayList; public class ImportWstColumn { protected ImportWst wst; protected String name; protected String description; protected List<ImportWstColumnQRange> columnQRanges; protected WstColumn peer; public ImportWstColumn() { columnQRanges = new ArrayList<ImportWstColumnQRange>(); } public ImportWstColumn( ImportWst wst, String name, String description ) { this(); this.wst = wst; this.name = name; this.description = description; } public ImportWst getWst() { return wst; } public void setWst(ImportWst wst) { this.wst = wst; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public void addColumnQRange(ImportWstQRange columnQRange) { columnQRanges.add( new ImportWstColumnQRange(this, columnQRange)); } public void storeDependencies(River river) { WstColumn column = getPeer(river); for (ImportWstColumnQRange columnQRange: columnQRanges) { columnQRange.getPeer(river); } // TODO: Implement me! } public WstColumn getPeer(River river) { if (peer == null) { Wst w = wst.getPeer(river); Session session = Importer.sessionHolder.get(); Query query = session.createQuery( "from WstColumn where " + "wst=:wst and name=:name and description=:description"); query.setParameter("wst", w); query.setParameter("name", name); query.setParameter("description", description); List<WstColumn> columns = query.list(); if (columns.isEmpty()) { peer = new WstColumn(w, name, description, null); session.save(peer); } else { peer = columns.get(0); } } return peer; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :