diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/model/book/BookRepositoryCustom.java b/bookstore/src/main/java/com/fjordtek/bookstore/model/book/BookRepositoryCustom.java index c93e555..a8ce905 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/model/book/BookRepositoryCustom.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/model/book/BookRepositoryCustom.java @@ -1,5 +1,7 @@ package com.fjordtek.bookstore.model.book; +import java.util.List; + /** * * @author Pekka Helenius @@ -9,4 +11,5 @@ public interface BookRepositoryCustom { void updateWithoutPrice(Book book); + List findAllPublished(); } \ No newline at end of file diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/model/book/BookRepositoryImpl.java b/bookstore/src/main/java/com/fjordtek/bookstore/model/book/BookRepositoryImpl.java index 5f5d778..e2d248a 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/model/book/BookRepositoryImpl.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/model/book/BookRepositoryImpl.java @@ -1,8 +1,11 @@ package com.fjordtek.bookstore.model.book; +import java.util.List; + import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.persistence.Query; +import javax.persistence.TypedQuery; import org.springframework.transaction.annotation.Transactional; @@ -54,4 +57,25 @@ public class BookRepositoryImpl implements BookRepositoryCustom { } + /* + * Find all published books + */ + @Override + public List findAllPublished() { + try { + + TypedQuery query = entityManager.createQuery( + "SELECT i FROM Book i WHERE publish = 1", + Book.class + ); + + return query.getResultList(); + + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + } \ No newline at end of file