Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. @Entity
  2. @Access(AccessType.FIELD) // so I can avoid using setters for fields that won't change
  3. public class Book {
  4.  
  5. @Id
  6. @GeneratedValue(strategy = GenerationType.IDENTITY)
  7. private Long bookId;
  8.  
  9. @Embedded
  10. private Isbn isbn;
  11. @Embedded
  12. private Title title;
  13. @Embedded
  14. private Author author;
  15. @Embedded
  16. private Genre genre;
  17. @Embedded
  18. private PublicationYear publicationYear;
  19. private BigDecimal price;
  20.  
  21. // jpa requirement
  22. public Book() {
  23. }
  24.  
  25. public Book(Isbn isbn, Title title, Author author, Genre genre, PublicationYear publicationYear,
  26. BigDecimal price) {
  27. this.isbn = isbn;
  28. this.title = title;
  29. this.author = author;
  30. this.genre = genre;
  31. this.publicationYear = publicationYear;
  32. this.price = price;
  33. }
  34.  
  35. public Long getBookId() {
  36. return bookId;
  37. }
  38.  
  39. public Isbn getIsbn() {
  40. return isbn;
  41. }
  42.  
  43. public Title getTitle() {
  44. return title;
  45. }
  46.  
  47. public Author getAuthor() {
  48. return author;
  49. }
  50.  
  51. public Genre getGenre() {
  52. return genre;
  53. }
  54.  
  55. public BigDecimal getPrice() {
  56. return price;
  57. }
  58.  
  59. public PublicationYear getPublicationYear() {
  60. return publicationYear;
  61. }
  62.  
  63. // setter for price is needed because price of the book can change (discounts and so on)
  64. public void setPrice(BigDecimal price) {
  65. this.price = price;
  66. }
  67.  
  68. }
  69.  
  70. public class Isbn {
  71. private String isbn;
  72.  
  73. // jpa requirement
  74. public Isbn() {
  75. }
  76.  
  77. public Isbn(String isbn) {
  78. this.isbn = isbn;
  79. }
  80.  
  81. public String getIsbn() {
  82. return isbn;
  83. }
  84.  
  85. @Override
  86. public boolean equals(Object o) {
  87. if (this == o) {
  88. return true;
  89. }
  90. if (o == null || getClass() != o.getClass()) {
  91. return false;
  92. }
  93.  
  94. Isbn isbn1 = (Isbn) o;
  95.  
  96. return isbn != null ? isbn.equals(isbn1.isbn) : isbn1.isbn == null;
  97. }
  98.  
  99. @Override
  100. public int hashCode() {
  101. return isbn != null ? isbn.hashCode() : 0;
  102. }
  103.  
  104. @Override
  105. public String toString() {
  106. return "Isbn{" +
  107. "isbn='" + isbn + ''' +
  108. '}';
  109. }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement