/* * Created on: 16-Jan-2006 * Author: Dibyendu Majumdar */ package schema1.entity.tpcc; import java.math.BigDecimal; import java.util.Set; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.IdClass; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; import javax.persistence.TableGenerator; import javax.persistence.Version; @Entity @Table(name = "DISTRICT", schema = "TPCC") @IdClass(schema1.entity.tpcc.District.DistrictPK.class) public class District { Warehouse warehouse; int id; int warehouseId; int version = 1; String name; String street1; String street2; String city; String state; String zip; BigDecimal tax = new BigDecimal(0); BigDecimal ytd = new BigDecimal(0); BigDecimal nextOId = new BigDecimal(0); Set customers; @Column(name = "D_CITY", length = 20) public String getCity() { return city; } @Id @Column(name = "D_ID", nullable=false) @TableGenerator(name = "DISTRICT_ID_SEQUENCE", table = "IDGENERATOR", schema = "TPCC", pkColumnName = "SEQ_NAME", valueColumnName = "SEQ_COUNT", pkColumnValue = "DISTRICT_ID_SEQUENCE", initialValue=1, allocationSize=10) @GeneratedValue(strategy = GenerationType.TABLE, generator = "DISTRICT_ID_SEQUENCE") public int getId() { return id; } @Column(name = "D_NAME", nullable = false, length = 10) public String getName() { return name; } @Column(name = "D_NEXT_O_ID", precision = 8, scale = 0) public BigDecimal getNextOId() { return nextOId; } @Column(name = "D_STATE", length = 2) public String getState() { return state; } @Column(name = "D_STREET_1", length = 20) public String getStreet1() { return street1; } @Column(name = "D_STREET_2", length = 20) public String getStreet2() { return street2; } @Column(name = "D_TAX", precision = 4, scale = 0) public BigDecimal getTax() { return tax; } @Version @Column(name = "D_VERSION") public int getVersion() { return version; } @ManyToOne @JoinColumn(name = "D_W_ID", referencedColumnName = "W_ID") public Warehouse getWarehouse() { return warehouse; } @Column(name = "D_YTD", precision = 12, scale = 0) public BigDecimal getYtd() { return ytd; } @Column(name = "D_ZIP", length = 9) public String getZip() { return zip; } @Id @Column(name = "D_W_ID", nullable=false, insertable=false, updatable=false) public int getWarehouseId() { return warehouseId; } @OneToMany(mappedBy="district") public Set getCustomers() { return customers; } public void setCustomers(Set customers) { this.customers = customers; } public void setWarehouseId(int warehouseId) { this.warehouseId = warehouseId; } public void setCity(String city) { this.city = city; } public void setId(int id) { this.id = id; } public void setName(String name) { this.name = name; } public void setNextOId(BigDecimal nextOId) { this.nextOId = nextOId; } public void setState(String state) { this.state = state; } public void setStreet1(String street1) { this.street1 = street1; } public void setStreet2(String street2) { this.street2 = street2; } public void setTax(BigDecimal tax) { this.tax = tax; } public void setVersion(int version) { this.version = version; } public void setWarehouse(Warehouse warehouse) { this.warehouse = warehouse; warehouse.getDistricts().add(this); } public void setYtd(BigDecimal ytd) { this.ytd = ytd; } public void setZip(String zip) { this.zip = zip; } @Override public String toString() { return "District(Id=" + id + ", name=" + name + ")"; } public static class DistrictPK { int id; int warehouseId; public int getId() { return id; } public int getWarehouseId() { return warehouseId; } public void setId(int id) { this.id = id; } public void setWarehouseId(int warehouseId) { this.warehouseId = warehouseId; } @Override public boolean equals(Object arg0) { if (arg0 == this) { return true; } else if (arg0 instanceof DistrictPK) { DistrictPK other = (DistrictPK) arg0; return id == other.id && warehouseId == other.warehouseId; } return false; } @Override public int hashCode() { return id ^ warehouseId; } } }