]> git.mxchange.org Git - jaddressbook-core.git/blob - src/org/mxchange/jaddressbookcore/model/addressbook/entry/UserAddressbookEntry.java
aa005448522233b5cb7ca89bf5785545d820b799
[jaddressbook-core.git] / src / org / mxchange / jaddressbookcore / model / addressbook / entry / UserAddressbookEntry.java
1 /*
2  * Copyright (C) 2016 Roland Haeder
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.jaddressbookcore.model.addressbook.entry;
18
19 import java.util.Calendar;
20 import java.util.Objects;
21 import javax.persistence.Basic;
22 import javax.persistence.CascadeType;
23 import javax.persistence.Column;
24 import javax.persistence.Entity;
25 import javax.persistence.GeneratedValue;
26 import javax.persistence.GenerationType;
27 import javax.persistence.Id;
28 import javax.persistence.JoinColumn;
29 import javax.persistence.NamedQueries;
30 import javax.persistence.NamedQuery;
31 import javax.persistence.OneToOne;
32 import javax.persistence.Table;
33 import javax.persistence.Temporal;
34 import javax.persistence.TemporalType;
35 import org.mxchange.jaddressbookcore.model.addressbook.Addressbook;
36 import org.mxchange.jcontacts.contact.Contact;
37 import org.mxchange.jcontactsbusiness.BusinessContact;
38
39 /**
40  * A POJO for address book entries
41  * <p>
42  * @author Roland Haeder<roland@mxchange.org>
43  */
44 @Entity (name = "addressbook_entries")
45 @Table (name = "addressbook_entries")
46 @NamedQueries (
47                 @NamedQuery (
48                                 name = "SearchUsersAddressbookEntries",
49                                 query = "SELECT e FROM addressbook_entries AS e INNER JOIN addressbooks AS a ON e.addressbookId = a WHERE e.addressbookId = :addressbook AND a.addressbookUser = :owner ORDER BY e.addressbookEntryId ASC")
50 )
51 @SuppressWarnings ("PersistenceUnitPresent")
52 public class UserAddressbookEntry implements AddressbookEntry {
53
54         /**
55          * Serial number
56          */
57         private static final long serialVersionUID = 178_581_768_581_960L;
58
59         /**
60          * Connection to table "business_contacts" (commercial contacts)
61          */
62         @JoinColumn (name = "entry_business_contact_id", updatable = false)
63         @OneToOne (targetEntity = BusinessContact.class, cascade = CascadeType.REFRESH)
64         private BusinessContact addressbookEntryBusinessContact;
65
66         /**
67          * When this address book entry has been created
68          */
69         @Basic (optional = false)
70         @Temporal (TemporalType.TIMESTAMP)
71         @Column (name = "entry_created", nullable = false, updatable = false)
72         private Calendar addressbookEntryCreated;
73
74         /**
75          * Id number
76          */
77         @Id
78         @GeneratedValue (strategy = GenerationType.IDENTITY)
79         @Column (name = "entry_id", nullable = false, updatable = false)
80         private Long addressbookEntryId;
81
82         /**
83          * Connection to table "contacts" (private contacts)
84          */
85         @JoinColumn (name = "entry_private_contact_id", updatable = false)
86         @OneToOne (targetEntity = Contact.class, cascade = CascadeType.REFRESH)
87         private Contact addressbookEntryPrivateContact;
88
89         /**
90          * Connection to table "addressbooks"
91          */
92         @JoinColumn (name = "entry_addressbook_id", nullable = false, updatable = false)
93         @OneToOne (targetEntity = Addressbook.class, cascade = CascadeType.REFRESH, optional = false)
94         private Addressbook addressbookId;
95
96         @Override
97         public boolean equals (final Object object) {
98                 if (null == object) {
99                         return false;
100                 } else if (this.getClass() != object.getClass()) {
101                         return false;
102                 }
103
104                 final AddressbookEntry other = (AddressbookEntry) object;
105
106                 if (!Objects.equals(this.getAddressbookEntryBusinessContact(), other.getAddressbookEntryBusinessContact())) {
107                         return false;
108                 } else if (!Objects.equals(this.getAddressbookEntryPrivateContact(), other.getAddressbookEntryPrivateContact())) {
109                         return false;
110                 } else if (!Objects.equals(this.getAddressbookId(), other.getAddressbookId())) {
111                         return false;
112                 }
113
114                 return true;
115         }
116
117         @Override
118         public int hashCode () {
119                 int hash = 3;
120
121                 hash = 19 * hash + Objects.hashCode(this.getAddressbookEntryBusinessContact());
122                 hash = 19 * hash + Objects.hashCode(this.getAddressbookEntryPrivateContact());
123                 hash = 19 * hash + Objects.hashCode(this.getAddressbookId());
124
125                 return hash;
126         }
127
128         @Override
129         public BusinessContact getAddressbookEntryBusinessContact () {
130                 return this.addressbookEntryBusinessContact;
131         }
132
133         @Override
134         public void setAddressbookEntryBusinessContact (final BusinessContact addressbookEntryBusinessContact) {
135                 this.addressbookEntryBusinessContact = addressbookEntryBusinessContact;
136         }
137
138         @Override
139         @SuppressWarnings ("ReturnOfDateField")
140         public Calendar getAddressbookEntryCreated () {
141                 return this.addressbookEntryCreated;
142         }
143
144         @Override
145         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
146         public void setAddressbookEntryCreated (final Calendar addressbookEntryCreated) {
147                 this.addressbookEntryCreated = addressbookEntryCreated;
148         }
149
150         @Override
151         public Long getAddressbookEntryId () {
152                 return this.addressbookEntryId;
153         }
154
155         @Override
156         public void setAddressbookEntryId (final Long addressbookEntryId) {
157                 this.addressbookEntryId = addressbookEntryId;
158         }
159
160         @Override
161         public Contact getAddressbookEntryPrivateContact () {
162                 return this.addressbookEntryPrivateContact;
163         }
164
165         @Override
166         public void setAddressbookEntryPrivateContact (final Contact addressbookEntryPrivateContact) {
167                 this.addressbookEntryPrivateContact = addressbookEntryPrivateContact;
168         }
169
170         @Override
171         public Addressbook getAddressbookId () {
172                 return this.addressbookId;
173         }
174
175         @Override
176         public void setAddressbookId (final Addressbook addressbookId) {
177                 this.addressbookId = addressbookId;
178         }
179
180 }