at.thinkingco2.databasemanager.databeans.JourneyBean.java Source code

Java tutorial

Introduction

Here is the source code for at.thinkingco2.databasemanager.databeans.JourneyBean.java

Source

package at.thinkingco2.databasemanager.databeans;

import java.io.Serializable;
import java.sql.Date;
import java.sql.Timestamp;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

/**
 * Entity for JourneyBean. This JourneyBean represents a Journey with its needed
 * Attributes.
 * 
 * @author lukashaidacher
 * 
 */
@Entity
@Table(name = JourneyBean.TABLE)
public final class JourneyBean implements Serializable {
    private static final long serialVersionUID = 4896183576247098335L;
    public static final String TABLE = "Journey";

    /**
     * Unique-Id of JourneyBean
     */
    @Id
    @GeneratedValue
    @Column(name = "journeyId")
    private Integer id;

    /**
     * The description of the Journey
     */
    @Column(name = "description")
    private String description;

    /**
     * The AddressBean of the Destination of the Journey
     */
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "addressIdStart")
    private AddressBean start;

    /**
     * The AddressBean of the Destination of the Journey
     */
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "addressIdDestination")
    private AddressBean destination;

    /**
     * The ArrivleTime of the Journey
     */
    @Column(name = "arrivleTime")
    private Timestamp arrivleTime;

    /**
     * The License-Numbers of the Car
     */
    @Column(name = "licenseNumber")
    private String licenseNumber;

    /**
     * The RouteId of an Route
     */
    @Column(name = "routeId")
    private Integer routeId;

    /**
     * The ParentBean, which executes the JourneyBean
     */
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "parentId")
    private ParentBean parent;

    /**
     * Set of Groups, which uses this JourneyBean
     */
    @ManyToMany(mappedBy = "journeys", fetch = FetchType.EAGER)
    private Set<GroupBean> groups;

    /**
     * Set of ChildBean, which uses this JounreyBean
     */
    @ManyToMany(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
    @JoinTable(name = "Child_Jounrey", joinColumns = { @JoinColumn(name = "jounreyId") }, inverseJoinColumns = {
            @JoinColumn(name = "childId") })
    private Set<ChildBean> children;

    /**
     * Default-Constructor for Hibernate
     * 
     * @deprecated use
     *             {@link #JourneyBean(String, AddressBean, AddressBean, Date, Integer)}
     *             instead.
     */
    public JourneyBean() {
        this(null, null, null, null, null);
    }

    /**
     * Initiate-Constructor for Creating an JourneyBean
     * 
     * @param description
     * @param start
     * @param destination
     * @param arrivleTime
     * @param freeSeats
     */
    public JourneyBean(String description, AddressBean start, AddressBean destination, Timestamp arrivleTime,
            String licenseNumber) {
        this.description = description;
        this.start = start;
        this.destination = destination;
        this.arrivleTime = arrivleTime;
        this.licenseNumber = licenseNumber;
        this.groups = new HashSet<GroupBean>();
        this.children = new HashSet<ChildBean>();
    }

    public void addChild(ChildBean child) {
        children.add(child);
    }

    public void removeChild(ChildBean child) {
        children.remove(child);
    }

    public Integer getId() {
        return id;
    }

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

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public AddressBean getStart() {
        return start;
    }

    public void setStart(AddressBean start) {
        this.start = start;
    }

    public AddressBean getDestination() {
        return destination;
    }

    public void setDestination(AddressBean destination) {
        this.destination = destination;
    }

    public Timestamp getArrivleTime() {
        return arrivleTime;
    }

    public void setArrivleTime(Timestamp arrivleTime) {
        this.arrivleTime = arrivleTime;
    }

    public String getLicenseNumber() {
        return licenseNumber;
    }

    public void setLicenseNumber(String licenseNumber) {
        this.licenseNumber = licenseNumber;
    }

    public ParentBean getParent() {
        return parent;
    }

    public void setParent(ParentBean parent) {
        this.parent = parent;
    }

    public Set<GroupBean> getGroups() {
        return groups;
    }

    public void setGroups(Set<GroupBean> groups) {
        this.groups = groups;
    }

    public Set<ChildBean> getChildren() {
        return children;
    }

    public void setChildren(Set<ChildBean> children) {
        this.children = children;
    }

    public Integer getRouteId() {
        return routeId;
    }

    public void setRouteId(Integer routeId) {
        this.routeId = routeId;
    }

    @Override
    public String toString() {
        ToStringBuilder sb = new ToStringBuilder(this);

        sb.append("description", getDescription());
        sb.append("start", getStart());
        sb.append("destitnation", getDestination());
        sb.append("arrivleTime", getArrivleTime());
        sb.append("licenseNumber", getLicenseNumber());
        sb.append("parent", getParent());
        sb.append("groups", getGroups());
        sb.append("children", getChildren());

        return sb.toString();
    }

    @Override
    public int hashCode() {
        HashCodeBuilder hb = new HashCodeBuilder(97, 103);

        hb.append(getDescription());
        hb.append(getStart());
        hb.append(getDestination());
        hb.append(getArrivleTime());
        hb.append(getLicenseNumber());

        return hb.toHashCode();
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof JourneyBean))
            return false;

        JourneyBean bean = (JourneyBean) o;
        EqualsBuilder eb = new EqualsBuilder();

        eb.append(getDescription(), bean.getDescription());
        eb.append(getStart(), bean.getStart());
        eb.append(getDestination(), bean.getDestination());
        eb.append(getArrivleTime(), bean.getArrivleTime());
        eb.append(getLicenseNumber(), bean.getLicenseNumber());

        return eb.isEquals();
    }

}