KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
9  * An immutable class representing one bid.
10  *
11  * @see Item
12  * @see User
13  * @author Christian Bauer <christian@hibernate.org>
14  */

15 @Entity(access = AccessType.FIELD)
16 @Table(name = "BID")
17 @org.hibernate.annotations.Entity(mutable = false)
18 public class Bid implements Serializable JavaDoc, Comparable JavaDoc {
19
20     @Id(generate = GeneratorType.AUTO)
21     @Column(name = "CAT_ID")
22     private Long JavaDoc id = null;
23
24     @org.hibernate.annotations.Type(type = "monetary_amount_usd")
25     @org.hibernate.annotations.Columns( columns = {
26             @Column( name="AMOUNT"),
27             @Column( name="AMOUNT_CURRENCY", length = 2)
28             }
29     )
30     private MonetaryAmount amount;
31
32     @ManyToOne()
33     @JoinColumn(name = "ITEM_ID", nullable = false)
34     private Item item;
35
36     @ManyToOne()
37     @JoinColumn(name = "BIDDER_ID", nullable = false)
38     private User bidder;
39
40     @Column( nullable = false, updatable = false)
41     private Date JavaDoc created = new Date JavaDoc();
42
43     /**
44      * No-arg constructor for JavaBean tools.
45      */

46     Bid() {}
47
48     /**
49      * Full constructor.
50      *
51      * @param amount
52      * @param item
53      * @param bidder
54      */

55
56     public Bid(MonetaryAmount amount, Item item, User bidder) {
57         this.amount = amount;
58         this.item = item;
59         this.bidder = bidder;
60     }
61
62     // ********************** Accessor Methods ********************** //
63

64     public Long JavaDoc getId() { return id; }
65
66     public MonetaryAmount getAmount() { return amount; }
67     public Item getItem() { return item; }
68     public User getBidder() { return bidder; }
69     public Date JavaDoc getCreated() { return created; }
70
71     // ********************** Common Methods ********************** //
72

73     public boolean equals(Object JavaDoc o) {
74         if (this == o) return true;
75         if (!(o instanceof Bid)) return false;
76
77         final Bid bid = (Bid) o;
78
79         if (!amount.equals(bid.amount)) return false;
80         if (!created.equals(bid.created)) return false;
81
82         return true;
83     }
84
85     public int hashCode() {
86         int result;
87         result = amount.hashCode();
88         result = 29 * result + created.hashCode();
89         return result;
90     }
91
92     public String JavaDoc toString() {
93         return "Bid ('" + getId() + "'), " +
94                 "Created: '" + getCreated() + "' " +
95                 "Amount: '" + getAmount() + "'";
96     }
97
98     public int compareTo(Object JavaDoc o) {
99         if (o instanceof Bid) {
100             return this.getCreated().compareTo( ((Bid)o).getCreated() );
101         }
102         return 0;
103     }
104
105     // ********************** Business Methods ********************** //
106

107
108 }
Popular Tags