ExportCostLine.java

package com.tradecloud.domain.export;

import com.tradecloud.common.base.PersistenceBase;
import com.tradecloud.domain.costing.CostLine;
import org.springframework.stereotype.Component;

import javax.persistence.*;
import javax.xml.bind.annotation.XmlAttribute;
import java.math.BigDecimal;

@Entity
@Component(value = "ExportCostLine")
@Table(name = "exportcostline")
@Access(AccessType.FIELD)
public class ExportCostLine extends PersistenceBase implements Comparable<ExportCostLine> {

    @ManyToOne
    private CostLine costLine;

    private BigDecimal value;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "export_id", foreignKey = @ForeignKey(name = "fk_export_costline"))
    private Export export;

    @XmlAttribute
    private String overRideCostLineName;

    public String getOverRideCostLineName() {
        return overRideCostLineName;
    }

    public void setOverRideCostLineName(String overRideCostLineName) {
        this.overRideCostLineName = overRideCostLineName;
    }

    public ExportCostLine() {

    }

    public ExportCostLine(Export export, CostLine costLine, BigDecimal value) {
        this.export = export;
        this.costLine = costLine;
        this.value = value;
    }

    @Override
    public int compareTo(ExportCostLine e) {
        return getCostLine().getCostLineTemplate().getSortingPriority() - e.getCostLine().getCostLineTemplate().getSortingPriority();
    }

    public CostLine getCostLine() {
        return costLine;
    }

    public void setCostLine(CostLine costLine) {
        this.costLine = costLine;
    }

    public BigDecimal getValue() {
        return value;
    }

    public void setValue(BigDecimal value) {
        this.value = value;
    }

    public Export getExport() {
        return export;
    }

    public void setExport(Export export) {
        this.export = export;
    }

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

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (!super.equals(obj))
            return false;
        if (getClass() != obj.getClass())
            return false;
        ExportCostLine other = (ExportCostLine) obj;
        if (costLine == null) {
            if (other.costLine != null)
                return false;
        } else if (!costLine.equals(other.costLine))
            return false;
        return true;
    }

}