]> git.mxchange.org Git - addressbook-lib.git/blob - src/org/mxchange/addressbook/model/addressbook/entry/UserAddressbookEntry.java
4ad8484b86d74b945d1b1e94a74c0ccaea928ec4
[addressbook-lib.git] / src / org / mxchange / addressbook / model / addressbook / entry / UserAddressbookEntry.java
1 /*
2  * Copyright (C) 2015 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.addressbook.model.addressbook.entry;
18
19 import java.util.Calendar;
20 import javax.persistence.Basic;
21 import javax.persistence.CascadeType;
22 import javax.persistence.Column;
23 import javax.persistence.Entity;
24 import javax.persistence.GeneratedValue;
25 import javax.persistence.GenerationType;
26 import javax.persistence.Id;
27 import javax.persistence.JoinColumn;
28 import javax.persistence.NamedQueries;
29 import javax.persistence.NamedQuery;
30 import javax.persistence.OneToOne;
31 import javax.persistence.Table;
32 import javax.persistence.Temporal;
33 import javax.persistence.TemporalType;
34 import org.mxchange.addressbook.model.addressbook.Addressbook;
35 import org.mxchange.addressbook.model.addressbook.UserAddressbook;
36 import org.mxchange.jcontacts.contact.Contact;
37 import org.mxchange.jcontacts.contact.UserContact;
38 import org.mxchange.jcontactsbusiness.BusinessContact;
39 import org.mxchange.jcontactsbusiness.CompanyContact;
40 import org.mxchange.jusercore.model.user.LoginUser;
41 import org.mxchange.jusercore.model.user.User;
42
43 /**
44  * A POJO for address book entries
45  * <p>
46  * @author Roland Haeder
47  */
48 @Entity (name = "addressbook_entries")
49 @Table (name = "addressbook_entries")
50 @NamedQueries (
51                 @NamedQuery (
52                                 name = "AllAddressbookEntries",
53                                 query = "SELECT e FROM addressbook_entries AS e WHERE e.addressbookId = :addressbook AND (e.addressbookEntryUserOwner = :owner OR e.addressbookEntryUserSharer = :sharer) ORDER BY e.addressbookEntryId ASC")
54 )
55 public class UserAddressbookEntry implements AddressbookEntry, Comparable<AddressbookEntry> {
56
57         /**
58          * Serial number
59          */
60         private static final long serialVersionUID = 178_581_768_581_960L;
61
62         /**
63          * Connection to table "business_contacts" (commercial contacts)
64          */
65         @JoinColumn (name = "entry_business_contact_id", updatable = false)
66         @OneToOne (targetEntity = CompanyContact.class, cascade = CascadeType.ALL)
67         private BusinessContact addressbookEntryBusinessContact;
68
69         /**
70          * When this address book entry has been created
71          */
72         @Basic (optional = false)
73         @Temporal (TemporalType.TIMESTAMP)
74         @Column (name = "entry_created", nullable = false, updatable = false)
75         private Calendar addressbookEntryCreated;
76
77         /**
78          * Id number
79          */
80         @Id
81         @GeneratedValue (strategy = GenerationType.IDENTITY)
82         @Column (name = "entry_id", nullable = false, updatable = false)
83         private Long addressbookEntryId;
84
85         /**
86          * Connection to table "contacts" (private contacts)
87          */
88         @JoinColumn (name = "entry_private_contact_id", updatable = false)
89         @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.ALL)
90         private Contact addressbookEntryPrivateContact;
91
92         /**
93          * Connection to table "users" (who has initially created this entry
94          */
95         @JoinColumn (name = "entry_owner_user_id", nullable = false, updatable = false)
96         @OneToOne (targetEntity = LoginUser.class, optional = false, cascade = CascadeType.ALL)
97         private User addressbookEntryUserOwner;
98
99         /**
100          * Connection to table "users" (who has added this entry)
101          */
102         @JoinColumn (name = "entry_sharer_user_id", updatable = false)
103         @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.ALL)
104         private User addressbookEntryUserSharer;
105
106         /**
107          * Connection to table "addressbooks"
108          */
109         @JoinColumn (name = "addressbook_id", nullable = false, updatable = false)
110         @OneToOne (targetEntity = UserAddressbook.class, optional = false, cascade = CascadeType.ALL)
111         private Addressbook addressbookId;
112
113         @Override
114         public int compareTo (final AddressbookEntry addressbookEntry) {
115                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
116         }
117
118         @Override
119         public BusinessContact getAddressbookEntryBusinessContact () {
120                 return this.addressbookEntryBusinessContact;
121         }
122
123         @Override
124         public void setAddressbookEntryBusinessContact (final BusinessContact addressbookEntryBusinessContact) {
125                 this.addressbookEntryBusinessContact = addressbookEntryBusinessContact;
126         }
127
128         @Override
129         public Calendar getAddressbookEntryCreated () {
130                 return this.addressbookEntryCreated;
131         }
132
133         @Override
134         public void setAddressbookEntryCreated (final Calendar addressbookEntryCreated) {
135                 this.addressbookEntryCreated = addressbookEntryCreated;
136         }
137
138         @Override
139         public Long getAddressbookEntryId () {
140                 return this.addressbookEntryId;
141         }
142
143         @Override
144         public void setAddressbookEntryId (final Long addressbookEntryId) {
145                 this.addressbookEntryId = addressbookEntryId;
146         }
147
148         @Override
149         public Contact getAddressbookEntryPrivateContact () {
150                 return this.addressbookEntryPrivateContact;
151         }
152
153         @Override
154         public void setAddressbookEntryPrivateContact (final Contact addressbookEntryPrivateContact) {
155                 this.addressbookEntryPrivateContact = addressbookEntryPrivateContact;
156         }
157
158         @Override
159         public User getAddressbookEntryUserSharer () {
160                 return this.addressbookEntryUserSharer;
161         }
162
163         @Override
164         public void setAddressbookEntryUserSharer (final User addressbookEntryUserSharer) {
165                 this.addressbookEntryUserSharer = addressbookEntryUserSharer;
166         }
167
168         @Override
169         public User getAddressbookEntryUserOwner () {
170                 return this.addressbookEntryUserOwner;
171         }
172
173         @Override
174         public void setAddressbookEntryUserOwner (final User addressbookEntryUserOwner) {
175                 this.addressbookEntryUserOwner = addressbookEntryUserOwner;
176         }
177
178         @Override
179         public Addressbook getAddressbookId () {
180                 return this.addressbookId;
181         }
182
183         @Override
184         public void setAddressbookId (final Addressbook addressbookId) {
185                 this.addressbookId = addressbookId;
186         }
187
188 }