use of ninja.jpa.UnitOfWork in project ninja by ninjaframework.
the class ArticleDao method getAllArticles.
@UnitOfWork
public ArticlesDto getAllArticles() {
EntityManager entityManager = entitiyManagerProvider.get();
TypedQuery<Article> query = entityManager.createQuery("SELECT x FROM Article x", Article.class);
List<Article> articles = query.getResultList();
ArticlesDto articlesDto = new ArticlesDto();
articlesDto.articles = articles;
return articlesDto;
}
use of ninja.jpa.UnitOfWork in project ninja by ninjaframework.
the class ArticleDao method getArticle.
@UnitOfWork
public Article getArticle(Long id) {
EntityManager entityManager = entitiyManagerProvider.get();
Query q = entityManager.createQuery("SELECT x FROM Article x WHERE x.id = :idParam");
Article article = (Article) q.setParameter("idParam", id).getSingleResult();
return article;
}
use of ninja.jpa.UnitOfWork in project ninja by ninjaframework.
the class ArticleDao method getOlderArticlesForFrontPage.
@UnitOfWork
public List<Article> getOlderArticlesForFrontPage() {
EntityManager entityManager = entitiyManagerProvider.get();
Query q = entityManager.createQuery("SELECT x FROM Article x ORDER BY x.postedAt DESC");
List<Article> articles = (List<Article>) q.setFirstResult(1).setMaxResults(10).getResultList();
return articles;
}
use of ninja.jpa.UnitOfWork in project ninja by ninjaframework.
the class ArticleDao method getFirstArticleForFrontPage.
@UnitOfWork
public Article getFirstArticleForFrontPage() {
EntityManager entityManager = entitiyManagerProvider.get();
Query q = entityManager.createQuery("SELECT x FROM Article x ORDER BY x.postedAt DESC");
Article article = (Article) q.setMaxResults(1).getSingleResult();
return article;
}
use of ninja.jpa.UnitOfWork in project ninja by ninjaframework.
the class UserDao method isUserAndPasswordValid.
@UnitOfWork
public boolean isUserAndPasswordValid(String username, String password) {
if (username != null && password != null) {
EntityManager entityManager = entityManagerProvider.get();
TypedQuery<User> q = entityManager.createQuery("SELECT x FROM User x WHERE username = :usernameParam", User.class);
User user = getSingleResult(q.setParameter("usernameParam", username));
if (user != null) {
if (user.password.equals(password)) {
return true;
}
}
}
return false;
}
Aggregations