Discount.java 5.63 KB
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package fi.insomnia.bortal.model;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author jkj
 */
@Entity
@Table(name = "discounts")
@NamedQueries({
    @NamedQuery(name = "Discount.findAll", query = "SELECT d FROM Discount d"),
    @NamedQuery(name = "Discount.findByDiscountsId", query = "SELECT d FROM Discount d WHERE d.discountsId = :discountsId"),
    @NamedQuery(name = "Discount.findByPercentage", query = "SELECT d FROM Discount d WHERE d.percentage = :percentage"),
    @NamedQuery(name = "Discount.findByCode", query = "SELECT d FROM Discount d WHERE d.code = :code"),
    @NamedQuery(name = "Discount.findByDetails", query = "SELECT d FROM Discount d WHERE d.details = :details"),
    @NamedQuery(name = "Discount.findByAmountMin", query = "SELECT d FROM Discount d WHERE d.amountMin = :amountMin"),
    @NamedQuery(name = "Discount.findByAmountMax", query = "SELECT d FROM Discount d WHERE d.amountMax = :amountMax"),
    @NamedQuery(name = "Discount.findByActive", query = "SELECT d FROM Discount d WHERE d.active = :active"),
    @NamedQuery(name = "Discount.findByMaxNum", query = "SELECT d FROM Discount d WHERE d.maxNum = :maxNum"),
    @NamedQuery(name = "Discount.findByPerUser", query = "SELECT d FROM Discount d WHERE d.perUser = :perUser")})
public class Discount implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "discounts_id", nullable = false)
    private Integer discountsId;
    @Basic(optional = false)
    @Column(name = "percentage", nullable = false)
    private BigInteger percentage;
    @Column(name = "code", length = 2147483647)
    private String code;
    @Column(name = "details", length = 2147483647)
    private String details;
    @Basic(optional = false)
    @Column(name = "amount_min", nullable = false)
    private int amountMin;
    @Basic(optional = false)
    @Column(name = "amount_max", nullable = false)
    private int amountMax;
    @Basic(optional = false)
    @Column(name = "active", nullable = false)
    private boolean active;
    @Basic(optional = false)
    @Column(name = "max_num", nullable = false)
    private int maxNum;
    @Basic(optional = false)
    @Column(name = "per_user", nullable = false)
    private int perUser;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "discountsId")
    private List<DiscountInstance> discountInstanceList;

    public Discount() {
    }

    public Discount(Integer discountsId) {
        this.discountsId = discountsId;
    }

    public Discount(Integer discountsId, BigInteger percentage, int amountMin, int amountMax, boolean active, int maxNum, int perUser) {
        this.discountsId = discountsId;
        this.percentage = percentage;
        this.amountMin = amountMin;
        this.amountMax = amountMax;
        this.active = active;
        this.maxNum = maxNum;
        this.perUser = perUser;
    }

    public Integer getDiscountsId() {
        return discountsId;
    }

    public void setDiscountsId(Integer discountsId) {
        this.discountsId = discountsId;
    }

    public BigInteger getPercentage() {
        return percentage;
    }

    public void setPercentage(BigInteger percentage) {
        this.percentage = percentage;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDetails() {
        return details;
    }

    public void setDetails(String details) {
        this.details = details;
    }

    public int getAmountMin() {
        return amountMin;
    }

    public void setAmountMin(int amountMin) {
        this.amountMin = amountMin;
    }

    public int getAmountMax() {
        return amountMax;
    }

    public void setAmountMax(int amountMax) {
        this.amountMax = amountMax;
    }

    public boolean getActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    public int getMaxNum() {
        return maxNum;
    }

    public void setMaxNum(int maxNum) {
        this.maxNum = maxNum;
    }

    public int getPerUser() {
        return perUser;
    }

    public void setPerUser(int perUser) {
        this.perUser = perUser;
    }

    public List<DiscountInstance> getDiscountInstanceList() {
        return discountInstanceList;
    }

    public void setDiscountInstanceList(List<DiscountInstance> discountInstanceList) {
        this.discountInstanceList = discountInstanceList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (discountsId != null ? discountsId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Discount)) {
            return false;
        }
        Discount other = (Discount) object;
        if ((this.discountsId == null && other.discountsId != null) || (this.discountsId != null && !this.discountsId.equals(other.discountsId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "fi.insomnia.bortal.model.Discount[discountsId=" + discountsId + "]";
    }

}