com.epam.ipodromproject.domain.Horse.java Source code

Java tutorial

Introduction

Here is the source code for com.epam.ipodromproject.domain.Horse.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.epam.ipodromproject.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import java.io.Serializable;
import java.util.Map;
import java.util.Objects;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.MapKeyJoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author Oleh
 */
@Entity
@Table(name = "HORSE")
@NamedQueries({ @NamedQuery(name = "Horse.findAll", query = "SELECT h FROM Horse h"),
        @NamedQuery(name = "Horse.findByName", query = "SELECT h FROM Horse h WHERE h.name = :name"),
        @NamedQuery(name = "Horse.findNumberOfHorsesByPartOfName", query = "SELECT COUNT(h) FROM Horse h where (h.name like :partOfName)"),
        @NamedQuery(name = "Horse.getHorsesByPageAndPartOfName", query = "SELECT h FROM Horse h where (h.name like :partOfName)"),
        @NamedQuery(name = "Horse.findByNameAndEnabled", query = "SELECT h FROM Horse h "
                + "WHERE (h.name = :name) " + "AND (h.enabled = :enabled)") })
public class Horse implements Serializable {

    @Id
    @Column(name = "ID")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(name = "NAME", nullable = false)
    private String name;

    @JsonIgnore
    @ElementCollection
    @CollectionTable(name = "COEFFICIENTS_ON_HORSES", joinColumns = { @JoinColumn(name = "HORSE_ID") })
    @MapKeyJoinColumn(name = "COMPETITION_ID")
    @Column(name = "INFORMATION")
    private Map<Competition, HorseInfo> competitions;

    @Column(name = "ENABLED", nullable = false)
    private Boolean enabled = true;

    public Horse() {
    }

    public Horse(String name) {
        this.name = name;
    }

    public Horse(Long id, String name) {
        this.id = id;
        this.name = name;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Map<Competition, HorseInfo> getCompetitions() {
        return competitions;
    }

    public void setCompetitions(Map<Competition, HorseInfo> competitions) {
        this.competitions = competitions;
    }

    public Boolean getEnabled() {
        return enabled;
    }

    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }

    @Override
    public String toString() {
        return "Horse{" + "id=" + id + ", name=" + name + ", enabled=" + enabled + '}';
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 19 * hash + Objects.hashCode(this.name);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Horse other = (Horse) obj;
        if (Objects.equals(this.id, other.id)) {
            return true;
        } else {
            if ((this.id == null) || (other.id == null)) {
                return Objects.equals(this.name, other.name);
            } else {
                return false;
            }
        }
    }
}