Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.rewe.exercise.bookstore.book;
- import com.rewe.exercise.bookstore.author.AuthorEntity;
- import com.rewe.exercise.bookstore.bookstore.BookstoreEntity;
- import com.rewe.exercise.bookstore.storage.StorageEntity;
- import javax.persistence.*;
- import java.math.BigInteger;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Objects;
- @Entity(name = "Book")
- @Table(name = "books")
- public class BookEntity {
- @Id
- @Column(name = "id")
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- private BigInteger id;
- private Long isbn;
- private String title;
- private String publisher;
- private int year;
- private double price;
- @Column(name = "quantity")
- private int availableQuantity;
- @ManyToMany(mappedBy = "authorBooks", cascade = CascadeType.ALL)
- private List<AuthorEntity> authors = new ArrayList<>();
- @ManyToMany(mappedBy = "storageBooks")
- private List<StorageEntity> storages = new ArrayList<>();
- @ManyToMany(mappedBy = "bookstoreBooks")
- private List<BookstoreEntity> bookstores = new ArrayList<>();
- public BigInteger getId() {
- return id;
- }
- public void setId(BigInteger id) {
- this.id = id;
- }
- public Long getIsbn() {
- return isbn;
- }
- public void setIsbn(Long isbn) {
- this.isbn = isbn;
- }
- public String getTitle() {
- return title;
- }
- public void setTitle(String title) {
- this.title = title;
- }
- String getPublisher() {
- return publisher;
- }
- void setPublisher(String publisher) {
- this.publisher = publisher;
- }
- int getYear() {
- return year;
- }
- void setYear(int year) {
- this.year = year;
- }
- double getPrice() {
- return price;
- }
- public void setPrice(double price) {
- this.price = price;
- }
- public int getAvailableQuantity() {
- return availableQuantity;
- }
- public void setAvailableQuantity(int quantity) {
- this.availableQuantity = quantity;
- }
- List<AuthorEntity> getAuthors() {
- return authors;
- }
- public void setAuthors(List<AuthorEntity> authors) {
- this.authors = authors;
- authors.forEach(author -> author.getAuthorBooks().add(this));
- }
- public List<StorageEntity> getStorages() {
- return storages;
- }
- public void setStorages(List<StorageEntity> storages) {
- this.storages = storages;
- }
- public List<BookstoreEntity> getBookstores() {
- return bookstores;
- }
- public void setBookstores(List<BookstoreEntity> bookstores) {
- this.bookstores = bookstores;
- }
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- BookEntity book = (BookEntity) o;
- return year == book.year &&
- Double.compare(book.price, price) == 0 &&
- Objects.equals(id, book.id) &&
- Objects.equals(title, book.title) &&
- Objects.equals(publisher, book.publisher) &&
- Objects.equals(storages, book.storages) &&
- Objects.equals(bookstores, book.bookstores);
- }
- @Override
- public int hashCode() {
- return Objects.hash(id, title, publisher, year, price, storages, bookstores);
- }
- @Override
- public String toString() {
- return "Book{" +
- "id=" + id +
- ", title='" + title + '\'' +
- ", publisher='" + publisher + '\'' +
- ", year=" + year +
- ", price=" + price +
- ", storages=" + storages +
- ", bookstores=" + bookstores +
- '}';
- }
- }
Add Comment
Please, Sign In to add comment