forked from ebean-orm/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomer.java
More file actions
137 lines (107 loc) · 3 KB
/
Copy pathCustomer.java
File metadata and controls
137 lines (107 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package org.example.domain;
import io.ebean.annotation.DbArray;
import io.ebean.annotation.DbComment;
import org.example.domain.finder.CustomerFinder;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
* Customer entity bean.
*
* This example shows an entity bean without a default constructor. The name property is
* expected to be final and non-null. Note the InsertCustomerTest.testRef() test showing
* loading the partially loaded bean.
*/
@DbComment("Customer table general comment")
@Entity
@Table(name="customer")
public class Customer extends BaseModel {
public static final CustomerFinder find = new CustomerFinder();
boolean inactive;
@NotNull
@Column(unique = true)
@Size(min = 1, max = 100)
String name;
@DbComment("The date the customer first registered")
LocalDate registered;
@DbArray // Postgres ARRAY
List<UUID> uids = new ArrayList<>();
@Lob
String comments;
@ManyToOne(cascade=CascadeType.ALL)
Address billingAddress;
@ManyToOne(cascade=CascadeType.ALL)
Address shippingAddress;
@OneToMany(mappedBy="customer", cascade=CascadeType.PERSIST)
List<Contact> contacts;
public Customer(String name) {
this.name = name;
}
public String toString() {
return "id:" + id + " name:" + name;
}
public boolean isInactive() {
return inactive;
}
public void setInactive(boolean inactive) {
this.inactive = inactive;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public LocalDate getRegistered() {
return registered;
}
public void setRegistered(LocalDate registered) {
this.registered = registered;
}
public String getComments() {
return comments;
}
public void setComments(String comments) {
this.comments = comments;
}
public Address getBillingAddress() {
return billingAddress;
}
public void setBillingAddress(Address billingAddress) {
this.billingAddress = billingAddress;
}
public Address getShippingAddress() {
return shippingAddress;
}
public void setShippingAddress(Address shippingAddress) {
this.shippingAddress = shippingAddress;
}
public List<Contact> getContacts() {
return contacts;
}
public void setContacts(List<Contact> contacts) {
this.contacts = contacts;
}
/**
* Helper method to add a contact to the customer.
*/
public void addContact(Contact contact) {
if (contacts == null) {
contacts = new ArrayList<>();
}
// setting the customer is automatically done when Ebean does
// a cascade save from customer to contacts.
contact.setCustomer(this);
contacts.add(contact);
}
}