Mercurial > dive4elements > river
view flys-backend/src/main/java/de/intevation/flys/importer/ImportAnnotation.java @ 759:9f2204ed79ed
Import edges to database.
flys-backend/trunk@2107 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 14 Jun 2011 13:13:58 +0000 |
parents | 67fd63e4ef66 |
children | 3170fe2e7661 |
line wrap: on
line source
package de.intevation.flys.importer; import de.intevation.flys.model.Annotation; import de.intevation.flys.model.Range; import de.intevation.flys.model.Position; import de.intevation.flys.model.Attribute; import de.intevation.flys.model.River; import de.intevation.flys.model.Edge; import org.hibernate.Session; import org.hibernate.Query; import java.util.List; public class ImportAnnotation implements Comparable<ImportAnnotation> { protected ImportAttribute attribute; protected ImportPosition position; protected ImportRange range; protected ImportEdge edge; protected Annotation peer; public ImportAnnotation() { } public ImportAnnotation( ImportAttribute attribute, ImportPosition position, ImportRange range, ImportEdge edge ) { this.attribute = attribute; this.position = position; this.range = range; this.edge = edge; } public int compareTo(ImportAnnotation other) { int d = attribute.compareTo(other.attribute); if (d != 0) { return d; } if ((d = position.compareTo(other.position)) != 0) { return d; } if ((d = range.compareTo(other.range)) != 0) { return d; } if (edge == null && other.edge != null) return -1; if (edge != null && other.edge == null) return +1; if (edge == null && other.edge == null) return 0; return edge.compareTo(other.edge); } public ImportAttribute getAttribute() { return attribute; } public void setAttribute(ImportAttribute attribute) { this.attribute = attribute; } public ImportPosition getPosition() { return position; } public void setPosition(ImportPosition position) { this.position = position; } public ImportRange getRange() { return range; } public void setRange(ImportRange range) { this.range = range; } public Annotation getPeer(River river) { if (peer == null) { Range r = range.getPeer(river); Attribute a = attribute.getPeer(); Position p = position.getPeer(); Edge e = edge != null ? edge.getPeer() : null; Session session = ImporterSession.getInstance().getDatabaseSession(); Query query = session.createQuery( "from Annotation where " + "range=:range and " + "attribute=:attribute and " + "position=:position and " + "edge=:edge"); query.setParameter("range", r); query.setParameter("attribute", a); query.setParameter("position", p); query.setParameter("edge", e); List<Annotation> annotations = query.list(); if (annotations.isEmpty()) { peer = new Annotation(r, a, p); session.save(peer); } else { peer = annotations.get(0); } } return peer; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :