/* * 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.Lob; 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; import javax.persistence.Transient; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; /** * * @author metz */ @XmlRootElement @Entity @Table(name = "answer") @NamedQueries({ @NamedQuery(name = "Answer.findAll", query = "SELECT a FROM Answer a"), @NamedQuery(name = "Answer.findById", query = "SELECT a FROM Answer a WHERE a.id = :id"), @NamedQuery(name = "Answer.findByUrl", query = "SELECT a FROM Answer a WHERE a.url = :url"), @NamedQuery(name = "Answer.findByTitle", query = "SELECT a FROM Answer a WHERE a.title = :title"), @NamedQuery(name = "Answer.findByAssignment", query = "SELECT a FROM Answer a WHERE a.assignment = :assignment"), @NamedQuery(name = "Answer.findByCreated", query = "SELECT a FROM Answer a WHERE a.created = :created"), @NamedQuery(name = "Answer.findByModified", query = "SELECT a FROM Answer a WHERE a.modified = :modified"), @NamedQuery(name = "Answer.findByCourse", query = "SELECT a FROM Answer a WHERE a.assignment.course = :course")}) public class Answer implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(generator = "AnswerID") @TableGenerator(name="AnswerID", table="id_gen", pkColumnName="ID_NAME", valueColumnName = "ID_VAL", pkColumnValue="LAST_ANSWER", allocationSize=1) @Basic(optional = false) @Column( name = "id" ) private Long id; @Basic(optional = false) @Column(name = "url") private String url = ""; @Column(name = "title") private String title; @Basic(optional = false) @Lob @Column(name = "content") private String content; @Basic(optional = true) @Lob @Column(name = "backup") private String backup; @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; @Transient @XmlElement(name="learner-id") private Long learnerId; @Basic(optional = false) @Column(name = "modified") @Temporal(TemporalType.TIMESTAMP) private Date modified; @Basic(optional = false) @Column(name = "graded") @Temporal(TemporalType.TIMESTAMP) private Date graded; @JoinColumn(name = "assignment", referencedColumnName = "id") @ManyToOne(optional = false) private Assignment assignment; @Transient @XmlElement(name="assignment-id") private Long assignmentId; @Basic(optional = true) @Column(name = "grade") private int grade; @Basic(optional = true) @Lob @Column(name = "feedback") private String feedback; public Answer() { } public Answer(Long id) { this.id = id; } public Answer(Long id, String url, String content, Date created, Date modified, Date graded) { this.id = id; this.url = url; this.content = content; this.created = created; this.modified = modified; this.graded = graded; } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getContent() { return content; } public void setContent(String content) { this.content = content; } public String getBackup() { return backup; } public void setBackup(String backup) { this.backup = backup; } 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 Long getLearnerId() { return learnerId; } public Date getModified() { return modified; } public void setModified(Date modified) { this.modified = modified; } public Date getGraded() { return graded; } public void setGraded(Date graded) { this.graded = graded; } public Assignment getAssignment() { return assignment; } public void setAssignment(Assignment assignemnt) { this.assignment = assignemnt; //Bi-directional answer add to Set if (!assignment.getAnswers().contains(this)) { assignment.addAnswer(this); } } public Long getAssignmentId() { return assignmentId; } public Integer getGrade() { return grade; } public void setGrade(Integer grade) { this.grade = grade; } public String getFeedback() { return feedback; } public void setFeedback(String feedback) { this.feedback = feedback; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || !(o instanceof Answer)) return false; Answer other = (Answer)o; if (id == other.getId()) return true; if (id == null) return false; // equivalence by id return id.equals(other.getId()); } @Override public int hashCode() { if (id != null) { return id.hashCode(); } else { return super.hashCode(); } } @Override public String toString() { return "ee.tlu.htk.dippler.entities.Answer[id=" + id + "]"; } }