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