]> git.mxchange.org Git - jfinancials-lib.git/blob - src/org/mxchange/addressbook/model/addressbook/UserAddressbook.java
re-ordered members + re-formated
[jfinancials-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          * When this address book has been created
62          */
63         @Basic (optional = false)
64         @Temporal (value = TemporalType.TIMESTAMP)
65         @Column (name = "addressbook_created", nullable = false, updatable = false)
66         private Calendar addressbookCreated;
67
68         /**
69          * Id number
70          */
71         @Id
72         @GeneratedValue (strategy = GenerationType.IDENTITY)
73         @Column (name = "addressbook_id", length = 20, nullable = false, updatable = false)
74         private Long addressbookId;
75
76         /**
77          * Name for this address book
78          */
79         @Basic (optional = false)
80         @Column (name = "addressbook_name", length = 50, nullable = false)
81         private String addressbookName;
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          * Connection to "users" table
93          */
94         @JoinColumn (name = "addressbook_user_id", nullable = false)
95         @OneToOne (targetEntity = LoginUser.class, optional = false, cascade = CascadeType.ALL)
96         private User addressbookUser;
97
98         /**
99          * Public constructor with address book name
100          * <p>
101          * @param addressbookName Address book name
102          */
103         public UserAddressbook (final String addressbookName) {
104                 // Call default constructor
105                 this();
106
107                 // Set name
108                 this.addressbookName = addressbookName;
109         }
110
111         /**
112          * Default protected constructor
113          */
114         protected UserAddressbook () {
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 }