/** * Most of the code in the Qalingo project is copyrighted Hoteia and licensed * under the Apache License Version 2.0 (release version 0.8.0) * http://www.apache.org/licenses/LICENSE-2.0 * * Copyright (c) Hoteia, 2012-2014 * http://www.hoteia.com - http://twitter.com/hoteia - contact@hoteia.com * */ package org.hoteia.qalingo.core.domain; import java.math.BigDecimal; import java.util.Date; 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.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.Lob; import javax.persistence.ManyToMany; import javax.persistence.OneToMany; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Version; import org.hoteia.qalingo.core.domain.impl.DomainEntity; @Entity @Table(name="TECO_TAX") public class Tax extends AbstractEntity<Tax> implements DomainEntity { /** * Generated UID */ private static final long serialVersionUID = 7515272027282284761L; @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "ID", nullable = false) private Long id; @Version @Column(name = "VERSION", nullable = false)// , columnDefinition = "int(11) default 1" private int version; @Column(name = "CODE", unique = true, nullable = false) private String code; @Column(name = "NAME") private String name; @Column(name = "DESCRIPTION") @Lob private String description; @Column(name = "PERCENT") private BigDecimal percent; @ManyToMany(fetch = FetchType.LAZY, cascade = { CascadeType.MERGE }, targetEntity = org.hoteia.qalingo.core.domain.TaxType.class) @JoinTable(name = "TECO_TAX_TYPE_REL", joinColumns = @JoinColumn(name = "TAX_ID"), inverseJoinColumns = @JoinColumn(name = "TAX_TYPE_ID")) private Set<TaxType> taxTypes = new HashSet<TaxType>(); @OneToMany(fetch = FetchType.LAZY) @JoinColumn(name = "TAX_ID") private Set<TaxCountry> taxCountries = new HashSet<TaxCountry>(); @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL) @JoinColumn(name = "TAX_ID") private Set<TaxAttribute> attributes = new HashSet<TaxAttribute>(); @ManyToMany(fetch = FetchType.LAZY, cascade = { CascadeType.MERGE }, targetEntity = org.hoteia.qalingo.core.domain.MarketArea.class) @JoinTable(name = "TECO_MARKET_AREA_TAX_REL", joinColumns = @JoinColumn(name = "TAX_ID"), inverseJoinColumns = @JoinColumn(name = "MARKET_AREA_ID")) private Set<MarketArea> marketAreas = new HashSet<MarketArea>(); @Temporal(TemporalType.TIMESTAMP) @Column(name = "DATE_CREATE") private Date dateCreate; @Temporal(TemporalType.TIMESTAMP) @Column(name = "DATE_UPDATE") private Date dateUpdate; public Tax() { this.dateCreate = new Date(); this.dateUpdate = new Date(); } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public int getVersion() { return version; } public void setVersion(int version) { this.version = version; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public BigDecimal getPercent() { return percent; } public void setPercent(BigDecimal percent) { this.percent = percent; } public Set<TaxType> getTaxTypes() { return taxTypes; } public void setTaxTypes(Set<TaxType> taxTypes) { this.taxTypes = taxTypes; } public Date getDateCreate() { return dateCreate; } public void setDateCreate(Date dateCreate) { this.dateCreate = dateCreate; } public Date getDateUpdate() { return dateUpdate; } public void setDateUpdate(Date dateUpdate) { this.dateUpdate = dateUpdate; } public Set<TaxCountry> getTaxCountries() { return taxCountries; } public void setTaxeCountries(Set<TaxCountry> taxCountries) { this.taxCountries = taxCountries; } public Set<TaxAttribute> getAttributes() { return attributes; } public void setAttributes(Set<TaxAttribute> attributes) { this.attributes = attributes; } public Set<MarketArea> getMarketAreas() { return marketAreas; } public void setMarketAreas(Set<MarketArea> marketAreas) { this.marketAreas = marketAreas; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((code == null) ? 0 : code.hashCode()); result = prime * result + ((dateCreate == null) ? 0 : dateCreate.hashCode()); result = prime * result + ((id == null) ? 0 : id.hashCode()); return result; } @Override public boolean equals(Object sourceObj) { Object obj = deproxy(sourceObj); if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Tax other = (Tax) obj; if (code == null) { if (other.code != null) return false; } else if (!code.equals(other.code)) return false; if (dateCreate == null) { if (other.dateCreate != null) return false; } else if (!dateCreate.equals(other.dateCreate)) return false; if (id == null) { if (other.id != null) return false; } else if (!id.equals(other.id)) return false; return true; } @Override public String toString() { return "Tax [id=" + id + ", version=" + version + ", code=" + code + ", name=" + name + ", description=" + description + ", percent=" + percent + ", taxCountries=" + taxCountries + ", attributes=" + attributes + ", dateCreate=" + dateCreate + ", dateUpdate=" + dateUpdate + "]"; } }