1+ package org .baeldung .spring .data .couchbase .model ;
2+
3+ import javax .validation .constraints .NotNull ;
4+ import javax .validation .constraints .Past ;
5+ import javax .validation .constraints .Pattern ;
6+ import javax .validation .constraints .Size ;
7+
8+ import org .joda .time .DateTime ;
9+ import org .springframework .data .annotation .Id ;
10+ import org .springframework .data .annotation .Version ;
11+ import org .springframework .data .couchbase .core .mapping .Document ;
12+
13+ import com .couchbase .client .java .repository .annotation .Field ;
14+
15+ @ Document
16+ public class Student {
17+ private static final String NAME_REGEX = "^[a-zA-Z .'-]+$" ;
18+
19+ @ Id
20+ private String id ;
21+ @ Field
22+ @ NotNull
23+ @ Size (min =1 , max =20 )
24+ @ Pattern (regexp =NAME_REGEX )
25+ private String firstName ;
26+ @ Field
27+ @ NotNull
28+ @ Size (min =1 , max =20 )
29+ @ Pattern (regexp =NAME_REGEX )
30+ private String lastName ;
31+ @ Field
32+ @ Past
33+ private DateTime dateOfBirth ;
34+ @ Field
35+ @ NotNull
36+ private DateTime created ;
37+ @ Field
38+ private DateTime updated ;
39+ @ Version
40+ private long version ;
41+
42+ public Student () {}
43+
44+ public Student (String id , String firstName , String lastName , DateTime dateOfBirth ) {
45+ this .id = id ;
46+ this .firstName = firstName ;
47+ this .lastName = lastName ;
48+ this .dateOfBirth = dateOfBirth ;
49+ }
50+
51+ public String getId () {
52+ return id ;
53+ }
54+ public void setId (String id ) {
55+ this .id = id ;
56+ }
57+ public String getFirstName () {
58+ return firstName ;
59+ }
60+ public void setFirstName (String firstName ) {
61+ this .firstName = firstName ;
62+ }
63+ public String getLastName () {
64+ return lastName ;
65+ }
66+ public void setLastName (String lastName ) {
67+ this .lastName = lastName ;
68+ }
69+ public DateTime getDateOfBirth () {
70+ return dateOfBirth ;
71+ }
72+ public void setDateOfBirth (DateTime dateOfBirth ) {
73+ this .dateOfBirth = dateOfBirth ;
74+ }
75+ public DateTime getCreated () {
76+ return created ;
77+ }
78+ public void setCreated (DateTime created ) {
79+ this .created = created ;
80+ }
81+ public DateTime getUpdated () {
82+ return updated ;
83+ }
84+ public void setUpdated (DateTime updated ) {
85+ this .updated = updated ;
86+ }
87+
88+ @ Override
89+ public int hashCode () {
90+ int hash = 1 ;
91+ if (id != null ) {
92+ hash = hash * 31 + id .hashCode ();
93+ }
94+ if (firstName != null ) {
95+ hash = hash * 31 + firstName .hashCode ();
96+ }
97+ if (lastName != null ) {
98+ hash = hash * 31 + lastName .hashCode ();
99+ }
100+ if (dateOfBirth != null ) {
101+ hash = hash * 31 + dateOfBirth .hashCode ();
102+ }
103+ return hash ;
104+ }
105+
106+ @ Override
107+ public boolean equals (Object obj ) {
108+ if ((obj == null ) || (obj .getClass () != this .getClass ())) return false ;
109+ if (obj == this ) return true ;
110+ Student other = (Student ) obj ;
111+ return this .hashCode () == other .hashCode ();
112+ }
113+ }
0 commit comments