KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > ce > auction > model > Comment


1 package org.hibernate.ce.auction.model;
2
3 import javax.persistence.*;
4 import java.io.Serializable JavaDoc;
5 import java.util.Date JavaDoc;
6
7 /**
8  * An immutable class representing a comment from users.
9  * <p>
10  * Comments are always made in the context of an auction, that
11  * is, a comment has a reference to an Item. The comment has
12  * a free text field and a rating (using a typesafe enumeration).
13  *
14  * @see Item
15  * @see User
16  * @see Rating
17  * @author Christian Bauer <christian@hibernate.org>
18  */

19 @Entity(access = AccessType.FIELD)
20 @Table(name = "COMMENT")
21 public class Comment implements Serializable JavaDoc, Comparable JavaDoc {
22
23     @Id(generate = GeneratorType.AUTO)
24     @Column(name = "COMMENT_ID")
25     private Long JavaDoc id = null;
26
27     @Version
28     private int version = 0;
29
30     //TODO: Test if this really works
31
@org.hibernate.annotations.Type(type = "rating")
32     @Column(name = "RATING", nullable = false)
33     private Rating rating;
34
35     @Column(length = 4000, updatable = false)
36     private String JavaDoc text;
37
38     @ManyToOne
39     @JoinColumn(name = "FROM_USER_ID", nullable = false, updatable = false)
40     private User fromUser;
41
42     @ManyToOne
43     @JoinColumn(name = "ABOUT_ITEM_ID", nullable = false, updatable = false)
44     private Item item;
45
46     @Column( nullable = false, updatable = false)
47     private Date JavaDoc created = new Date JavaDoc();
48
49     /**
50      * No-arg constructor for JavaBean tools.
51      */

52     Comment() {}
53
54     /**
55      * Full constructor.
56      *
57      * @param rating
58      * @param text
59      * @param fromUser
60      * @param item
61      */

62     public Comment(Rating rating, String JavaDoc text, User fromUser, Item item) {
63         this.rating = rating;
64         this.text = text;
65         this.fromUser = fromUser;
66         this.item = item;
67     }
68
69     // ********************** Accessor Methods ********************** //
70

71     public Long JavaDoc getId() { return id; }
72     public int getVersion() { return version; }
73
74     public Rating getRating() { return rating; }
75
76     public String JavaDoc getText() { return text; }
77     public void setText(String JavaDoc text) {
78         this.text = text;
79     }
80
81     public User getFromUser() { return fromUser; }
82
83     public Item getItem() { return item; }
84
85     public Date JavaDoc getCreated() { return created; }
86
87     // ********************** Common Methods ********************** //
88

89     public boolean equals(Object JavaDoc o) {
90         if (this == o) return true;
91         if (!(o instanceof Comment)) return false;
92
93         final Comment comment = (Comment) o;
94
95         if (!created.equals(comment.created)) return false;
96         if (!rating.equals(comment.rating)) return false;
97         if (text != null ? !text.equals(comment.text) : comment.text != null) return false;
98
99         return true;
100     }
101
102     public int hashCode() {
103         int result;
104         result = rating.hashCode();
105         result = 29 * result + (text != null ? text.hashCode() : 0);
106         result = 29 * result + created.hashCode();
107         return result;
108     }
109
110     public String JavaDoc toString() {
111         return "Comment ('" + getId() + "'), " +
112                 "Rating: '" + getRating() + "'";
113     }
114
115     public int compareTo(Object JavaDoc o) {
116         if (o instanceof Comment) {
117             return this.getCreated().compareTo(((Comment) o).getCreated());
118         }
119         return 0;
120     }
121
122     // ********************** Business Methods ********************** //
123

124 }
125
Popular Tags