Промежуточное сохранение.
This commit is contained in:
parent
438e1ed4d4
commit
9297fb06ae
@ -1,7 +1,9 @@
|
||||
package labWork.premium_store.model;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
public class Tank {
|
||||
@ -20,18 +22,23 @@ public class Tank {
|
||||
@JoinColumn(name = "level_id")
|
||||
private Level level;
|
||||
|
||||
@Column(nullable = false)
|
||||
private int cost;
|
||||
|
||||
//реализация двунаправленной связи мнокие-ко-многим
|
||||
@ManyToMany
|
||||
@JoinTable(name = "tanks_of_clients",
|
||||
joinColumns = @JoinColumn(name = "tank_fk"),
|
||||
inverseJoinColumns = @JoinColumn(name = "client_fk"))
|
||||
private List<Client> clients;
|
||||
|
||||
@Column(nullable = false)
|
||||
private int cost;
|
||||
|
||||
public Tank() {
|
||||
}
|
||||
|
||||
public Long getId(){
|
||||
return id;
|
||||
}
|
||||
|
||||
public Tank(String name, int cost) {
|
||||
this.name = name;
|
||||
this.cost = cost;
|
||||
@ -53,35 +60,57 @@ public class Tank {
|
||||
this.cost = cost;
|
||||
}
|
||||
|
||||
public List<OrderProducts> getProducts() {
|
||||
return products;
|
||||
public Level getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setProducts(List<OrderProducts> products) {
|
||||
this.products = products;
|
||||
public void setLevel(Level level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public void addProduct(OrderProducts orderProducts){
|
||||
if (products == null){
|
||||
this.products = new ArrayList<>();
|
||||
public Nation getNation() {
|
||||
return nation;
|
||||
}
|
||||
|
||||
public void setNation(Nation nation) {
|
||||
this.nation = nation;
|
||||
}
|
||||
|
||||
public List<Client> getClients() {
|
||||
return clients;
|
||||
}
|
||||
|
||||
public void setClients(List<Client> clients) {
|
||||
this.clients = clients;
|
||||
}
|
||||
|
||||
public void addClient(Client newClient){
|
||||
if (clients == null){
|
||||
this.clients = new ArrayList<>();
|
||||
}
|
||||
if (!products.contains(orderProducts))
|
||||
this.products.add(orderProducts);
|
||||
|
||||
if (!clients.contains(newClient))
|
||||
this.clients.add(newClient);
|
||||
}
|
||||
public void removeProducts(OrderProducts orderProducts){
|
||||
if (products.contains(orderProducts))
|
||||
this.products.remove(orderProducts);
|
||||
|
||||
public void removeClient(Client remClient){
|
||||
if (clients.contains(remClient))
|
||||
this.clients.remove(remClient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Order order)) return false;
|
||||
return Objects.equals(getId(), order.getId()) && Objects.equals(getDate(), order.getDate()) && Objects.equals(getPrice(), order.getPrice());
|
||||
|
||||
if (!(o instanceof Tank tank)) return false;
|
||||
|
||||
return Objects.equals(getId(), tank.getId()) && Objects.equals(getName(), tank.getName())
|
||||
&& Objects.equals(getCost(), tank.getCost()) && Objects.equals(getClients(), tank.getClients())
|
||||
&& Objects.equals(getLevel(), tank.getLevel());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(getId(), getDate(), getPrice());
|
||||
return Objects.hash(getId(), getName(), getLevel(), getClients(), getCost());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user