bizzcuit

BookEntity

Sep 25th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. package com.rewe.exercise.bookstore.book;
  2.  
  3. import com.rewe.exercise.bookstore.author.AuthorEntity;
  4. import com.rewe.exercise.bookstore.bookstore.BookstoreEntity;
  5. import com.rewe.exercise.bookstore.storage.StorageEntity;
  6.  
  7. import javax.persistence.*;
  8. import java.math.BigInteger;
  9. import java.util.ArrayList;
  10. import java.util.List;
  11. import java.util.Objects;
  12.  
  13. @Entity(name = "Book")
  14. @Table(name = "books")
  15. public class BookEntity {
  16.  
  17. @Id
  18. @Column(name = "id")
  19. @GeneratedValue(strategy = GenerationType.IDENTITY)
  20. private BigInteger id;
  21.  
  22. private Long isbn;
  23.  
  24. private String title;
  25.  
  26. private String publisher;
  27.  
  28. private int year;
  29.  
  30. private double price;
  31.  
  32. @Column(name = "quantity")
  33. private int availableQuantity;
  34.  
  35. @ManyToMany(mappedBy = "authorBooks", cascade = CascadeType.ALL)
  36. private List<AuthorEntity> authors = new ArrayList<>();
  37.  
  38. @ManyToMany(mappedBy = "storageBooks")
  39. private List<StorageEntity> storages = new ArrayList<>();
  40.  
  41. @ManyToMany(mappedBy = "bookstoreBooks")
  42. private List<BookstoreEntity> bookstores = new ArrayList<>();
  43.  
  44. public BigInteger getId() {
  45. return id;
  46. }
  47.  
  48. public void setId(BigInteger id) {
  49. this.id = id;
  50. }
  51.  
  52. public Long getIsbn() {
  53. return isbn;
  54. }
  55.  
  56. public void setIsbn(Long isbn) {
  57. this.isbn = isbn;
  58. }
  59.  
  60. public String getTitle() {
  61. return title;
  62. }
  63.  
  64. public void setTitle(String title) {
  65. this.title = title;
  66. }
  67.  
  68. String getPublisher() {
  69. return publisher;
  70. }
  71.  
  72. void setPublisher(String publisher) {
  73. this.publisher = publisher;
  74. }
  75.  
  76. int getYear() {
  77. return year;
  78. }
  79.  
  80. void setYear(int year) {
  81. this.year = year;
  82. }
  83.  
  84. double getPrice() {
  85. return price;
  86. }
  87.  
  88. public void setPrice(double price) {
  89. this.price = price;
  90. }
  91.  
  92. public int getAvailableQuantity() {
  93. return availableQuantity;
  94. }
  95.  
  96. public void setAvailableQuantity(int quantity) {
  97. this.availableQuantity = quantity;
  98. }
  99.  
  100. List<AuthorEntity> getAuthors() {
  101. return authors;
  102. }
  103.  
  104. public void setAuthors(List<AuthorEntity> authors) {
  105. this.authors = authors;
  106. authors.forEach(author -> author.getAuthorBooks().add(this));
  107. }
  108.  
  109. public List<StorageEntity> getStorages() {
  110. return storages;
  111. }
  112.  
  113. public void setStorages(List<StorageEntity> storages) {
  114. this.storages = storages;
  115. }
  116.  
  117. public List<BookstoreEntity> getBookstores() {
  118. return bookstores;
  119. }
  120.  
  121. public void setBookstores(List<BookstoreEntity> bookstores) {
  122. this.bookstores = bookstores;
  123. }
  124.  
  125. @Override
  126. public boolean equals(Object o) {
  127. if (this == o) return true;
  128. if (o == null || getClass() != o.getClass()) return false;
  129. BookEntity book = (BookEntity) o;
  130. return year == book.year &&
  131. Double.compare(book.price, price) == 0 &&
  132. Objects.equals(id, book.id) &&
  133. Objects.equals(title, book.title) &&
  134. Objects.equals(publisher, book.publisher) &&
  135. Objects.equals(storages, book.storages) &&
  136. Objects.equals(bookstores, book.bookstores);
  137. }
  138.  
  139. @Override
  140. public int hashCode() {
  141. return Objects.hash(id, title, publisher, year, price, storages, bookstores);
  142. }
  143.  
  144. @Override
  145. public String toString() {
  146. return "Book{" +
  147. "id=" + id +
  148. ", title='" + title + '\'' +
  149. ", publisher='" + publisher + '\'' +
  150. ", year=" + year +
  151. ", price=" + price +
  152. ", storages=" + storages +
  153. ", bookstores=" + bookstores +
  154. '}';
  155. }
  156. }
Add Comment
Please, Sign In to add comment