package de.hsadmin.mods.pac; import static javax.persistence.CascadeType.ALL; import static javax.persistence.FetchType.EAGER; import static javax.persistence.FetchType.LAZY; import static javax.persistence.GenerationType.SEQUENCE; import java.util.Set; import javax.persistence.EntityManager; import de.hsadmin.mods.user.UnixUser; @javax.persistence.Entity(name="Hives") @javax.persistence.Table(name="hive") @javax.persistence.SequenceGenerator(name="HivesSeqGen", sequenceName="hive_hive_id_seq") public class Hive extends de.hsadmin.core.model.AbstractEntity implements java.io.Serializable { private static final long serialVersionUID = -2270234313165009590L; /// bean ctor public Hive() { } public Hive( String name, INetAddress inetAddr ) { this.name = name; this.inetAddr = inetAddr; } public Hive( String name, INetAddress inetAddr, String desc ) { this(name, inetAddr); this.description = desc; } /// {@inheritDoc} public static String createQueryFromStringKey(String humanKey) { return "hiveName='" + humanKey + "'"; } /// {@inheritDoc} @Override public String createStringKey() { return getHiveName(); } /// {@inheritDoc} @Override public long id() { return id; } // attribute id @javax.persistence.Id @javax.persistence.GeneratedValue(strategy=SEQUENCE, generator="HivesSeqGen") @javax.persistence.Column(name="hive_id") private long id; public long getId() { return id; } public void setId( long id ) { this.id = id; } // attribute hiveName @javax.persistence.Column(name="hive_name", columnDefinition="character varying(3)", unique=true) private String name; public String getName() { return name; } @Override public String getHiveName() { return name; } public void setName( String hiveName ) { this.name = hiveName; } // attribute inetAddr @javax.persistence.JoinColumn(name="inet_addr_id") @javax.persistence.ManyToOne(fetch=EAGER) private INetAddress inetAddr; public INetAddress getInetAddr() { return inetAddr; } public void setInetAddr( INetAddress inetAddr ) { this.inetAddr = inetAddr; } // attribute description @javax.persistence.Column(name="description", columnDefinition="character varying(100)") private String description; public String getDescription() { return description; } public void setDescription( String description ) { this.description = description; } // virtual attribute pacs @javax.persistence.OneToMany(fetch=LAZY, cascade=ALL, mappedBy="hive") @javax.persistence.OrderBy("name") private Set pacs; public Set getPacs() { return pacs; } public void setPacs( Set pacs) { this.pacs = pacs; } /// {$inheritDoc} @Override public boolean isNew() { return id == 0; } /// {@inheritDoc} @Override public UnixUser owningUser( EntityManager em ) { return null; // TODO: kinda somebody like root needed } }