ingo@1230: package de.intevation.flys.model; ingo@1230: ingo@1230: import java.io.Serializable; ingo@1231: import java.util.List; ingo@1230: ingo@1230: import javax.persistence.Column; ingo@1230: import javax.persistence.Entity; ingo@1230: import javax.persistence.Id; ingo@1230: import javax.persistence.JoinColumn; ingo@1230: import javax.persistence.OneToOne; ingo@1230: import javax.persistence.Table; ingo@1230: rrenkert@5170: import org.hibernate.HibernateException; ingo@1231: import org.hibernate.Session; ingo@1231: import org.hibernate.Query; ingo@1230: import org.hibernate.annotations.Type; ingo@1230: rrenkert@5140: import com.vividsolutions.jts.geom.MultiLineString; ingo@1230: ingo@1231: import de.intevation.flys.backend.SessionHolder; aheinecke@5146: import de.intevation.flys.model.AxisKind; ingo@1231: ingo@1230: ingo@2375: /** aheinecke@5146: * A river has one axis that is used for calculation. aheinecke@5146: * Additional axes of a river can be used to be painted int maps etc. aheinecke@5146: * which one is the main river axis can be determined over the axis kind. ingo@2375: */ ingo@1230: @Entity ingo@1230: @Table(name = "river_axes") ingo@1230: public class RiverAxis ingo@1230: implements Serializable ingo@1230: { ingo@1230: private Integer id; aheinecke@5146: private AxisKind kind; ingo@1230: private River river; rrenkert@5140: private MultiLineString geom; teichmann@4736: aheinecke@5146: public static final int KIND_UNKOWN = 0; aheinecke@5146: public static final int KIND_CURRENT = 1; aheinecke@5146: public static final int KIND_OTHER = 2; ingo@1230: ingo@1230: public RiverAxis() { ingo@1230: } ingo@1230: ingo@1230: ingo@1230: @Id ingo@1230: @Column(name = "id") ingo@1230: public Integer getId() { ingo@1230: return id; ingo@1230: } ingo@1230: ingo@1230: ingo@1230: public void setId(Integer id) { ingo@1230: this.id = id; ingo@1230: } ingo@1230: ingo@1230: ingo@1230: @OneToOne ingo@1230: @JoinColumn(name = "river_id") ingo@1230: public River getRiver() { ingo@1230: return river; ingo@1230: } ingo@1230: ingo@1230: ingo@1230: public void setRiver(River river) { ingo@1230: this.river = river; ingo@1230: } ingo@1230: ingo@1230: aheinecke@5146: /** aheinecke@5146: * Get kind. aheinecke@5146: * aheinecke@5146: * @return kind as AxisKind. aheinecke@5146: */ aheinecke@5146: @OneToOne aheinecke@5146: @JoinColumn(name = "kind_id") aheinecke@5146: public AxisKind getKind() { ingo@1230: return kind; ingo@1230: } ingo@1230: aheinecke@5146: /** aheinecke@5146: * Set kind. aheinecke@5146: * aheinecke@5146: * @param kind the value to set. aheinecke@5146: */ aheinecke@5146: public void setKind(AxisKind kind) { ingo@1230: this.kind = kind; ingo@1230: } ingo@1230: ingo@1230: ingo@1230: @Column(name = "geom") ingo@1230: @Type(type = "org.hibernatespatial.GeometryUserType") rrenkert@5140: public MultiLineString getGeom() { ingo@1230: return geom; ingo@1230: } ingo@1230: ingo@1230: rrenkert@5140: public void setGeom(MultiLineString geom) { ingo@1230: this.geom = geom; ingo@1230: } ingo@1231: ingo@1231: rrenkert@5170: public static List getRiverAxis(String river) rrenkert@5173: throws IllegalArgumentException { aheinecke@5146: return getRiverAxis(river, KIND_CURRENT); ingo@3959: } teichmann@4736: rrenkert@5170: public static List getRiverAxis(String river, int kind) rrenkert@5181: throws HibernateException { ingo@1231: Session session = SessionHolder.HOLDER.get(); ingo@1231: Query query = session.createQuery( aheinecke@5146: "from RiverAxis where river.name =:river AND kind.id =:kind"); ingo@1231: query.setParameter("river", river); ingo@3959: query.setParameter("kind", kind); ingo@1231: rrenkert@5181: List list = query.list(); rrenkert@5181: return list.isEmpty() ? null : list; ingo@1231: } ingo@1230: } ingo@1230: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :