2 * Copyright (C) 2016 Roland Haeder
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.
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.
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/>.
17 package org.mxchange.jaddressbookcore.model.addressbook;
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.EnumType;
26 import javax.persistence.Enumerated;
27 import javax.persistence.GeneratedValue;
28 import javax.persistence.GenerationType;
29 import javax.persistence.Id;
30 import javax.persistence.JoinColumn;
31 import javax.persistence.Lob;
32 import javax.persistence.NamedQueries;
33 import javax.persistence.NamedQuery;
34 import javax.persistence.OneToOne;
35 import javax.persistence.Table;
36 import javax.persistence.Temporal;
37 import javax.persistence.TemporalType;
38 import org.mxchange.jaddressbookcore.model.addressbook.status.AddressbokStatus;
39 import org.mxchange.jusercore.model.user.User;
42 * A POJO for user addressbooks
44 * @author Roland Haeder<roland@mxchange.org>
46 @Entity (name = "addressbooks")
47 @Table (name = "addressbooks")
50 @NamedQuery (name = "AllUsersAddressbooks", query = "SELECT a FROM addressbooks AS a WHERE a.addressbookUser = :param ORDER BY a.addressbookId ASC"),
51 @NamedQuery (name = "SearchUserAddressbookName", query = "SELECT a FROM addressbooks AS a WHERE a.addressbookUser = :user AND LOWER(a.addressbookName) LIKE LOWER(:name)"),
52 @NamedQuery (name = "SearchAddressbookById", query = "SELECT a FROM addressbooks AS a WHERE a.addressbookId = :id")
55 public class UserAddressbook implements Addressbook {
60 private static final long serialVersionUID = 176_573_148_678_169L;
63 * When this address book has been created
65 @Basic (optional = false)
66 @Temporal (value = TemporalType.TIMESTAMP)
67 @Column (name = "addressbook_created", nullable = false, updatable = false)
68 private Calendar addressbookCreated;
74 @GeneratedValue (strategy = GenerationType.IDENTITY)
75 @Column (name = "addressbook_id", nullable = false, updatable = false)
76 private Long addressbookId;
79 * Last locked timestamp
81 @Temporal (TemporalType.TIMESTAMP)
82 @Column (name = "addressbook_last_locked")
83 private Calendar addressbookLastLocked;
86 * Last locked timestamp
89 @Column (name = "addressbook_last_locked_reason")
90 private String addressbookLastLockedReason;
93 * Name for this address book
95 @Basic (optional = false)
96 @Column (name = "addressbook_name", length = 50, nullable = false)
97 private String addressbookName;
102 @Basic (optional = false)
103 @Enumerated (EnumType.STRING)
104 @Column (name = "addressbook_status", nullable = false, length = 10)
105 private AddressbokStatus addressbookStatus;
108 * Connection to "users" table
110 @JoinColumn (name = "addressbook_user_id", nullable = false)
111 @OneToOne (targetEntity = User.class, cascade = CascadeType.REFRESH, optional = false)
112 private User addressbookUser;
115 * Public constructor with address book name
117 * @param addressbookName Address book name
118 * @param addressbookUser User instance
120 public UserAddressbook (final String addressbookName, final User addressbookUser) {
121 // Call default constructor
124 // Set name and user instance
125 this.addressbookName = addressbookName;
126 this.addressbookUser = addressbookUser;
130 * Default constructor
132 public UserAddressbook () {
133 // Set status to UNLOCKED
134 this.addressbookStatus = AddressbokStatus.UNLOCKED;
138 public boolean equals (final Object object) {
139 if (null == object) {
141 } else if (this.getClass() != object.getClass()) {
145 final Addressbook other = (Addressbook) object;
147 if (!Objects.equals(this.getAddressbookName(), other.getAddressbookName())) {
149 } else if (!Objects.equals(this.getAddressbookUser(), other.getAddressbookUser())) {
157 public int hashCode () {
159 hash = 59 * hash + Objects.hashCode(this.getAddressbookName());
160 hash = 59 * hash + Objects.hashCode(this.getAddressbookUser());
165 public Calendar getAddressbookCreated () {
166 return this.addressbookCreated;
170 public void setAddressbookCreated (final Calendar addressbookCreated) {
171 this.addressbookCreated = addressbookCreated;
175 public Long getAddressbookId () {
176 return this.addressbookId;
180 public void setAddressbookId (final Long addressbookId) {
181 this.addressbookId = addressbookId;
185 public Calendar getAddressbookLastLocked () {
186 return this.addressbookLastLocked;
190 public void setAddressbookLastLocked (final Calendar addressbookLastLocked) {
191 this.addressbookLastLocked = addressbookLastLocked;
195 public String getAddressbookLastLockedReason () {
196 return this.addressbookLastLockedReason;
200 public void setAddressbookLastLockedReason (final String addressbookLastLockedReason) {
201 this.addressbookLastLockedReason = addressbookLastLockedReason;
205 public String getAddressbookName () {
206 return this.addressbookName;
210 public void setAddressbookName (final String addressbookName) {
211 this.addressbookName = addressbookName;
215 public AddressbokStatus getAddressbookStatus () {
216 return this.addressbookStatus;
220 public void setAddressbookStatus (final AddressbokStatus addressbookStatus) {
221 this.addressbookStatus = addressbookStatus;
225 public User getAddressbookUser () {
226 return this.addressbookUser;
230 public void setAddressbookUser (final User addressbookUser) {
231 this.addressbookUser = addressbookUser;