Commit cc7d5e43 by Patryk Czarnik

dodanie klas encji z bazy sklep

parent 019a342f
package sklep.model;
import jakarta.persistence.*;
import java.util.LinkedHashSet;
import java.util.Set;
@Entity
@Table(name = "customers")
public class Customer {
@Id
@Column(name = "customer_email", nullable = false, length = 100)
private String customerEmail;
@Column(name = "customer_name", nullable = false, length = 100)
private String customerName;
@Column(name = "phone_number", length = 20)
private String phoneNumber;
@Column(name = "address", length = 250)
private String address;
@Column(name = "postal_code", length = 10)
private String postalCode;
@Column(name = "city", length = 100)
private String city;
@OneToMany(mappedBy = "customer")
private Set<Order> orders = new LinkedHashSet<>();
public String getCustomerEmail() {
return customerEmail;
}
public void setCustomerEmail(String customerEmail) {
this.customerEmail = customerEmail;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getPostalCode() {
return postalCode;
}
public void setPostalCode(String postalCode) {
this.postalCode = postalCode;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public Set<Order> getOrders() {
return orders;
}
public void setOrders(Set<Order> orders) {
this.orders = orders;
}
}
\ No newline at end of file
package sklep.model;
import jakarta.persistence.*;
import org.hibernate.annotations.ColumnDefault;
import java.time.Instant;
import java.time.LocalDate;
import java.util.LinkedHashSet;
import java.util.Set;
@Entity
@Table(name = "orders")
public class Order {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ColumnDefault("nextval('orders_seq'::regclass)")
@Column(name = "order_id", nullable = false)
private Integer id;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "customer_email", nullable = false)
private Customer customer;
@ColumnDefault("CURRENT_TIMESTAMP")
@Column(name = "order_date", nullable = false)
private Instant orderDate;
@Column(name = "delivery_date")
private LocalDate deliveryDate;
@OneToMany(mappedBy = "order")
private Set<OrderProduct> orderProducts = new LinkedHashSet<>();
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customerEmail) {
this.customer = customerEmail;
}
public Instant getOrderDate() {
return orderDate;
}
public void setOrderDate(Instant orderDate) {
this.orderDate = orderDate;
}
public LocalDate getDeliveryDate() {
return deliveryDate;
}
public void setDeliveryDate(LocalDate deliveryDate) {
this.deliveryDate = deliveryDate;
}
public Set<OrderProduct> getOrderProducts() {
return orderProducts;
}
public void setOrderProducts(Set<OrderProduct> orderProducts) {
this.orderProducts = orderProducts;
}
/*
TODO [Reverse Engineering] create field to map the 'status' column
Available actions: Define target Java type | Uncomment as is | Remove column mapping
@ColumnDefault("'NEW'::order_status")
@Column(name = "status", columnDefinition = "order_status not null")
private Object status;
*/
}
\ No newline at end of file
package sklep.model;
import jakarta.persistence.*;
import org.hibernate.annotations.ColumnDefault;
import java.math.BigDecimal;
@Entity
@Table(name = "order_products")
public class OrderProduct {
@EmbeddedId
private OrderProductId id;
@MapsId("orderId")
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "order_id", nullable = false)
private Order order;
@MapsId("productId")
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "product_id", nullable = false)
private Product product;
@ColumnDefault("1")
@Column(name = "quantity", nullable = false)
private Short quantity;
@Column(name = "actual_price", nullable = false, precision = 10, scale = 2)
private BigDecimal actualPrice;
@Column(name = "actual_vat", precision = 2, scale = 2)
private BigDecimal actualVat;
public OrderProductId getId() {
return id;
}
public void setId(OrderProductId id) {
this.id = id;
}
public Order getOrder() {
return order;
}
public void setOrder(Order order) {
this.order = order;
}
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
public Short getQuantity() {
return quantity;
}
public void setQuantity(Short quantity) {
this.quantity = quantity;
}
public BigDecimal getActualPrice() {
return actualPrice;
}
public void setActualPrice(BigDecimal actualPrice) {
this.actualPrice = actualPrice;
}
public BigDecimal getActualVat() {
return actualVat;
}
public void setActualVat(BigDecimal actualVat) {
this.actualVat = actualVat;
}
}
\ No newline at end of file
package sklep.model;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import org.hibernate.Hibernate;
import java.util.Objects;
@Embeddable
public class OrderProductId implements java.io.Serializable {
private static final long serialVersionUID = -675988817260271390L;
@Column(name = "order_id", nullable = false)
private Integer orderId;
@Column(name = "product_id", nullable = false)
private Integer productId;
public Integer getOrderId() {
return orderId;
}
public void setOrderId(Integer orderId) {
this.orderId = orderId;
}
public Integer getProductId() {
return productId;
}
public void setProductId(Integer productId) {
this.productId = productId;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
OrderProductId entity = (OrderProductId) o;
return Objects.equals(this.productId, entity.productId) &&
Objects.equals(this.orderId, entity.orderId);
}
@Override
public int hashCode() {
return Objects.hash(productId, orderId);
}
}
\ No newline at end of file
package sklep.model;
import jakarta.persistence.*;
import org.hibernate.annotations.ColumnDefault;
import java.math.BigDecimal;
@Entity
@Table(name = "products")
@NamedQuery(name="Product.findAll", query="SELECT p FROM Product p ORDER BY p.id")
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ColumnDefault("nextval('products_seq'::regclass)")
@Column(name = "product_id", nullable = false)
private Integer id;
@Column(name = "product_name", nullable = false, length = 100)
private String productName;
@Column(name = "price", nullable = false, precision = 10, scale = 2)
private BigDecimal price;
@Column(name = "vat", precision = 2, scale = 2)
private BigDecimal vat;
@Column(name = "description", length = Integer.MAX_VALUE)
private String description;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public BigDecimal getVat() {
return vat;
}
public void setVat(BigDecimal vat) {
this.vat = vat;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment