2 * Copyright (C) 2016, 2017 Free Software Foundation
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.jaddressbook.model.addressbook;
19 import java.util.Date;
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 javax.persistence.Transient;
39 import org.mxchange.jaddressbook.model.addressbook.status.AddressbokStatus;
40 import org.mxchange.jusercore.model.user.LoginUser;
41 import org.mxchange.jusercore.model.user.User;
44 * A POJO for user addressbooks
46 * @author Roland Häder<roland@mxchange.org>
48 @Entity (name = "addressbooks")
49 @Table (name = "addressbooks")
52 @NamedQuery (name = "AllUsersAddressbooks", query = "SELECT a FROM addressbooks AS a WHERE a.addressbookUser = :param ORDER BY a.addressbookId ASC"),
53 @NamedQuery (name = "SearchUserAddressbookName", query = "SELECT a FROM addressbooks AS a WHERE a.addressbookUser = :user AND LOWER(a.addressbookName) LIKE LOWER(:name)"),
56 @SuppressWarnings ("PersistenceUnitPresent")
57 public class UserAddressbook implements Addressbook {
63 private static final long serialVersionUID = 176_573_148_678_169L;
66 * When this address book has been created
68 @Basic (optional = false)
69 @Temporal (value = TemporalType.TIMESTAMP)
70 @Column (name = "addressbook_created", nullable = false, updatable = false)
71 private Date addressbookCreated;
77 @GeneratedValue (strategy = GenerationType.IDENTITY)
78 @Column (name = "addressbook_id", nullable = false, updatable = false)
79 private Long addressbookId;
82 * Last locked timestamp
84 @Temporal (TemporalType.TIMESTAMP)
85 @Column (name = "addressbook_last_locked")
86 private Date addressbookLastLocked;
89 * Last locked timestamp
92 @Column (name = "addressbook_last_locked_reason")
93 private String addressbookLastLockedReason;
96 * Name for this address book
98 @Basic (optional = false)
99 @Column (name = "addressbook_name", length = 50, nullable = false)
100 private String addressbookName;
105 @Basic (optional = false)
106 @Enumerated (EnumType.STRING)
107 @Column (name = "addressbook_status", nullable = false, length = 10)
108 private AddressbokStatus addressbookStatus;
111 * Connection to "users" table
113 @JoinColumn (name = "addressbook_user_id", nullable = false)
114 @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH, optional = false)
115 private User addressbookUser;
118 * Public constructor with address book name
120 * @param addressbookName Address book name
121 * @param addressbookUser User instance
123 public UserAddressbook (final String addressbookName, final User addressbookUser) {
124 // Call default constructor
127 // Set name and user instance
128 this.addressbookName = addressbookName;
129 this.addressbookUser = addressbookUser;
133 * Default constructor
135 public UserAddressbook () {
136 // Set status to UNLOCKED
137 this.addressbookStatus = AddressbokStatus.UNLOCKED;
141 public boolean equals (final Object object) {
142 if (null == object) {
144 } else if (this.getClass() != object.getClass()) {
148 final Addressbook other = (Addressbook) object;
150 if (!Objects.equals(this.getAddressbookName(), other.getAddressbookName())) {
152 } else if (!Objects.equals(this.getAddressbookUser(), other.getAddressbookUser())) {
160 public int hashCode () {
162 hash = 59 * hash + Objects.hashCode(this.getAddressbookName());
163 hash = 59 * hash + Objects.hashCode(this.getAddressbookUser());
168 public Date getAddressbookCreated () {
169 return this.addressbookCreated;
173 public void setAddressbookCreated (final Date addressbookCreated) {
174 this.addressbookCreated = addressbookCreated;
178 public Long getAddressbookId () {
179 return this.addressbookId;
183 public void setAddressbookId (final Long addressbookId) {
184 this.addressbookId = addressbookId;
188 public Date getAddressbookLastLocked () {
189 return this.addressbookLastLocked;
193 public void setAddressbookLastLocked (final Date addressbookLastLocked) {
194 this.addressbookLastLocked = addressbookLastLocked;
198 public String getAddressbookLastLockedReason () {
199 return this.addressbookLastLockedReason;
203 public void setAddressbookLastLockedReason (final String addressbookLastLockedReason) {
204 this.addressbookLastLockedReason = addressbookLastLockedReason;
208 public String getAddressbookName () {
209 return this.addressbookName;
213 public void setAddressbookName (final String addressbookName) {
214 this.addressbookName = addressbookName;
218 public AddressbokStatus getAddressbookStatus () {
219 return this.addressbookStatus;
223 public void setAddressbookStatus (final AddressbokStatus addressbookStatus) {
224 this.addressbookStatus = addressbookStatus;
228 public User getAddressbookUser () {
229 return this.addressbookUser;
233 public void setAddressbookUser (final User addressbookUser) {
234 this.addressbookUser = addressbookUser;