Mercurial > dive4elements > river
diff 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 diff
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportWstColumn.java Wed Mar 23 10:46:58 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportWstColumn.java Wed Mar 23 15:22:32 2011 +0000 @@ -1,17 +1,95 @@ 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 WstColumn getPeer() { + 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) { - // TODO: Implement me! + 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; }