hs.hsadmin/hsarback/src/de/hsadmin/mods/pac/Hive.java

140 lines
3.1 KiB
Java
Raw Normal View History

2010-10-01 21:52:51 +02:00
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;
2010-10-06 15:06:01 +02:00
import java.io.Serializable;
2010-10-01 21:52:51 +02:00
import java.util.Set;
2010-10-06 15:06:01 +02:00
import javax.persistence.Column;
import javax.persistence.Entity;
2010-10-01 21:52:51 +02:00
import javax.persistence.EntityManager;
2010-10-06 15:06:01 +02:00
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import de.hsadmin.core.model.AbstractEntity;
2013-02-20 17:24:23 +01:00
import de.hsadmin.core.util.Config;
2010-10-01 21:52:51 +02:00
import de.hsadmin.mods.user.UnixUser;
2010-10-06 15:06:01 +02:00
@Entity(name = "Hives")
@Table(name = "hive")
@SequenceGenerator(name = "HivesSeqGen", sequenceName = "hive_hive_id_seq")
public class Hive extends AbstractEntity implements Serializable {
2010-10-01 21:52:51 +02:00
private static final long serialVersionUID = -2270234313165009590L;
2010-10-06 15:06:01 +02:00
@Id
@GeneratedValue(strategy = SEQUENCE, generator = "HivesSeqGen")
@Column(name = "hive_id")
private long id;
@Column(name = "hive_name", columnDefinition = "character varying(3)", unique = true)
private String name;
@JoinColumn(name = "inet_addr_id")
@ManyToOne(fetch = EAGER)
private INetAddress inetAddr;
@Column(name = "description", columnDefinition = "character varying(100)")
private String description;
@OneToMany(fetch = LAZY, cascade = ALL, mappedBy = "hive")
@OrderBy("name")
private Set<Pac> pacs;
public Hive() {
2010-10-01 21:52:51 +02:00
}
2010-10-06 15:06:01 +02:00
public Hive(String name, INetAddress inetAddr) {
2010-10-01 21:52:51 +02:00
this.name = name;
this.inetAddr = inetAddr;
}
2010-10-06 15:06:01 +02:00
public Hive(String name, INetAddress inetAddr, String desc) {
2010-10-01 21:52:51 +02:00
this(name, inetAddr);
this.description = desc;
}
2010-10-06 15:06:01 +02:00
public static String createQueryFromStringKey(String humanKey) {
2011-08-29 16:09:20 +02:00
return "obj.hiveName='" + humanKey + "'";
2010-10-01 21:52:51 +02:00
}
@Override
2010-10-06 15:06:01 +02:00
public String createStringKey() {
2010-10-01 21:52:51 +02:00
return getHiveName();
}
@Override
2010-10-06 15:06:01 +02:00
public long id() {
return id;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
2010-10-01 21:52:51 +02:00
@Override
2010-10-06 15:06:01 +02:00
public String getHiveName() {
return name;
}
public void setName(String hiveName) {
this.name = hiveName;
}
public INetAddress getInetAddr() {
return inetAddr;
}
public void setInetAddr(INetAddress inetAddr) {
this.inetAddr = inetAddr;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Set<Pac> getPacs() {
return pacs;
}
public void setPacs(Set<Pac> pacs) {
this.pacs = pacs;
}
@Override
public boolean isNew() {
2010-10-01 21:52:51 +02:00
return id == 0;
}
2010-10-06 15:06:01 +02:00
2010-10-01 21:52:51 +02:00
@Override
2010-10-06 15:06:01 +02:00
public UnixUser owningUser(EntityManager em) {
2010-10-01 21:52:51 +02:00
return null; // TODO: kinda somebody like root needed
}
2013-02-20 17:24:23 +01:00
public String getDefaultGateway() {
String hiveIP = getInetAddr().getInetAddr();
return Config.getInstance().getProperty("hsadmin.default_gateway", hiveIP.substring(0, hiveIP.lastIndexOf('.')) + ".1");
}
2010-10-01 21:52:51 +02:00
}