2 * Copyright (C) 2015 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.addressbook.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.NamedQueries;
32 import javax.persistence.NamedQuery;
33 import javax.persistence.OneToOne;
34 import javax.persistence.Table;
35 import javax.persistence.Temporal;
36 import javax.persistence.TemporalType;
37 import org.mxchange.addressbook.model.addressbook.status.AddressbokStatus;
38 import org.mxchange.jusercore.model.user.LoginUser;
39 import org.mxchange.jusercore.model.user.User;
42 * A POJO for user addressbooks
44 * @author Roland Haeder
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 = "FindAddressbookById", query = "SELECT a FROM addressbooks AS a WHERE a.addressbookId = :id")
55 public class UserAddressbook implements Addressbook, Comparable<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", length = 20, nullable = false, updatable = false)
76 private Long addressbookId;
79 * Name for this address book
81 @Basic (optional = false)
82 @Column (name = "addressbook_name", length = 50, nullable = false)
83 private String addressbookName;
88 @Basic (optional = false)
89 @Enumerated (EnumType.STRING)
90 @Column (name = "addressbook_status", nullable = false, length = 10)
91 private AddressbokStatus addressbookStatus;
94 * Connection to "users" table
96 @JoinColumn (name = "addressbook_user_id", nullable = false)
97 @OneToOne (targetEntity = LoginUser.class, optional = false, cascade = CascadeType.ALL)
98 private User addressbookUser;
101 * Public constructor with address book name
103 * @param addressbookName Address book name
105 public UserAddressbook (final String addressbookName) {
106 // Call default constructor
110 this.addressbookName = addressbookName;
114 * Default protected constructor
116 protected UserAddressbook () {
120 public int compareTo (final Addressbook addressbook) {
121 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
125 public boolean equals (final Object object) {
126 if (object == null) {
128 } else if (getClass() != object.getClass()) {
132 final Addressbook other = (Addressbook) object;
134 if (!Objects.equals(this.getAddressbookName(), other.getAddressbookName())) {
136 } else if (!Objects.equals(this.getAddressbookUser(), other.getAddressbookUser())) {
144 public Calendar getAddressbookCreated () {
145 return this.addressbookCreated;
149 public void setAddressbookCreated (final Calendar addressbookCreated) {
150 this.addressbookCreated = addressbookCreated;
154 public Long getAddressbookId () {
155 return this.addressbookId;
159 public void setAddressbookId (final Long addressbookId) {
160 this.addressbookId = addressbookId;
164 public String getAddressbookName () {
165 return this.addressbookName;
169 public void setAddressbookName (final String addressbookName) {
170 this.addressbookName = addressbookName;
174 public AddressbokStatus getAddressbookStatus () {
175 return this.addressbookStatus;
179 public void setAddressbookStatus (final AddressbokStatus addressbookStatus) {
180 this.addressbookStatus = addressbookStatus;
184 public User getAddressbookUser () {
185 return this.addressbookUser;
189 public void setAddressbookUser (final User addressbookUser) {
190 this.addressbookUser = addressbookUser;
194 public int hashCode () {
196 hash = 59 * hash + Objects.hashCode(this.getAddressbookName());
197 hash = 59 * hash + Objects.hashCode(this.getAddressbookUser());