KickJava   Java API By Example, From Geeks To Geeks.

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


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  * This is the abstract superclass for BillingDetails.
9  * <p>
10  * A BillingDetails object is always associated with a single
11  * User and depends on the lifecycle of that user. It represents
12  * one of the billing strategies the User has choosen, usually
13  * one BillingDetails is the default in a collection of many.
14  *
15  * @author Christian Bauer <christian@hibernate.org>
16  */

17 @Entity(access = AccessType.FIELD)
18 @Table(name = "BILLING_DETAILS")
19 @Inheritance(strategy = InheritanceType.JOINED)
20 public abstract class BillingDetails implements Serializable JavaDoc, Comparable JavaDoc {
21
22     @Id(generate = GeneratorType.AUTO)
23     @Column(name = "BILLING_DETAILS_ID")
24     private Long JavaDoc id = null;
25
26     @Version
27     private int version = 0;
28
29     @Column(name = "OWNER_NAME", nullable = false)
30     private String JavaDoc ownerName;
31
32     @ManyToOne
33     @JoinColumn(name = "USER_ID", updatable = false)
34     private User user;
35
36     @Column( nullable = false, updatable = false)
37     private Date JavaDoc created = new Date JavaDoc();
38
39     /**
40      * No-arg constructor for JavaBean tools.
41      */

42     BillingDetails() {}
43
44     /**
45      * Full constructor;
46      */

47     protected BillingDetails(String JavaDoc ownerName, User user) {
48         this.ownerName = ownerName;
49         this.user = user;
50     }
51
52     // ********************** Accessor Methods ********************** //
53

54     public Long JavaDoc getId() { return id; }
55     public int getVersion() { return version; }
56
57     public String JavaDoc getOwnerName() { return ownerName; }
58     public void setOwnerName(String JavaDoc ownerName) { this.ownerName = ownerName; }
59
60     public User getUser() { return user; }
61
62     public Date JavaDoc getCreated() { return created; }
63
64     // ********************** Common Methods ********************** //
65

66     public boolean equals(Object JavaDoc o) {
67         if (this == o) return true;
68         if (!(o instanceof BillingDetails)) return false;
69
70         final BillingDetails billingDetails = (BillingDetails) o;
71
72         if (!getCreated().equals(billingDetails.getCreated())) return false;
73         if (!getOwnerName().equals(billingDetails.getOwnerName())) return false;
74
75         return true;
76     }
77
78     public int hashCode() {
79         int result;
80         result = getCreated().hashCode();
81         result = 29 * result + getOwnerName().hashCode();
82         return result;
83     }
84
85     public int compareTo(Object JavaDoc o) {
86         // Billing Details are simply sorted by creation date
87
if (o instanceof BillingDetails)
88             return getCreated().compareTo( ((BillingDetails)o).getCreated() );
89         return 0;
90     }
91
92     // ********************** Business Methods ********************** //
93

94     /**
95      * Checks if the billing information is correct.
96      * <p>
97      * Check algorithm is implemented in subclasses.
98      *
99      * @return boolean
100      */

101     public abstract boolean isValid();
102
103 }
104
Popular Tags