Mercurial > dive4elements > river
view flys-backend/src/main/java/de/intevation/flys/importer/ImportWstColumn.java @ 478:db430bd9e0e0
Implemented a WstColumnValue cache to speed up inserting WST files into database.
flys-backend/trunk@1734 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 20 Apr 2011 07:21:03 +0000 |
parents | 3570e4af8cb2 |
children | 67fd63e4ef66 |
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.WstColumnValue; import de.intevation.flys.model.River; import org.hibernate.Session; import org.hibernate.Query; import java.util.List; import java.util.ArrayList; import java.util.Map; import java.math.BigDecimal; public class ImportWstColumn { protected ImportWst wst; protected String name; protected String description; protected Integer position; protected List<ImportWstColumnQRange> columnQRanges; protected List<ImportWstColumnValue> columnValues; protected Map<WstColumnValueKey, WstColumnValue> wstCache; protected WstColumn peer; public ImportWstColumn() { columnQRanges = new ArrayList<ImportWstColumnQRange>(); columnValues = new ArrayList<ImportWstColumnValue>(); } public ImportWstColumn( ImportWst wst, String name, String description, Integer position, Map<WstColumnValueKey, WstColumnValue> wstCache ) { this(); this.wst = wst; this.name = name; this.description = description; this.position = position; this.wstCache = wstCache; } 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 Integer getPosition() { return position; } public void setPosition(Integer position) { this.position = position; } public void addColumnValue(BigDecimal position, BigDecimal w) { columnValues.add( new ImportWstColumnValue(this, position, w, wstCache)); } 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); } for (ImportWstColumnValue columnValue: columnValues) { columnValue.getPeer(river); } } 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" + " and position=:position"); query.setParameter("wst", w); query.setParameter("name", name); query.setParameter("description", description); query.setParameter("position", position); List<WstColumn> columns = query.list(); if (columns.isEmpty()) { peer = new WstColumn(w, name, description, position, null); session.save(peer); } else { peer = columns.get(0); } } return peer; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :