use of javax.persistence.criteria.CriteriaBuilder in project nikita-noark5-core by HiOA-ABI.
the class FondsCreatorService method findFondsCreatorByOwnerPaginated.
// All READ operations
@Override
public List<FondsCreator> findFondsCreatorByOwnerPaginated(Integer top, Integer skip) {
if (top == null || top > maxPageSize) {
top = maxPageSize;
}
if (skip == null) {
skip = 0;
}
String loggedInUser = SecurityContextHolder.getContext().getAuthentication().getName();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<FondsCreator> criteriaQuery = criteriaBuilder.createQuery(FondsCreator.class);
Root<FondsCreator> from = criteriaQuery.from(FondsCreator.class);
CriteriaQuery<FondsCreator> select = criteriaQuery.select(from);
criteriaQuery.where(criteriaBuilder.equal(from.get("ownedBy"), loggedInUser));
TypedQuery<FondsCreator> typedQuery = entityManager.createQuery(select);
typedQuery.setFirstResult(skip);
typedQuery.setMaxResults(maxPageSize);
return typedQuery.getResultList();
}
use of javax.persistence.criteria.CriteriaBuilder in project nikita-noark5-core by HiOA-ABI.
the class FondsService method findFondsByOwnerPaginated.
// All READ operations
public List<Fonds> findFondsByOwnerPaginated(Integer top, Integer skip) {
if (top == null || top > maxPageSize) {
top = maxPageSize;
}
if (skip == null) {
skip = 0;
}
String loggedInUser = SecurityContextHolder.getContext().getAuthentication().getName();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Fonds> criteriaQuery = criteriaBuilder.createQuery(Fonds.class);
Root<Fonds> from = criteriaQuery.from(Fonds.class);
CriteriaQuery<Fonds> select = criteriaQuery.select(from);
criteriaQuery.where(criteriaBuilder.equal(from.get("ownedBy"), loggedInUser));
TypedQuery<Fonds> typedQuery = entityManager.createQuery(select);
typedQuery.setFirstResult(skip);
typedQuery.setMaxResults(maxPageSize);
return typedQuery.getResultList();
}
use of javax.persistence.criteria.CriteriaBuilder in project tomee by apache.
the class MoviesBean method getMovies.
public List<Movie> getMovies(Integer firstResult, Integer maxResults, String field, String searchTerm) {
CriteriaBuilder qb = entityManager.getCriteriaBuilder();
CriteriaQuery<Movie> cq = qb.createQuery(Movie.class);
Root<Movie> root = cq.from(Movie.class);
EntityType<Movie> type = entityManager.getMetamodel().entity(Movie.class);
if (field != null && searchTerm != null && !"".equals(field.trim()) && !"".equals(searchTerm.trim())) {
Path<String> path = root.get(type.getDeclaredSingularAttribute(field.trim(), String.class));
Predicate condition = qb.like(path, "%" + searchTerm.trim() + "%");
cq.where(condition);
}
TypedQuery<Movie> q = entityManager.createQuery(cq);
if (maxResults != null) {
q.setMaxResults(maxResults);
}
if (firstResult != null) {
q.setFirstResult(firstResult);
}
return q.getResultList();
}
use of javax.persistence.criteria.CriteriaBuilder in project tomee by apache.
the class MoviesBean method count.
public int count(String field, String searchTerm) {
CriteriaBuilder qb = entityManager.getCriteriaBuilder();
CriteriaQuery<Long> cq = qb.createQuery(Long.class);
Root<Movie> root = cq.from(Movie.class);
EntityType<Movie> type = entityManager.getMetamodel().entity(Movie.class);
Path<String> path = root.get(type.getDeclaredSingularAttribute(field, String.class));
Predicate condition = qb.like(path, "%" + searchTerm + "%");
cq.select(qb.count(root));
cq.where(condition);
return entityManager.createQuery(cq).getSingleResult().intValue();
}
use of javax.persistence.criteria.CriteriaBuilder in project jgnash by ccavanaugh.
the class JpaCommodityDAO method getSecurities.
/*
* @see jgnash.engine.dao.CommodityDAO#getSecurities()
*/
@Override
@NotNull
public List<SecurityNode> getSecurities() {
List<SecurityNode> securityNodeList = Collections.emptyList();
try {
Future<List<SecurityNode>> future = executorService.submit(() -> {
emLock.lock();
try {
final CriteriaBuilder cb = em.getCriteriaBuilder();
final CriteriaQuery<SecurityNode> cq = cb.createQuery(SecurityNode.class);
Root<SecurityNode> root = cq.from(SecurityNode.class);
cq.select(root);
TypedQuery<SecurityNode> q = em.createQuery(cq);
return stripMarkedForRemoval(new ArrayList<>(q.getResultList()));
} finally {
emLock.unlock();
}
});
securityNodeList = future.get();
} catch (final InterruptedException | ExecutionException e) {
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
return securityNodeList;
}
Aggregations