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 javax.persistence.Basic;
21 import javax.persistence.CascadeType;
22 import javax.persistence.Column;
23 import javax.persistence.Entity;
24 import javax.persistence.EnumType;
25 import javax.persistence.Enumerated;
26 import javax.persistence.GeneratedValue;
27 import javax.persistence.GenerationType;
28 import javax.persistence.Id;
29 import javax.persistence.JoinColumn;
30 import javax.persistence.NamedQueries;
31 import javax.persistence.NamedQuery;
32 import javax.persistence.OneToOne;
33 import javax.persistence.Table;
34 import javax.persistence.Temporal;
35 import javax.persistence.TemporalType;
36 import org.mxchange.addressbook.model.addressbook.status.AddressbokStatus;
37 import org.mxchange.jusercore.model.user.LoginUser;
38 import org.mxchange.jusercore.model.user.User;
41 * A POJO for user addressbooks
43 * @author Roland Haeder
45 @Entity (name = "addressbooks")
46 @Table (name = "addressbooks")
49 @NamedQuery (name = "AllUsersAddressbooks", query = "SELECT a FROM addressbooks AS a WHERE a.addressbookUser = :param ORDER BY a.addressbookId ASC"),
50 @NamedQuery (name = "SearchUserAddressbookName", query = "SELECT a FROM addressbooks AS a WHERE a.addressbookUser = :user AND LOWER(a.addressbookName) LIKE LOWER(:name)"),
51 @NamedQuery (name = "FindAddressbookById", query = "SELECT a FROM addressbooks AS a WHERE a.addressbookId = :id")
54 public class UserAddressbook implements Addressbook, Comparable<Addressbook> {
59 private static final long serialVersionUID = 176_573_148_678_169L;
62 * When this address book has been created
64 @Basic (optional = false)
65 @Temporal (value = TemporalType.TIMESTAMP)
66 @Column (name = "addressbook_created", nullable = false, updatable = false)
67 private Calendar addressbookCreated;
73 @GeneratedValue (strategy = GenerationType.IDENTITY)
74 @Column (name = "addressbook_id", length = 20, nullable = false, updatable = false)
75 private Long addressbookId;
78 * Name for this address book
80 @Basic (optional = false)
81 @Column (name = "addressbook_name", length = 50, nullable = false)
82 private String addressbookName;
87 @Basic (optional = false)
88 @Enumerated (EnumType.STRING)
89 @Column (name = "addressbook_status", nullable = false, length = 10)
90 private AddressbokStatus addressbookStatus;
93 * Connection to "users" table
95 @JoinColumn (name = "addressbook_user_id", nullable = false)
96 @OneToOne (targetEntity = LoginUser.class, optional = false, cascade = CascadeType.ALL)
97 private User addressbookUser;
100 * Public constructor with address book name
102 * @param addressbookName Address book name
104 public UserAddressbook (final String addressbookName) {
105 // Call default constructor
109 this.addressbookName = addressbookName;
113 * Default protected constructor
115 protected UserAddressbook () {
119 public int compareTo (final Addressbook addressbook) {
120 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
124 public Calendar getAddressbookCreated () {
125 return this.addressbookCreated;
129 public void setAddressbookCreated (final Calendar addressbookCreated) {
130 this.addressbookCreated = addressbookCreated;
134 public Long getAddressbookId () {
135 return this.addressbookId;
139 public void setAddressbookId (final Long addressbookId) {
140 this.addressbookId = addressbookId;
144 public String getAddressbookName () {
145 return this.addressbookName;
149 public void setAddressbookName (final String addressbookName) {
150 this.addressbookName = addressbookName;
154 public AddressbokStatus getAddressbookStatus () {
155 return this.addressbookStatus;
159 public void setAddressbookStatus (final AddressbokStatus addressbookStatus) {
160 this.addressbookStatus = addressbookStatus;
164 public User getAddressbookUser () {
165 return this.addressbookUser;
169 public void setAddressbookUser (final User addressbookUser) {
170 this.addressbookUser = addressbookUser;