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)")
53 public class UserAddressbook implements Addressbook, Comparable<Addressbook> {
58 private static final long serialVersionUID = 176_573_148_678_169L;
64 @GeneratedValue (strategy = GenerationType.IDENTITY)
65 @Column (name = "addressbook_id", length = 20, nullable = false, updatable = false)
66 private Long addressbookId;
69 * Connection to "users" table
71 @JoinColumn (name = "addressbook_user_id", nullable = false)
72 @OneToOne (targetEntity = LoginUser.class, optional = false, cascade = CascadeType.ALL)
73 private User addressbookUser;
76 * When this address book has been created
78 @Basic (optional = false)
79 @Temporal (TemporalType.TIMESTAMP)
80 @Column (name = "addressbook_created", nullable = false, updatable = false)
81 private Calendar addressbookCreated;
86 @Basic (optional = false)
87 @Enumerated (EnumType.STRING)
88 @Column (name = "addressbook_status", nullable = false, length = 10)
89 private AddressbokStatus addressbookStatus;
92 * Name for this address book
94 @Basic (optional = false)
95 @Column (name = "addressbook_name", length = 50, nullable = false)
96 private String addressbookName;
99 * Default protected constructor
101 protected UserAddressbook () {
105 * Public constructor with address book name
107 * @param addressbookName Address book name
109 public UserAddressbook (final String addressbookName) {
110 // Call default constructor
114 this.addressbookName = addressbookName;
118 public int compareTo (final Addressbook addressbook) {
119 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
123 public Calendar getAddressbookCreated () {
124 return this.addressbookCreated;
128 public void setAddressbookCreated (final Calendar addressbookCreated) {
129 this.addressbookCreated = addressbookCreated;
133 public Long getAddressbookId () {
134 return this.addressbookId;
138 public void setAddressbookId (final Long addressbookId) {
139 this.addressbookId = addressbookId;
143 public String getAddressbookName () {
144 return this.addressbookName;
148 public void setAddressbookName (final String addressbookName) {
149 this.addressbookName = addressbookName;
153 public AddressbokStatus getAddressbookStatus () {
154 return this.addressbookStatus;
158 public void setAddressbookStatus (final AddressbokStatus addressbookStatus) {
159 this.addressbookStatus = addressbookStatus;
163 public User getAddressbookUser () {
164 return this.addressbookUser;
168 public void setAddressbookUser (final User addressbookUser) {
169 this.addressbookUser = addressbookUser;