From 708184146f4bd4ebdedb89a76dd0bd25702dcd03 Mon Sep 17 00:00:00 2001 From: meliurwen Date: Sun, 12 Jan 2020 22:58:54 +0100 Subject: [PATCH] Test book fix --- mivan/src/main/java/mivan/model/Book.java | 12 ++++++------ .../java/mivan/repository/AuthorRepository.java | 4 ++-- .../mivan/repository/AuthorRepositoryImpl.java | 4 ++-- .../java/mivan/repository/BookRepository.java | 9 ++++----- .../java/mivan/repository/BookRepositoryImpl.java | 15 ++++++++++----- 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/mivan/src/main/java/mivan/model/Book.java b/mivan/src/main/java/mivan/model/Book.java index 3c75b49..96e14b7 100644 --- a/mivan/src/main/java/mivan/model/Book.java +++ b/mivan/src/main/java/mivan/model/Book.java @@ -17,11 +17,11 @@ import javax.persistence.Table; @Table(name = "book") public class Book implements Serializable { - private static final long serialVersionUID = -5124436115031696628L; + private static final long serialVersionUID = 19L; @Id - @Column(name = "isbn", nullable=false) - private int isbn; + @Column(name = "isbn", nullable=false, unique=true) + private long isbn; @Column(name = "title", nullable=false) private String title; @@ -39,14 +39,14 @@ public class Book implements Serializable { public Book() { } - public Book(int isbn, String title, Book prequel) { + public Book(long isbn, String title, Book prequel) { this.isbn = isbn; this.title = title; this.prequel = prequel; this.authors = new ArrayList(); } - public int getIsbn() { + public long getIsbn() { return isbn; } @@ -58,7 +58,7 @@ public class Book implements Serializable { return prequel; } - public void setIsbn(int isbn) { + public void setIsbn(long isbn) { this.isbn = isbn; } diff --git a/mivan/src/main/java/mivan/repository/AuthorRepository.java b/mivan/src/main/java/mivan/repository/AuthorRepository.java index ab2b72a..b5fc0d2 100644 --- a/mivan/src/main/java/mivan/repository/AuthorRepository.java +++ b/mivan/src/main/java/mivan/repository/AuthorRepository.java @@ -12,9 +12,9 @@ public interface AuthorRepository extends Repository { public Author searchAuthorByName(String name); - public void addBook(int isbn, long id); + public void addBook(Long isbn, Long id); - public void removeBook(int isbn, long id); + public void removeBook(Long isbn, Long id); public int getSize(); } diff --git a/mivan/src/main/java/mivan/repository/AuthorRepositoryImpl.java b/mivan/src/main/java/mivan/repository/AuthorRepositoryImpl.java index 0e5086a..ea0d85b 100644 --- a/mivan/src/main/java/mivan/repository/AuthorRepositoryImpl.java +++ b/mivan/src/main/java/mivan/repository/AuthorRepositoryImpl.java @@ -115,7 +115,7 @@ public class AuthorRepositoryImpl implements AuthorRepository { } @Override - public void addBook(int isbn, long id) { + public void addBook(Long isbn, Long id) { final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); try { if (!entityManager.getTransaction().isActive()) { @@ -134,7 +134,7 @@ public class AuthorRepositoryImpl implements AuthorRepository { } @Override - public void removeBook(int isbn, long id) { + public void removeBook(Long isbn, Long id) { final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); try { if (!entityManager.getTransaction().isActive()) { diff --git a/mivan/src/main/java/mivan/repository/BookRepository.java b/mivan/src/main/java/mivan/repository/BookRepository.java index 63f0465..ba772ae 100644 --- a/mivan/src/main/java/mivan/repository/BookRepository.java +++ b/mivan/src/main/java/mivan/repository/BookRepository.java @@ -1,23 +1,22 @@ package mivan.repository; -import mivan.model.Author; import mivan.model.Book; public interface BookRepository extends Repository{ //public Optional findUserAddressById(Long id); - public void deleteBookById(int isbn); + public void deleteBookById(Long isbn); public void addBook(Book book); - public void updateBook(int isbn, String title, Book prequel); + public void updateBook(Long isbn, String title, Book prequel); public Book searchBookByTitle(String title); - public void addAuthor(int isbn, long id); + public void addAuthor(Long isbn, Long id); - public void removeAuthor(int isbn, long id); + public void removeAuthor(Long isbn, Long id); public int getSize(); } diff --git a/mivan/src/main/java/mivan/repository/BookRepositoryImpl.java b/mivan/src/main/java/mivan/repository/BookRepositoryImpl.java index 72cd1b7..4c0006e 100644 --- a/mivan/src/main/java/mivan/repository/BookRepositoryImpl.java +++ b/mivan/src/main/java/mivan/repository/BookRepositoryImpl.java @@ -5,6 +5,7 @@ import java.util.Optional; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; import mivan.model.Author; import mivan.model.Book; @@ -13,6 +14,10 @@ public class BookRepositoryImpl implements BookRepository { private EntityManagerFactory entityManagerFactory; + public BookRepositoryImpl(){ + this.entityManagerFactory = Persistence.createEntityManagerFactory("mivan"); + } + @Override public Optional findById(Long id) { final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); @@ -30,7 +35,7 @@ public class BookRepositoryImpl implements BookRepository { } @Override - public void deleteBookById(int isbn) { + public void deleteBookById(Long isbn) { final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); try { if (!entityManager.getTransaction().isActive()) { @@ -46,7 +51,7 @@ public class BookRepositoryImpl implements BookRepository { } @Override - public void addBook(Book book) { + public void addBook(Book book) { final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); try { if (!entityManager.getTransaction().isActive()) { @@ -62,7 +67,7 @@ public class BookRepositoryImpl implements BookRepository { } @Override - public void updateBook(int isbn, String title, Book prequel) { + public void updateBook(Long isbn, String title, Book prequel) { final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); try { if (!entityManager.getTransaction().isActive()) { @@ -115,7 +120,7 @@ public class BookRepositoryImpl implements BookRepository { @Override - public void addAuthor(int isbn, long id) { + public void addAuthor(Long isbn, Long id) { final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); try { if (!entityManager.getTransaction().isActive()) { @@ -134,7 +139,7 @@ public class BookRepositoryImpl implements BookRepository { } @Override - public void removeAuthor(int isbn, long id) { + public void removeAuthor(Long isbn, Long id) { final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); try { if (!entityManager.getTransaction().isActive()) {