|
|
@ -5,6 +5,7 @@ import java.util.Optional; |
|
|
|
|
|
|
|
|
|
|
|
import javax.persistence.EntityManager; |
|
|
|
import javax.persistence.EntityManager; |
|
|
|
import javax.persistence.EntityManagerFactory; |
|
|
|
import javax.persistence.EntityManagerFactory; |
|
|
|
|
|
|
|
import javax.persistence.Persistence; |
|
|
|
|
|
|
|
|
|
|
|
import mivan.model.Author; |
|
|
|
import mivan.model.Author; |
|
|
|
import mivan.model.Book; |
|
|
|
import mivan.model.Book; |
|
|
@ -13,6 +14,10 @@ public class BookRepositoryImpl implements BookRepository { |
|
|
|
|
|
|
|
|
|
|
|
private EntityManagerFactory entityManagerFactory; |
|
|
|
private EntityManagerFactory entityManagerFactory; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public BookRepositoryImpl(){ |
|
|
|
|
|
|
|
this.entityManagerFactory = Persistence.createEntityManagerFactory("mivan"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Optional<Book> findById(Long id) { |
|
|
|
public Optional<Book> findById(Long id) { |
|
|
|
final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); |
|
|
|
final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); |
|
|
@ -30,7 +35,7 @@ public class BookRepositoryImpl implements BookRepository { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void deleteBookById(int isbn) { |
|
|
|
public void deleteBookById(Long isbn) { |
|
|
|
final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); |
|
|
|
final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
if (!entityManager.getTransaction().isActive()) { |
|
|
|
if (!entityManager.getTransaction().isActive()) { |
|
|
@ -62,7 +67,7 @@ public class BookRepositoryImpl implements BookRepository { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@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(); |
|
|
|
final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
if (!entityManager.getTransaction().isActive()) { |
|
|
|
if (!entityManager.getTransaction().isActive()) { |
|
|
@ -115,7 +120,7 @@ public class BookRepositoryImpl implements BookRepository { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void addAuthor(int isbn, long id) { |
|
|
|
public void addAuthor(Long isbn, Long id) { |
|
|
|
final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); |
|
|
|
final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
if (!entityManager.getTransaction().isActive()) { |
|
|
|
if (!entityManager.getTransaction().isActive()) { |
|
|
@ -134,7 +139,7 @@ public class BookRepositoryImpl implements BookRepository { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void removeAuthor(int isbn, long id) { |
|
|
|
public void removeAuthor(Long isbn, Long id) { |
|
|
|
final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); |
|
|
|
final EntityManager entityManager = this.entityManagerFactory.createEntityManager(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
if (!entityManager.getTransaction().isActive()) { |
|
|
|
if (!entityManager.getTransaction().isActive()) { |
|
|
|