package tudu.domain.model; import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; import org.hibernate.annotations.GenericGenerator; import javax.persistence.*; import java.io.Serializable; import java.util.Date; /** * A Todo. * * @author Julien Dubois */ @Entity @Table(name = "todo") @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) public class Todo implements Serializable, Comparable<Todo> { /** * The serialVersionUID. */ private static final long serialVersionUID = 4048798961366546485L; @Id @Column(name = "id") @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") private String todoId; @ManyToOne private TodoList todoList; private Date creationDate; private String description; private int priority; private boolean completed; private Date completionDate; private Date dueDate; @ManyToOne private User assignedUser; /** * The length of this field is 10000, which is OK with MySQL but which will * cause trouble with other databases (Oracle is limited at 4000 characters, * SQL Server at 8000). */ @Basic(fetch = FetchType.LAZY) @Column(length = 10000) private String notes; private boolean hasNotes; public String getTodoId() { return todoId; } public void setTodoId(String todoId) { this.todoId = todoId; } public boolean isCompleted() { return completed; } public void setCompleted(boolean completed) { this.completed = completed; } public Date getCompletionDate() { return completionDate; } public void setCompletionDate(Date completionDate) { this.completionDate = completionDate; } public Date getCreationDate() { return creationDate; } public void setCreationDate(Date creationDate) { this.creationDate = creationDate; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public Date getDueDate() { return dueDate; } public void setDueDate(Date dueDate) { this.dueDate = dueDate; } public int getPriority() { return priority; } public void setPriority(int priority) { this.priority = priority; } public User getAssignedUser() { return assignedUser; } public void setAssignedUser(User assignedUser) { this.assignedUser = assignedUser; } public boolean isHasNotes() { return hasNotes; } public void setHasNotes(boolean hasNotes) { this.hasNotes = hasNotes; } public String getNotes() { return notes; } public void setNotes(String notes) { this.notes = notes; } public TodoList getTodoList() { return todoList; } public void setTodoList(TodoList todoList) { this.todoList = todoList; } public int compareTo(Todo that) { int order = that.getPriority() - this.getPriority(); if (this.isCompleted()) { order += 10000; } if (that.isCompleted()) { order -= 10000; } if (order == 0) { order = (this.getDescription() + this.getTodoId()).compareTo(that .getDescription() + that.getTodoId()); } return order; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof Todo)) { return false; } final Todo todo = (Todo) o; if (todoId != null ? !todoId.equals(todo.todoId) : todo.todoId != null) { return false; } return true; } @Override public int hashCode() { return (todoId != null ? todoId.hashCode() : 0); } }