97 lines
2.0 KiB
Java
97 lines
2.0 KiB
Java
package de.ctdo.bunti.model;
|
|
|
|
import javax.persistence.*;
|
|
import java.util.*;
|
|
|
|
|
|
@Entity
|
|
@Table( name = "rooms" )
|
|
public final class Room {
|
|
|
|
private int id;
|
|
private String name;
|
|
private String floor;
|
|
private int xCord;
|
|
private int yCord;
|
|
private List<BuntiDevice> devices = new ArrayList<BuntiDevice>();
|
|
|
|
@Id
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
@Column(name = "ROOM_ID", updatable=false, nullable=false)
|
|
public int getId() {
|
|
return id;
|
|
}
|
|
|
|
public void setId(int id) {
|
|
this.id = id;
|
|
}
|
|
|
|
@Column( name = "roomName")
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
|
|
public void setName(String name) {
|
|
this.name = name;
|
|
}
|
|
|
|
public int getxCord() {
|
|
return xCord;
|
|
}
|
|
|
|
public void setxCord(int xCord) {
|
|
this.xCord = xCord;
|
|
}
|
|
|
|
public int getyCord() {
|
|
return yCord;
|
|
}
|
|
|
|
public void setyCord(int yCord) {
|
|
this.yCord = yCord;
|
|
}
|
|
|
|
|
|
public String getFloor() {
|
|
return floor;
|
|
}
|
|
|
|
public void setFloor(String floor) {
|
|
this.floor = floor;
|
|
}
|
|
|
|
|
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, targetEntity = BuntiDevice.class)
|
|
@JoinTable(name = "ROOM_BUNTIDEVICE",
|
|
joinColumns = { @JoinColumn(name = "ROOM_ID") },
|
|
inverseJoinColumns = { @JoinColumn(name = "BUNTIDEVICE_ID") })
|
|
public List<BuntiDevice> getDevices() {
|
|
return Collections.unmodifiableList(this.devices);
|
|
}
|
|
|
|
public void setDevices(List<BuntiDevice> devices) {
|
|
this.devices = devices;
|
|
}
|
|
|
|
|
|
@Transient
|
|
public boolean addDevice(BuntiDevice device) {
|
|
return getDevices().add(device);
|
|
}
|
|
|
|
@Transient
|
|
public boolean removeDevice(BuntiDevice device) {
|
|
return getDevices().remove(device);
|
|
}
|
|
|
|
@Transient
|
|
public BuntiDevice getDevice(int id) {
|
|
for (BuntiDevice device: getDevices()) {
|
|
if( device.getId() == id) {
|
|
return device;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|