2 * Copyright (C) 2017 Roland Häder<roland@mxchange.org>
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.jfinancials.model.income;
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.EnumType;
26 import javax.persistence.Enumerated;
27 import javax.persistence.GeneratedValue;
28 import javax.persistence.GenerationType;
29 import javax.persistence.Id;
30 import javax.persistence.JoinColumn;
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.jfinancials.model.income.interval.FinancialInterval;
37 import org.mxchange.jusercore.model.user.LoginUser;
38 import org.mxchange.jusercore.model.user.User;
41 * An entity for income data
43 * @author Roland Häder<roland@mxchange.org>
45 @Entity (name = "income")
46 @Table (name = "income")
47 @SuppressWarnings ("PersistenceUnitPresent")
48 public class FinancialIncome implements BillableIncome {
54 private static final long serialVersionUID = 173_587_690_625_524L;
57 * Income created timestamp
59 @Basic (optional = false)
60 @Temporal (TemporalType.TIMESTAMP)
61 @Column (name = "income_created", nullable = false, updatable = false)
62 private Calendar incomeCreated;
65 * Income enabled (default) or disabled (no longer receiving income but need
66 * to keep it for statistics).
68 @Basic (optional = false)
69 @Column (name = "income_enabled", nullable = false)
70 private Boolean incomeEnabled;
73 * Income id (primary key)
76 @GeneratedValue (strategy = GenerationType.IDENTITY)
77 @Column (name = "income_id", nullable = false, updatable = false)
78 private Long incomeId;
83 @Basic (optional = false)
84 @Column (name = "income_interval", nullable = false)
85 @Enumerated (EnumType.STRING)
86 private FinancialInterval incomeInterval;
89 * Income single amount
91 @Basic (optional = false)
92 @Column (name = "income_single_amount", nullable = false)
93 private Float incomeSingleAmount;
98 @Basic (optional = false)
99 @Column (name = "income_title", nullable = false)
100 private String incomeTitle;
103 * Income updated timestamp
105 @Temporal (TemporalType.TIMESTAMP)
106 @Column (name = "income_updated", insertable = false)
107 private Calendar incomeUpdated;
110 * Connected user account
112 @JoinColumn (name = "income_user_id", referencedColumnName = "user_id", nullable = false, updatable = false)
113 @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH, optional = false)
114 private User incomeUser;
117 * Default constructor
119 public FinancialIncome () {
123 * Constructor with all fields, except timestamps. These have to be set at a
126 * @param incomeTitle Income (type) title
127 * @param incomeSingleAmount Single amount
128 * @param incomeInterval Interval
129 * @param incomeUser Connected user
131 public FinancialIncome (final String incomeTitle, final Float incomeSingleAmount, final FinancialInterval incomeInterval, final User incomeUser) {
132 // Call default constructor
136 this.incomeTitle = incomeTitle;
137 this.incomeSingleAmount = incomeSingleAmount;
138 this.incomeInterval = incomeInterval;
139 this.incomeUser = incomeUser;
141 // Enable this income by default
142 this.incomeEnabled = Boolean.TRUE;
146 public boolean equals (final Object object) {
147 if (this == object) {
149 } else if (null == object) {
151 } else if (this.getClass() != object.getClass()) {
155 final BillableIncome other = (BillableIncome) object;
157 if (!Objects.equals(this.getIncomeTitle(), other.getIncomeTitle())) {
159 } else if (!Objects.equals(this.getIncomeId(), other.getIncomeId())) {
161 } else if (!Objects.equals(this.getIncomeUser(), other.getIncomeUser())) {
168 @SuppressWarnings ("ReturnOfDateField")
169 public Calendar getIncomeCreated () {
170 return this.incomeCreated;
174 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
175 public void setIncomeCreated (Calendar incomeCreated) {
176 this.incomeCreated = incomeCreated;
180 public Boolean getIncomeEnabled () {
181 return this.incomeEnabled;
185 public void setIncomeEnabled (Boolean incomeEnabled) {
186 this.incomeEnabled = incomeEnabled;
190 public Long getIncomeId () {
191 return this.incomeId;
195 public void setIncomeId (final Long incomeId) {
196 this.incomeId = incomeId;
200 public FinancialInterval getIncomeInterval () {
201 return this.incomeInterval;
205 public void setIncomeInterval (FinancialInterval incomeInterval) {
206 this.incomeInterval = incomeInterval;
210 public Float getIncomeSingleAmount () {
211 return this.incomeSingleAmount;
215 public void setIncomeSingleAmount (Float incomeSingleAmount) {
216 this.incomeSingleAmount = incomeSingleAmount;
220 public String getIncomeTitle () {
221 return this.incomeTitle;
225 public void setIncomeTitle (String incomeTitle) {
226 this.incomeTitle = incomeTitle;
230 @SuppressWarnings ("ReturnOfDateField")
231 public Calendar getIncomeUpdated () {
232 return this.incomeUpdated;
236 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
237 public void setIncomeUpdated (Calendar incomeUpdated) {
238 this.incomeUpdated = incomeUpdated;
242 public User getIncomeUser () {
243 return this.incomeUser;
247 public void setIncomeUser (User incomeUser) {
248 this.incomeUser = incomeUser;
252 public int hashCode () {
255 hash = 29 * hash + Objects.hashCode(this.getIncomeId());
256 hash = 29 * hash + Objects.hashCode(this.getIncomeTitle());
257 hash = 29 * hash + Objects.hashCode(this.getIncomeUser());