/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package ee.tlu.htk.dippler.entities; import java.io.Serializable; import java.util.Collection; import java.util.Date; import java.util.Iterator; import javax.persistence.Basic; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.Lob; import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.OneToMany; import javax.persistence.Table; import javax.persistence.TableGenerator; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; /** * * @author metz */ @XmlRootElement @Entity @Table(name = "coursegroup") @NamedQueries({ @NamedQuery(name = "Coursegroup.findAll", query = "SELECT c FROM Coursegroup c"), @NamedQuery(name = "Coursegroup.findById", query = "SELECT c FROM Coursegroup c WHERE c.id = :id"), @NamedQuery(name = "Coursegroup.findByTitle", query = "SELECT c FROM Coursegroup c WHERE c.title = :title"), @NamedQuery(name = "Coursegroup.findByCourse", query = "SELECT c FROM Coursegroup c WHERE c.course = :course") }) public class Coursegroup implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(generator = "CourseGroupID") @TableGenerator(name="CourseGroupID", table="id_gen", pkColumnName="ID_NAME", valueColumnName = "ID_VAL", pkColumnValue="LAST_COURSE_GROUP", allocationSize=1) @Basic(optional = false) @Column(name = "id") private Long id; @Column(name = "title") private String title; @Lob @Column(name = "description") private String description; @Column(name = "workspace") private String workspace; @Basic(optional = false) @Column(name = "created") @Temporal(TemporalType.TIMESTAMP) private Date created; @JoinColumn(name = "creator", referencedColumnName = "id") @ManyToOne(optional = false, fetch = FetchType.LAZY) private User creator; @OneToMany (cascade= CascadeType.MERGE) @JoinTable(name = "coursegroup_member", joinColumns = { @JoinColumn(name = "coursegroup", referencedColumnName = "id")}, inverseJoinColumns = { @JoinColumn(name = "learner", referencedColumnName = "id")}) private Collection members; @JoinTable(name = "assignment_target_group", joinColumns = { @JoinColumn(name = "coursegroup_id", referencedColumnName = "id")}, inverseJoinColumns = { @JoinColumn(name = "assignment_id", referencedColumnName = "id")}) @ManyToMany private Collection assignments; @JoinColumn(name = "course", referencedColumnName = "id") @ManyToOne(optional = false) private Course course; @Transient @XmlElement(name="course-id") private Long courseId; @Transient @XmlElementWrapper(name="member-ids") @XmlElement(name="member-id") public Collection memberIds; public Coursegroup() { } public Coursegroup(Long id) { this.id = id; } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String getWorkspace() { return workspace; } public void setWorkspace(String workspace) { this.workspace = workspace; } public Date getCreated() { return created; } public void setCreated(Date created) { this.created = created; } public User getCreator() { return creator; } public void setCreator(User user) { this.creator = user; } public Collection getMembers() { return members; } public void setMembers(Collection userCollection) { this.members = userCollection; } public Course getCourse() { return course; } public void setCourse(Course course) { this.course = course; if ( !this.course.getGroups().contains(this) ) { this.course.addGroup(this); } } public Long getCourseId() { return courseId; } /* public Collection getMemberIds() { return memberIds; }*/ public void setMemberIds(Collection id) { this.memberIds = id; } @Override public int hashCode() { int hash = 0; hash += (id != null ? id.hashCode() : 0); return hash; } @Override public boolean equals(Object object) { // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof Coursegroup)) { return false; } Coursegroup other = (Coursegroup) object; if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { return false; } return true; } @Override public String toString() { return "ee.tlu.htk.dippler.entities.Coursegroup[id=" + id + "]"; } }