net.yadaframework.commerce.persistence.entity.YadaOrderItem Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yadawebcommerce Show documentation
Show all versions of yadawebcommerce Show documentation
Yada Framework for E-Commerce sites
The newest version!
package net.yadaframework.commerce.persistence.entity;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;
import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Inheritance;
import jakarta.persistence.InheritanceType;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;
import jakarta.persistence.Version;
import net.yadaframework.persistence.YadaMoney;
import net.yadaframework.persistence.YadaMoneyConverter;
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class YadaOrderItem implements Serializable {
private static final long serialVersionUID = 1L;
// For synchronization with external databases
@Column(insertable = false, updatable = false, columnDefinition="DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")
@Temporal(TemporalType.TIMESTAMP)
protected Date modified;
// For optimistic locking
@Version
protected long version;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
protected Long id;
protected int quantity;
@Convert(converter = YadaMoneyConverter.class)
protected YadaMoney unitPrice;
// Not a reference to YadaArticle so that we can delete old articles but still have the correct code in the order item
protected String articleCode;
@ManyToOne(optional=false)
protected YadaOrder order;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public YadaMoney getUnitPrice() {
return unitPrice;
}
public void setUnitPrice(YadaMoney unitPrice) {
this.unitPrice = unitPrice;
}
public YadaOrder getOrder() {
return order;
}
public void setOrder(YadaOrder order) {
this.order = order;
}
public String getArticleCode() {
return articleCode;
}
public void setArticleCode(String articleCode) {
this.articleCode = articleCode;
}
public Date getModified() {
return modified;
}
public void setModified(Date modified) {
this.modified = modified;
}
public long getVersion() {
return version;
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
YadaOrderItem other = (YadaOrderItem) obj;
return Objects.equals(id, other.id);
}
}