2 * Copyright (C) 2016, 2017 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.jcontactsbusiness.model.opening_times;
19 import java.util.Date;
20 import java.util.Objects;
21 import javax.persistence.Basic;
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.NamedQueries;
30 import javax.persistence.NamedQuery;
31 import javax.persistence.Table;
32 import javax.persistence.Temporal;
33 import javax.persistence.TemporalType;
34 import javax.persistence.Transient;
35 import org.mxchange.jcontactsbusiness.model.opening_times.dayofweek.DayOfTheWeek;
38 * A POJO for business opening hours
40 * @author Roland Häder<roland@mxchange.org>
42 @Entity (name = "company_opening_times")
43 @Table (name = "company_opening_times")
46 @NamedQuery (name = "AllOpeningTimes", query = "SELECT ot FROM company_opening_times AS ot ORDER BY ot.openingId ASC"),
47 @NamedQuery (name = "SearchOpeningTimesById", query = "SELECT ot FROM company_opening_times AS ot WHERE ot.openingId = :openingId")
50 @SuppressWarnings ("PersistenceUnitPresent")
51 public class BusinessOpeningTimes implements OpeningTimes {
57 private static final long serialVersionUID = 19_578_871_756_871L;
60 * When this opening time was created
62 @Basic(optional = false)
63 @Column(name = "opening_times_created", nullable = false, updatable = false)
64 @Temporal (TemporalType.TIMESTAMP)
65 private Date openingCreated;
68 * Ending day of opening hours (if applyable)
70 @Basic (optional = false)
71 @Column (name = "opening_times_end_day", nullable = false)
72 @Enumerated (EnumType.STRING)
73 private DayOfTheWeek openingEndDay;
78 @Basic (optional = false)
79 @Column (name = "opening_times_end_time", nullable = false)
80 @Temporal (TemporalType.TIME)
81 private Date openingEndTime;
87 @Column (name = "opening_times_id", nullable = false, updatable = false)
88 @GeneratedValue (strategy = GenerationType.IDENTITY)
89 private Long openingId;
92 * Starting day of opening times
94 @Basic (optional = false)
95 @Column (name = "opening_times_start_day", nullable = false)
96 @Enumerated (EnumType.STRING)
97 private DayOfTheWeek openingStartDay;
100 * Starting time (hh:mm)
102 @Basic (optional = false)
103 @Column (name = "opening_times_start_time", nullable = false)
104 @Temporal (TemporalType.TIME)
105 private Date openingStartTime;
108 * Default constructor
110 public BusinessOpeningTimes () {
114 * Constructor with all required fields except created timestamp
116 * @param openingEndDay End day
117 * @param openingEndTime End time
118 * @param openingStartDay Start day
119 * @param openingStartTime Start time
121 public BusinessOpeningTimes (final DayOfTheWeek openingEndDay, final Date openingEndTime, final DayOfTheWeek openingStartDay, final Date openingStartTime) {
123 this.openingEndDay = openingEndDay;
124 this.openingEndTime = openingEndTime;
125 this.openingStartDay = openingStartDay;
126 this.openingStartTime = openingStartTime;
130 public boolean equals (final Object obj) {
133 } else if (obj == null) {
135 } else if (this.getClass() != obj.getClass()) {
139 final OpeningTimes openingTimes = (OpeningTimes) obj;
141 if (!Objects.equals(this.getOpeningId(), openingTimes.getOpeningId())) {
143 } else if (this.getOpeningStartDay() != openingTimes.getOpeningStartDay()) {
145 } else if (this.getOpeningEndDay() != openingTimes.getOpeningEndDay()) {
147 } else if (!Objects.equals(this.getOpeningStartTime(), openingTimes.getOpeningStartTime())) {
149 } else if (!Objects.equals(this.getOpeningEndTime(), openingTimes.getOpeningEndTime())) {
157 @SuppressWarnings ("ReturnOfDateField")
158 public Date getOpeningCreated () {
159 return this.openingCreated;
163 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
164 public void setOpeningCreated (final Date openingCreated) {
165 this.openingCreated = openingCreated;
169 public DayOfTheWeek getOpeningEndDay () {
170 return this.openingEndDay;
174 public void setOpeningEndDay (final DayOfTheWeek openingEndDay) {
175 this.openingEndDay = openingEndDay;
179 @SuppressWarnings ("ReturnOfDateField")
180 public Date getOpeningEndTime () {
181 return this.openingEndTime;
185 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
186 public void setOpeningEndTime (final Date openingEndTime) {
187 this.openingEndTime = openingEndTime;
191 public Long getOpeningId () {
192 return this.openingId;
196 public void setOpeningId (final Long openingId) {
197 this.openingId = openingId;
201 public DayOfTheWeek getOpeningStartDay () {
202 return this.openingStartDay;
206 public void setOpeningStartDay (final DayOfTheWeek openingStartDay) {
207 this.openingStartDay = openingStartDay;
211 @SuppressWarnings ("ReturnOfDateField")
212 public Date getOpeningStartTime () {
213 return this.openingStartTime;
217 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
218 public void setOpeningStartTime (final Date openingStartTime) {
219 this.openingStartTime = openingStartTime;
223 public int hashCode () {
226 hash = 97 * hash + Objects.hashCode(this.getOpeningId());
227 hash = 97 * hash + Objects.hashCode(this.getOpeningStartDay());
228 hash = 97 * hash + Objects.hashCode(this.getOpeningEndDay());
229 hash = 97 * hash + Objects.hashCode(this.getOpeningStartTime());
230 hash = 97 * hash + Objects.hashCode(this.getOpeningEndTime());