diff --git a/src/main/java/guru/springframework/spring5webapp/Bootstrap/BootStrapData.java b/src/main/java/guru/springframework/spring5webapp/Bootstrap/BootStrapData.java new file mode 100644 index 0000000000..e2646f3b3a --- /dev/null +++ b/src/main/java/guru/springframework/spring5webapp/Bootstrap/BootStrapData.java @@ -0,0 +1,4 @@ +package guru.springframework.spring5webapp.Bootstrap; + +public class BootStrapData { +} diff --git a/src/main/java/guru/springframework/spring5webapp/domain/Author.java b/src/main/java/guru/springframework/spring5webapp/domain/Author.java new file mode 100644 index 0000000000..583a6419ac --- /dev/null +++ b/src/main/java/guru/springframework/spring5webapp/domain/Author.java @@ -0,0 +1,85 @@ +package guru.springframework.spring5webapp.domain; + + +import javax.persistence.*; + +import java.util.Set; + +@Entity +public class Author { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + public long id; + + private String firstName; + private String lastName; + @ManyToMany + private Set books; + + public Author() { + } + + public String getFirstName() { + return firstName; + } + + public Author(String firstName, String lastName, Set books) { + this.firstName = firstName; + this.lastName = lastName; + this.books = books; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public Set getBooks() { + return books; + } + + public void setBooks(Set books) { + this.books = books; + } + + @Override + public String toString() { + return "Author{" + + "id=" + id + + ", firstName='" + firstName + '\'' + + ", lastName='" + lastName + '\'' + + ", books=" + books + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Author author = (Author) o; + + return id == author.id; + } + + @Override + public int hashCode() { + return (int) (id ^ (id >>> 32)); + } +} diff --git a/src/main/java/guru/springframework/spring5webapp/domain/Books.java b/src/main/java/guru/springframework/spring5webapp/domain/Books.java new file mode 100644 index 0000000000..5f75853dbc --- /dev/null +++ b/src/main/java/guru/springframework/spring5webapp/domain/Books.java @@ -0,0 +1,86 @@ +package guru.springframework.spring5webapp.domain; + +import javax.persistence.*; +import java.util.Set; + +@Entity +public class Books { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + private String title; + private String isbn; + + @ManyToMany + @JoinTable(name = "author_book", joinColumns = @JoinColumn(name = "books_id"), + inverseJoinColumns = @JoinColumn(name = "author_id")) + private Set authors; + + + public Books() { + } + + public Books(String title, String isbn, Set authors) { + this.title = title; + this.isbn = isbn; + this.authors = authors; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Set getAuthors() { + return authors; + } + + public void setAuthors(Set authors) { + this.authors = authors; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getIsbn() { + return isbn; + } + + public void setIsbn(String isbn) { + this.isbn = isbn; + } + + @Override + public String toString() { + return "Books{" + + "id=" + id + + ", title='" + title + '\'' + + ", isbn='" + isbn + '\'' + + ", authors=" + authors + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Books books = (Books) o; + + return id != null ? id.equals(books.id) : books.id == null; + } + + @Override + public int hashCode() { + return id != null ? id.hashCode() : 0; + } +} diff --git a/src/main/java/repositories/AuthorRepository.java b/src/main/java/repositories/AuthorRepository.java new file mode 100644 index 0000000000..85c6b77233 --- /dev/null +++ b/src/main/java/repositories/AuthorRepository.java @@ -0,0 +1,7 @@ +package repositories; + +import guru.springframework.spring5webapp.domain.Author; +import org.springframework.data.repository.CrudRepository; + +public interface AuthorRepository extends CrudRepository { +} diff --git a/src/main/java/repositories/BookRepository.java b/src/main/java/repositories/BookRepository.java new file mode 100644 index 0000000000..7a2b969dd6 --- /dev/null +++ b/src/main/java/repositories/BookRepository.java @@ -0,0 +1,7 @@ +package repositories; + +import guru.springframework.spring5webapp.domain.Books; +import org.springframework.data.repository.CrudRepository; + +public interface BookRepository extends CrudRepository { +}