teichmann@5844: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5844: * Software engineering by Intevation GmbH teichmann@5844: * teichmann@5992: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5844: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5992: * documentation coming with Dive4Elements River for details. teichmann@5844: */ teichmann@5844: teichmann@5829: package org.dive4elements.river.model; ingo@2809: ingo@2809: import java.io.Serializable; ingo@2809: teichmann@5273: import java.util.List; teichmann@5273: ingo@2809: import javax.persistence.Entity; ingo@2809: import javax.persistence.Id; ingo@2809: import javax.persistence.Table; ingo@2809: import javax.persistence.GeneratedValue; ingo@2809: import javax.persistence.Column; ingo@2809: import javax.persistence.SequenceGenerator; ingo@2809: import javax.persistence.GenerationType; ingo@2809: ingo@2809: import org.apache.log4j.Logger; ingo@2809: teichmann@5273: import org.hibernate.Query; teichmann@5273: import org.hibernate.Session; teichmann@5273: teichmann@5829: import org.dive4elements.river.backend.SessionHolder; ingo@2809: ingo@2809: @Entity ingo@2809: @Table(name = "bed_height_type") ingo@2809: public class BedHeightType ingo@2809: implements Serializable ingo@2809: { ingo@2809: private static Logger log = Logger.getLogger(BedHeightType.class); ingo@2809: ingo@2809: private Integer id; ingo@2809: private String name; ingo@2809: ingo@2809: ingo@2809: public BedHeightType() { ingo@2809: } ingo@2809: teichmann@5273: public BedHeightType(String name) { teichmann@5273: this.name = name; ingo@2809: } ingo@2809: ingo@2809: @Id ingo@2809: @SequenceGenerator( ingo@2809: name = "SEQUENCE_BED_HEIGHT_TYPE_ID_SEQ", ingo@2809: sequenceName = "BED_HEIGHT_TYPE_SEQ", ingo@2809: allocationSize = 1) ingo@2809: @GeneratedValue( ingo@2809: strategy = GenerationType.SEQUENCE, ingo@2809: generator = "SEQUENCE_BED_HEIGHT_TYPE_ID_SEQ") ingo@2809: @Column(name = "id") ingo@2809: public Integer getId() { ingo@2809: return id; ingo@2809: } ingo@2809: ingo@2809: public void setId(Integer id) { ingo@2809: this.id = id; ingo@2809: } ingo@2809: ingo@2809: @Column(name = "name") ingo@2809: public String getName() { ingo@2809: return name; ingo@2809: } ingo@2809: ingo@2809: public void setName(String name) { ingo@2809: this.name = name; ingo@2809: } ingo@2809: teichmann@5273: public static BedHeightType fetchBedHeightTypeForType(String type) { teichmann@7252: return fetchBedHeightTypeForType(type, null); tom@5278: } tom@5278: tom@5278: public static BedHeightType fetchBedHeightTypeForType(String name, Session session) { tom@5278: teichmann@7252: if (session == null) { teichmann@7252: session = SessionHolder.HOLDER.get(); teichmann@7252: } tom@5278: teichmann@5273: Query query = session.createQuery( tom@5278: "from BedHeightType where name=:name"); teichmann@5273: tom@5278: query.setParameter("name", name); teichmann@5273: teichmann@5273: List results = query.list(); teichmann@5273: teichmann@5273: return results.isEmpty() ? null : (BedHeightType)results.get(0); ingo@2809: } ingo@2809: } ingo@2809: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :