/* * 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.Date; import javax.persistence.Basic; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.Table; import javax.persistence.TableGenerator; import javax.persistence.Temporal; import javax.persistence.TemporalType; /** * * @author aili */ @Entity @Table(name = "activity") @NamedQueries({ @NamedQuery(name = "Activity.findAll", query = "SELECT a FROM Activity a"), @NamedQuery(name = "Activity.findById", query = "SELECT a FROM Activity a WHERE a.id = :id"), @NamedQuery(name = "Activity.findByCourseTitle", query = "SELECT a FROM Activity a WHERE a.courseTitle = :courseTitle"), @NamedQuery(name = "Activity.findByEvent", query = "SELECT a FROM Activity a WHERE a.event = :event"), @NamedQuery(name = "Activity.findByObjectId", query = "SELECT a FROM Activity a WHERE a.objectId = :objectId"), @NamedQuery(name = "Activity.findByObjectTitle", query = "SELECT a FROM Activity a WHERE a.objectTitle = :objectTitle"), @NamedQuery(name = "Activity.findByObjectType", query = "SELECT a FROM Activity a WHERE a.objectType = :objectType"), @NamedQuery(name = "Activity.findByCreatorFullname", query = "SELECT a FROM Activity a WHERE a.creatorFullname = :creatorFullname"), @NamedQuery(name = "Activity.findByCreated", query = "SELECT a FROM Activity a WHERE a.created = :created")}) public class Activity implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(generator = "ActivityID") @TableGenerator(name="ActivityID", table="id_gen", pkColumnName="ID_NAME", valueColumnName = "ID_VAL", pkColumnValue="LAST_ACTIVITY", allocationSize=1) @Basic(optional = false) @Column( name = "id" ) private Long id; @JoinColumn(name="course", referencedColumnName = "id") @ManyToOne(optional=false, fetch = FetchType.LAZY) private Course course; @Column(name = "course_title") private String courseTitle; @Column(name = "event") private String event; @Column(name = "object_id") private Long objectId; @Column(name = "object_title") private String objectTitle; @Column(name = "object_type") private String objectType; @JoinColumn(name = "creator", referencedColumnName = "id") @ManyToOne(optional = false, fetch = FetchType.LAZY) private User creator; @Column(name = "creator_fullname") private String creatorFullname; @Basic(optional = false) @Column(name = "created") @Temporal(TemporalType.TIMESTAMP) private Date created; public Activity() { created = new Date(); //Set created timestamp on construct } public Activity(Long id) { this.id = id; } public Activity(Long id, Date created) { this.id = id; this.created = created; } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public Course getCourse() { return course; } public void setCourse(Course course) { this.course = course; if ( !this.course.getActivities().contains(this) ) { course.addActivity(this); } } public String getCourseTitle() { return courseTitle; } public void setCourseTitle(String courseTitle) { this.courseTitle = courseTitle; } public String getEvent() { return event; } public void setEvent(String event) { this.event = event; } public Long getObjectId() { return objectId; } public void setObjectId(Long objectId) { this.objectId = objectId; } public String getObjectTitle() { return objectTitle; } public void setObjectTitle(String objectTitle) { this.objectTitle = objectTitle; } public String getObjectType() { return objectType; } public void setObjectType(String objectType) { this.objectType = objectType; } public User getCreator() { return creator; } public void setCreator(User creator) { this.creator = creator; } public String getCreatorFullname() { return creatorFullname; } public void setCreatorFullname(String creatorFullname) { this.creatorFullname = creatorFullname; } public Date getCreated() { return created; } public void setCreated(Date created) { this.created = created; } @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 Activity)) { return false; } Activity other = (Activity) 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.Activity[id=" + id + "]"; } }