當前位置: 首頁>>代碼示例>>Java>>正文


Java CriteriaBuilder類代碼示例

本文整理匯總了Java中javax.persistence.criteria.CriteriaBuilder的典型用法代碼示例。如果您正苦於以下問題:Java CriteriaBuilder類的具體用法?Java CriteriaBuilder怎麽用?Java CriteriaBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CriteriaBuilder類屬於javax.persistence.criteria包,在下文中一共展示了CriteriaBuilder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: findRecentRegionFrom

import javax.persistence.criteria.CriteriaBuilder; //導入依賴的package包/類
@GET
@Produces({"application/xml", "application/json"})
@Path("/recent/region/{regionName}/{orderLineId}")
public List<LiveSalesList> findRecentRegionFrom(@PathParam("regionName") String regionName, @PathParam("orderLineId") Integer orderLineId) {
    CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
    javax.persistence.criteria.CriteriaQuery cq = cb.createQuery();
    Root<LiveSalesList> liveSalesList = cq.from(LiveSalesList.class);
    cq.select(liveSalesList);
    cq.where(cb.and(
        cb.equal(liveSalesList.get(LiveSalesList_.region), regionName),
        cb.gt(liveSalesList.get(LiveSalesList_.orderLineId), orderLineId)
    ));
    Query q = getEntityManager().createQuery(cq);
    q.setMaxResults(500);
    return q.getResultList();
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:17,代碼來源:LiveSalesListFacadeREST.java

示例2: toPredicate

import javax.persistence.criteria.CriteriaBuilder; //導入依賴的package包/類
@Override
public Predicate toPredicate(Root<TestSuite> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
	Predicate result = null;

	if (StringUtils.isNotEmpty(filter.getSuite())) {
		result = criteriaBuilder.like(criteriaBuilder.lower(root.get(SUITE_PROPERTY)),
				buildLikeValue(filter.getSuite()));
	}

	return result;
}
 
開發者ID:ATLANTBH,項目名稱:owl,代碼行數:12,代碼來源:TestSuiteFilterSpecification.java

示例3: findByWordAndPackageNo

import javax.persistence.criteria.CriteriaBuilder; //導入依賴的package包/類
public Collection<ExtGraph> findByWordAndPackageNo(String word, int packageno) {

        Long pkg = new Long(packageno);
        CriteriaBuilder criteriaBuilder = getEntityManager().getCriteriaBuilder();
        CriteriaQuery<ExtGraph> criteriaQuery = criteriaBuilder.createQuery(ExtGraph.class
        );

        Root<ExtGraph> root = criteriaQuery.from(ExtGraph.class);
        Join<ExtGraph, Synset> synset = root.join("synset", JoinType.INNER);
        Join<Synset, Sense> sts = synset.join("sense", JoinType.LEFT);
        List<Predicate> criteriaList = new ArrayList<>();

        Predicate firstCondition = criteriaBuilder.equal(root.get("word"), word);
        criteriaList.add(firstCondition);

        Predicate secondCondition = criteriaBuilder.equal(root.get("packageno"), pkg);
        criteriaList.add(secondCondition);

        Predicate thirdCondition = criteriaBuilder.equal(sts.get("senseIndex"), 0);
        criteriaList.add(thirdCondition);

        criteriaQuery.where(criteriaBuilder.and(criteriaList.toArray(new Predicate[0])));
        final TypedQuery<ExtGraph> query = getEntityManager().createQuery(criteriaQuery);

        return query.getResultList();
    }
 
開發者ID:CLARIN-PL,項目名稱:WordnetLoom,代碼行數:27,代碼來源:ExtGraphRepository.java

示例4: filterByKeywordAndStatus

import javax.persistence.criteria.CriteriaBuilder; //導入依賴的package包/類
public static Specification<Post> filterByKeywordAndStatus(
    final String keyword,//
    final Post.Status status) {
    return (Root<Post> root, CriteriaQuery<?> query, CriteriaBuilder cb) -> {
        List<Predicate> predicates = new ArrayList<>();
        if (StringUtils.hasText(keyword)) {
            predicates.add(
                cb.or(
                    cb.like(root.get(Post_.title), "%" + keyword + "%"),
                    cb.like(root.get(Post_.content), "%" + keyword + "%")
                )
            );
        }

        if (status != null) {
            predicates.add(cb.equal(root.get(Post_.status), status));
        }

        return cb.and(predicates.toArray(new Predicate[predicates.size()]));
    };
}
 
開發者ID:hantsy,項目名稱:spring-microservice-sample,代碼行數:22,代碼來源:PostSpecifications.java

示例5: toPredicate

import javax.persistence.criteria.CriteriaBuilder; //導入依賴的package包/類
@SuppressWarnings({ "rawtypes", "unchecked" })  
public Predicate toPredicate(Root<?> root, CriteriaQuery<?> query,  
        CriteriaBuilder builder) {  
    Path expression = null;  
    if(fieldName.contains(".")){  
        String[] names = StringUtils.split(fieldName, ".");  
        expression = root.get(names[0]);  
        for (int i = 1; i < names.length; i++) {  
            expression = expression.get(names[i]);  
        }  
    }else{  
        expression = root.get(fieldName);  
    }  
    
    switch (operator) {  
    case EQ:  
        return builder.equal(expression, value);  
    case NE:  
        return builder.notEqual(expression, value);  
    case LIKE:  
        return builder.like((Expression<String>) expression, "%" + value + "%");  
    case LT:  
        return builder.lessThan(expression, (Comparable) value);  
    case GT:  
        return builder.greaterThan(expression, (Comparable) value);  
    case LTE:  
        return builder.lessThanOrEqualTo(expression, (Comparable) value);  
    case GTE:  
        return builder.greaterThanOrEqualTo(expression, (Comparable) value);  
    default:  
        return null;  
    }  
}
 
開發者ID:wengwh,項目名稱:plumdo-work,代碼行數:34,代碼來源:SimpleExpression.java

示例6: search

import javax.persistence.criteria.CriteriaBuilder; //導入依賴的package包/類
@Override
public Page search(QueryCriteria criteria, Pageable pageable) {
    CriteriaBuilder builder = this.entityManager.getCriteriaBuilder();

    CriteriaQuery<Long> countCriteria = builder.createQuery(Long.class);
    Root<T> countRoot = countCriteria.from(this.domainClass);
    long total = this.entityManager.createQuery(
            countCriteria.select(builder.count(countRoot))
                    .where(toPredicates(criteria, countRoot, builder))
    ).getSingleResult();

    CriteriaQuery<T> pageCriteria = builder.createQuery(this.domainClass);
    Root<T> pageRoot = pageCriteria.from(this.domainClass);
    List<T> list = this.entityManager.createQuery(
            pageCriteria.select(pageRoot)
                    .where(toPredicates(criteria, pageRoot, builder))
                    .orderBy(toOrders(pageable.getSort(), pageRoot, builder))
    ).setFirstResult(pageable.getOffset())
            .setMaxResults(pageable.getPageSize())
            .getResultList();

    return new PageImpl<>(new ArrayList<>(list), pageable, total);
}
 
開發者ID:chaokunyang,項目名稱:amanda,代碼行數:24,代碼來源:AbstractJpaCriterionRepository.java

示例7: _criteria

import javax.persistence.criteria.CriteriaBuilder; //導入依賴的package包/類
private static void _criteria(DbService dbService) {
    final EntityManager em = dbService.getEntityManager();

    // INSERT new record
    em.getTransaction().begin();
    em.persist(new Account("A"));
    em.persist(new Account("B"));
    em.persist(new Account("C"));
    em.getTransaction().commit();



    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Account> query = builder.createQuery(Account.class);
    Root<Account> acc = query.from(Account.class);

    Predicate cond = builder.gt(acc.get("id"), 1);
    query.where(cond);
    TypedQuery<Account> q = em.createQuery(query);
    List<Account> resultList = q.getResultList();
    System.out.println(resultList);


}
 
開發者ID:vitaly-chibrikov,項目名稱:otus_java_2017_10,代碼行數:25,代碼來源:ConnectionHelper.java

示例8: validarUsuario

import javax.persistence.criteria.CriteriaBuilder; //導入依賴的package包/類
public Pessoa validarUsuario(String log, String pass){
	final CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
	
	final CriteriaQuery<Pessoa> cquery = cb.createQuery(Pessoa.class);
	final Root<Pessoa> root = cquery.from(Pessoa.class);
	final List<Predicate> condicoes = new ArrayList<Predicate>();

	condicoes.add(cb.equal(root.get("usuario").get("login"), log));
	condicoes.add(cb.equal(root.get("usuario").get("senha"), pass));
	
	cquery.select(root).where(condicoes.toArray(new Predicate[]{}));
	Pessoa pessoa = new Pessoa();
	try{
		pessoa = getEntityManager().createQuery(cquery).getSingleResult();
	} catch (Exception e) {
		throw new QueryTimeoutException("Usuário ou senha invalido!");
	}	
   	
   	return pessoa;
}
 
開發者ID:kashm1r,項目名稱:photoiff,代碼行數:21,代碼來源:PerfilService.java

示例9: applyOrder

import javax.persistence.criteria.CriteriaBuilder; //導入依賴的package包/類
/**
 * Apply ordering criteria.
 */
private <T> void applyOrder(final UiPageRequest uiPageRequest, final Map<String, String> mapping, final CriteriaBuilder builder,
		final CriteriaQuery<T> query, final Root<T> root) {
	// Apply the sort
	if (uiPageRequest.getUiSort() != null) {

		// Need to order the result
		final UiSort uiSort = uiPageRequest.getUiSort();
		final String ormColumn = mapping.get(uiSort.getColumn());
		if (ormColumn != null) {

			// ORM column is validated
			final Sort sort = new Sort(uiSort.getDirection(), mapping.get(uiSort.getColumn()));
			query.orderBy(QueryUtils.toOrders(sort, root, builder));
		}
	}
}
 
開發者ID:ligoj,項目名稱:bootstrap,代碼行數:20,代碼來源:PaginationDao.java

示例10: zoekLo3VoorkomenVoorActie

import javax.persistence.criteria.CriteriaBuilder; //導入依賴的package包/類
@Override
public final Lo3Voorkomen zoekLo3VoorkomenVoorActie(final Long actieId) {
    final CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
    final CriteriaQuery<Lo3Voorkomen> criteria = criteriaBuilder.createQuery(Lo3Voorkomen.class);
    final Root<Lo3Voorkomen> criteriaRoot = criteria.from(Lo3Voorkomen.class);
    criteria.select(criteriaRoot);
    criteria.where(new Predicate[] {criteriaBuilder.equal(criteriaRoot.get("actie").get("id"), actieId) });

    final List<Lo3Voorkomen> result = em.createQuery(criteria).getResultList();
    return result.isEmpty() ? null : result.get(0);
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:12,代碼來源:VerConvRepositoryImpl.java

示例11: getPermission

import javax.persistence.criteria.CriteriaBuilder; //導入依賴的package包/類
/**
 * retrieves the <code>RolesPermission</code> by the role.
 * 
 * @param role
 *            the role
 * @return userPermissions the list of permissions of the user
 * 
 */
public static Set<String> getPermission(String role) {
	EntityManagerFactory emf = Persistence.createEntityManagerFactory("userData");
	EntityManager em = emf.createEntityManager();
	EntityTransaction tx = em.getTransaction();
	tx.begin();
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<RolePermission> q = cb.createQuery(RolePermission.class);
	Root<RolePermission> c = q.from(RolePermission.class);
	q.select(c).where(cb.equal(c.get("roleName"), role));
	TypedQuery<RolePermission> query = em.createQuery(q);
	List<RolePermission> permissions = query.getResultList();
	Set<String> userPermissions = new HashSet<String>();
	for (RolePermission permission : permissions)
		userPermissions.add(permission.getPermission());
	tx.commit();
	em.close();
	return userPermissions;
}
 
開發者ID:ETspielberg,項目名稱:bibliometrics,代碼行數:27,代碼來源:RolePermissionDAO.java

示例12: findExternalId

import javax.persistence.criteria.CriteriaBuilder; //導入依賴的package包/類
public static Pod findExternalId(EntityManager em, String externalId) {

        CriteriaBuilder cb = em.getCriteriaBuilder();

        CriteriaQuery<Pod> query = cb.createQuery(Pod.class);

        Root<Pod> root = query.from(Pod.class);

        query = query.select(root)
                .where(cb.equal(root.get("externalId"), externalId));

        try {
            return em.createQuery(query).getSingleResult();
        } catch (NoResultException nre) {
            return null;
        }
    }
 
開發者ID:opensecuritycontroller,項目名稱:osc-core,代碼行數:18,代碼來源:PodEntityMgr.java

示例13: countDefault

import javax.persistence.criteria.CriteriaBuilder; //導入依賴的package包/類
private long countDefault(final Specification<T> specification, final DatatableQuery<?, T> input) {
  	final EntityManager entityManager = entityManagerFactory.createEntityManager();
      final CriteriaBuilder qb = entityManager.getCriteriaBuilder();
      final CriteriaQuery<Long> cq = qb.createQuery(Long.class);
      final Root<T> from = cq.from(this.entity);
      
      cq.select(qb.count(from));
      if (specification != null) {
          cq.where(specification.toPredicate(from, cq, qb));
      }
      final long ret = entityManager.createQuery(cq).getSingleResult();
      entityManager.close();
return ret;
  }
 
開發者ID:andresoviedo,項目名稱:datatable-java,代碼行數:15,代碼來源:DatatableDAOImpl.java

示例14: findRecentProductTypeFrom

import javax.persistence.criteria.CriteriaBuilder; //導入依賴的package包/類
@GET
@Produces({"application/xml", "application/json"})
@Path("/recent/producttype/{id}/{orderLineId}")
public List<LiveSalesList> findRecentProductTypeFrom(@PathParam("id") Integer productTypeId, @PathParam("orderLineId") Integer orderLineId) {
    CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
    javax.persistence.criteria.CriteriaQuery cq = cb.createQuery();
    Root<LiveSalesList> liveSalesList = cq.from(LiveSalesList.class);
    cq.select(liveSalesList);
    cq.where(cb.and(
        cb.equal(liveSalesList.get(LiveSalesList_.productTypeId), productTypeId),
        cb.gt(liveSalesList.get(LiveSalesList_.orderLineId), orderLineId)
    ));
    Query q = getEntityManager().createQuery(cq);
    q.setMaxResults(500);
    return q.getResultList();
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:17,代碼來源:LiveSalesListFacadeREST.java

示例15: findRecentRegionProductType

import javax.persistence.criteria.CriteriaBuilder; //導入依賴的package包/類
@GET
@Produces({"application/xml", "application/json"})
@Path("/recent/region/producttype/{regionName}/{productTypeId}")
public List<LiveSalesList> findRecentRegionProductType(@PathParam("regionName") String regionName, @PathParam("productTypeId") Integer productTypeId) {
    CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
    javax.persistence.criteria.CriteriaQuery cq = cb.createQuery();
    Root<LiveSalesList> liveSalesList = cq.from(LiveSalesList.class);
    cq.select(liveSalesList);
    cq.where(cb.and(
            cb.equal(liveSalesList.get(LiveSalesList_.productTypeId), productTypeId), 
            cb.equal(liveSalesList.get(LiveSalesList_.region), regionName)
    ));
    Query q = getEntityManager().createQuery(cq);
    q.setMaxResults(500);
    return q.getResultList();
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:17,代碼來源:LiveSalesListFacadeREST.java


注:本文中的javax.persistence.criteria.CriteriaBuilder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。