2 * Copyright (C) 2016 Roland Häder
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.jphone.phonenumbers.landline;
19 import java.util.Calendar;
20 import java.util.Objects;
21 import javax.persistence.Basic;
22 import javax.persistence.CascadeType;
23 import javax.persistence.Column;
24 import javax.persistence.Entity;
25 import javax.persistence.GeneratedValue;
26 import javax.persistence.GenerationType;
27 import javax.persistence.Id;
28 import javax.persistence.JoinColumn;
29 import javax.persistence.NamedQueries;
30 import javax.persistence.NamedQuery;
31 import javax.persistence.OneToOne;
32 import javax.persistence.Table;
33 import javax.persistence.Temporal;
34 import javax.persistence.TemporalType;
35 import javax.persistence.Transient;
36 import org.mxchange.jcountry.data.Country;
37 import org.mxchange.jcountry.data.CountryData;
40 * A POJO for dialable phone numbers
42 * @author Roland Häder<roland@mxchange.org>
44 @Entity (name = "landline_numbers")
45 @Table (name = "landline_numbers")
48 @NamedQuery (name = "AllLandLineNumbers", query = "SELECT p FROM landline_numbers AS p ORDER BY p.phoneId ASC"),
49 @NamedQuery (name = "SearchLandLineNumberId", query = "SELECT p FROM landline_numbers AS p WHERE p.phoneId = :landLineNumberId")
52 @SuppressWarnings ("PersistenceUnitPresent")
53 public class LandLineNumber implements DialableLandLineNumber {
59 private static final long serialVersionUID = 18_563_748_781_956L;
62 * Area code (example: 2151 for Krefeld)
64 @Basic (optional = false)
65 @Column (name = "landline_area_code", length = 10, nullable = false)
66 private Integer phoneAreaCode;
69 * Connection to table "country_data"
71 @JoinColumn (name = "landline_country_id", nullable = false, updatable = false)
72 @OneToOne (targetEntity = CountryData.class, cascade = CascadeType.REFRESH, optional = false)
73 private Country phoneCountry;
76 * Timestamp when this entry has been created
78 @Basic (optional = false)
79 @Temporal (TemporalType.TIMESTAMP)
80 @Column (name = "landline_entry_created", nullable = false, updatable = false)
81 private Calendar phoneEntryCreated;
84 * Timestamp when this entry has been created
86 @Temporal (TemporalType.TIMESTAMP)
87 @Column (name = "landline_entry_updated", updatable = false)
88 private Calendar phoneEntryUpdated;
94 @GeneratedValue (strategy = GenerationType.IDENTITY)
95 @Column (name = "landline_id", length = 10, nullable = false, updatable = false)
99 * Phone number with out dial prefix
101 @Basic (optional = false)
102 @Column (name = "landline_number", nullable = false)
103 private Long phoneNumber;
106 * Default constructor
108 public LandLineNumber () {
112 * Constructor with country instance, area code and number
114 * @param phoneCountry Country instance
115 * @param phoneAreaCode Phone area code
116 * @param phoneNumber Phone number
118 public LandLineNumber (final Country phoneCountry, final Integer phoneAreaCode, final Long phoneNumber) {
119 // Call default constructor
123 this.phoneCountry = phoneCountry;
124 this.phoneAreaCode = phoneAreaCode;
125 this.phoneNumber = phoneNumber;
129 public void copyAll (final DialableLandLineNumber sourceNumber) {
131 if (null == sourceNumber) {
133 throw new NullPointerException("sourceNumber is null"); //NOI18N
137 this.setPhoneAreaCode(sourceNumber.getPhoneAreaCode());
138 this.getPhoneCountry().copyAll(sourceNumber.getPhoneCountry());
139 this.setPhoneEntryCreated(sourceNumber.getPhoneEntryCreated());
140 this.setPhoneId(sourceNumber.getPhoneId());
141 this.setPhoneNumber(sourceNumber.getPhoneNumber());
145 public boolean equals (final Object object) {
146 if (null == object) {
148 } else if (this.getClass() != object.getClass()) {
152 final DialableLandLineNumber other = (DialableLandLineNumber) object;
154 if (!Objects.equals(this.getPhoneId(), other.getPhoneId())) {
156 } else if (!Objects.equals(this.getPhoneNumber(), other.getPhoneNumber())) {
158 } else if (!Objects.equals(this.getPhoneAreaCode(), other.getPhoneAreaCode())) {
160 } else if (!Objects.equals(this.getPhoneCountry(), other.getPhoneCountry())) {
168 public Integer getPhoneAreaCode () {
169 return this.phoneAreaCode;
173 public void setPhoneAreaCode (final Integer phoneAreaCode) {
174 this.phoneAreaCode = phoneAreaCode;
178 public Country getPhoneCountry () {
179 return this.phoneCountry;
183 public void setPhoneCountry (final Country phoneCountry) {
184 this.phoneCountry = phoneCountry;
188 @SuppressWarnings ("ReturnOfDateField")
189 public Calendar getPhoneEntryCreated () {
190 return this.phoneEntryCreated;
194 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
195 public void setPhoneEntryCreated (final Calendar phoneEntryCreated) {
196 this.phoneEntryCreated = phoneEntryCreated;
200 @SuppressWarnings ("ReturnOfDateField")
201 public Calendar getPhoneEntryUpdated () {
202 return this.phoneEntryUpdated;
206 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
207 public void setPhoneEntryUpdated (final Calendar phoneEntryUpdated) {
208 this.phoneEntryUpdated = phoneEntryUpdated;
212 public Long getPhoneId () {
217 public void setPhoneId (final Long phoneId) {
218 this.phoneId = phoneId;
222 public Long getPhoneNumber () {
223 return this.phoneNumber;
227 public void setPhoneNumber (final Long phoneNumber) {
228 this.phoneNumber = phoneNumber;
232 public int hashCode () {
235 hash = 47 * hash + Objects.hashCode(this.getPhoneId());
236 hash = 47 * hash + Objects.hashCode(this.getPhoneNumber());
237 hash = 47 * hash + Objects.hashCode(this.getPhoneAreaCode());
238 hash = 47 * hash + Objects.hashCode(this.getPhoneCountry());