ingo@1237: package de.intevation.flys.model; ingo@1237: ingo@1237: import java.io.Serializable; ingo@1237: import java.util.List; ingo@1237: ingo@1237: import javax.persistence.Column; ingo@1237: import javax.persistence.Entity; ingo@1237: import javax.persistence.Id; ingo@1237: import javax.persistence.JoinColumn; ingo@1237: import javax.persistence.OneToOne; ingo@1237: import javax.persistence.Table; ingo@1237: ingo@1237: import org.hibernate.Query; ingo@1237: import org.hibernate.Session; ingo@1237: import org.hibernate.annotations.Type; ingo@1237: ingo@2361: import com.vividsolutions.jts.geom.Polygon; ingo@1237: ingo@1237: import de.intevation.flys.backend.SessionHolder; ingo@1237: ingo@1237: ingo@1237: @Entity ingo@1237: @Table(name = "floodplain") ingo@1237: public class Floodplain ingo@1237: implements Serializable ingo@1237: { aheinecke@5242: private Integer id; ingo@1237: aheinecke@5242: private FloodplainKind kind; ingo@1237: aheinecke@5242: private River river; aheinecke@5242: aheinecke@5242: private Polygon geom; ingo@1237: ingo@1237: ingo@1237: public Floodplain() { ingo@1237: } ingo@1237: ingo@1237: ingo@1237: @Id ingo@1237: @Column(name = "id") ingo@1237: public Integer getId() { ingo@1237: return id; ingo@1237: } ingo@1237: ingo@1237: public void setId(Integer id) { ingo@1237: this.id = id; ingo@1237: } ingo@1237: ingo@1237: @OneToOne ingo@1237: @JoinColumn(name = "river_id") ingo@1237: public River getRiver() { ingo@1237: return river; ingo@1237: } ingo@1237: ingo@1237: public void setRiver(River river) { ingo@1237: this.river = river; ingo@1237: } ingo@1237: aheinecke@5242: @OneToOne aheinecke@5242: @JoinColumn(name = "kind_id") aheinecke@5242: public FloodplainKind getKind() { aheinecke@5242: return kind; aheinecke@5242: } aheinecke@5242: aheinecke@5242: public void setKind(FloodplainKind kind) { aheinecke@5242: this.kind = kind; aheinecke@5242: } aheinecke@5242: ingo@1237: @Column(name = "geom") ingo@1237: @Type(type = "org.hibernatespatial.GeometryUserType") ingo@2361: public Polygon getGeom() { ingo@1237: return geom; ingo@1237: } ingo@1237: ingo@2361: public void setGeom(Polygon geom) { ingo@1237: this.geom = geom; ingo@1237: } ingo@1237: ingo@1237: ingo@1237: public static Floodplain getFloodplain(String river) { ingo@1237: Session session = SessionHolder.HOLDER.get(); ingo@1237: aheinecke@5242: // kind_id 0 -> Offical aheinecke@5242: // kind_id 1 -> Misc. ingo@1237: Query query = session.createQuery( aheinecke@5242: "from Floodplain where river.name =:river and kind_id=1"); ingo@1237: query.setParameter("river", river); ingo@1237: ingo@1237: List result = query.list(); ingo@1237: ingo@1237: return result.isEmpty() ? null : result.get(0); ingo@1237: } ingo@1237: } ingo@1237: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :