]> git.mxchange.org Git - jbonuscard-lib.git/blob - src/org/mxchange/addressbook/model/addressbook/UserAddressbook.java
95496f104b0b7703657ea7d0b62f135e9a9ea019
[jbonuscard-lib.git] / src / org / mxchange / addressbook / model / addressbook / UserAddressbook.java
1 /*
2  * Copyright (C) 2015 Roland Haeder
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.addressbook.model.addressbook;
18
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;
39
40 /**
41  * A POJO for user addressbooks
42  * <p>
43  * @author Roland Haeder
44  */
45 @Entity (name = "addressbooks")
46 @Table (name = "addressbooks")
47 @NamedQueries (
48                 {
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")
52                 }
53 )
54 public class UserAddressbook implements Addressbook, Comparable<Addressbook> {
55
56         /**
57          * Serial number
58          */
59         private static final long serialVersionUID = 176_573_148_678_169L;
60
61         /**
62          * When this address book has been created
63          */
64         @Basic (optional = false)
65         @Temporal (value = TemporalType.TIMESTAMP)
66         @Column (name = "addressbook_created", nullable = false, updatable = false)
67         private Calendar addressbookCreated;
68
69         /**
70          * Id number
71          */
72         @Id
73         @GeneratedValue (strategy = GenerationType.IDENTITY)
74         @Column (name = "addressbook_id", length = 20, nullable = false, updatable = false)
75         private Long addressbookId;
76
77         /**
78          * Name for this address book
79          */
80         @Basic (optional = false)
81         @Column (name = "addressbook_name", length = 50, nullable = false)
82         private String addressbookName;
83
84         /**
85          * Adress book status
86          */
87         @Basic (optional = false)
88         @Enumerated (EnumType.STRING)
89         @Column (name = "addressbook_status", nullable = false, length = 10)
90         private AddressbokStatus addressbookStatus;
91
92         /**
93          * Connection to "users" table
94          */
95         @JoinColumn (name = "addressbook_user_id", nullable = false)
96         @OneToOne (targetEntity = LoginUser.class, optional = false, cascade = CascadeType.ALL)
97         private User addressbookUser;
98
99         /**
100          * Public constructor with address book name
101          * <p>
102          * @param addressbookName Address book name
103          */
104         public UserAddressbook (final String addressbookName) {
105                 // Call default constructor
106                 this();
107
108                 // Set name
109                 this.addressbookName = addressbookName;
110         }
111
112         /**
113          * Default protected constructor
114          */
115         protected UserAddressbook () {
116         }
117
118         @Override
119         public int compareTo (final Addressbook addressbook) {
120                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
121         }
122
123         @Override
124         public Calendar getAddressbookCreated () {
125                 return this.addressbookCreated;
126         }
127
128         @Override
129         public void setAddressbookCreated (final Calendar addressbookCreated) {
130                 this.addressbookCreated = addressbookCreated;
131         }
132
133         @Override
134         public Long getAddressbookId () {
135                 return this.addressbookId;
136         }
137
138         @Override
139         public void setAddressbookId (final Long addressbookId) {
140                 this.addressbookId = addressbookId;
141         }
142
143         @Override
144         public String getAddressbookName () {
145                 return this.addressbookName;
146         }
147
148         @Override
149         public void setAddressbookName (final String addressbookName) {
150                 this.addressbookName = addressbookName;
151         }
152
153         @Override
154         public AddressbokStatus getAddressbookStatus () {
155                 return this.addressbookStatus;
156         }
157
158         @Override
159         public void setAddressbookStatus (final AddressbokStatus addressbookStatus) {
160                 this.addressbookStatus = addressbookStatus;
161         }
162
163         @Override
164         public User getAddressbookUser () {
165                 return this.addressbookUser;
166         }
167
168         @Override
169         public void setAddressbookUser (final User addressbookUser) {
170                 this.addressbookUser = addressbookUser;
171         }
172 }