Browse Source

Implement findAllPublished method for BookRepository

Signed-off-by: Pekka Helenius <fincer89@hotmail.com>
v0.0.3-alpha
Pekka Helenius 4 years ago
parent
commit
1651eae80c
2 changed files with 27 additions and 0 deletions
  1. +3
    -0
      bookstore/src/main/java/com/fjordtek/bookstore/model/book/BookRepositoryCustom.java
  2. +24
    -0
      bookstore/src/main/java/com/fjordtek/bookstore/model/book/BookRepositoryImpl.java

+ 3
- 0
bookstore/src/main/java/com/fjordtek/bookstore/model/book/BookRepositoryCustom.java View File

@ -1,5 +1,7 @@
package com.fjordtek.bookstore.model.book; package com.fjordtek.bookstore.model.book;
import java.util.List;
/** /**
* *
* @author Pekka Helenius * @author Pekka Helenius
@ -9,4 +11,5 @@ public interface BookRepositoryCustom {
void updateWithoutPrice(Book book); void updateWithoutPrice(Book book);
List<Book> findAllPublished();
} }

+ 24
- 0
bookstore/src/main/java/com/fjordtek/bookstore/model/book/BookRepositoryImpl.java View File

@ -1,8 +1,11 @@
package com.fjordtek.bookstore.model.book; package com.fjordtek.bookstore.model.book;
import java.util.List;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext; import javax.persistence.PersistenceContext;
import javax.persistence.Query; import javax.persistence.Query;
import javax.persistence.TypedQuery;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -54,4 +57,25 @@ public class BookRepositoryImpl implements BookRepositoryCustom {
} }
/*
* Find all published books
*/
@Override
public List<Book> findAllPublished() {
try {
TypedQuery<Book> query = entityManager.createQuery(
"SELECT i FROM Book i WHERE publish = 1",
Book.class
);
return query.getResultList();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
} }

Loading…
Cancel
Save