当前位置: 首页>>代码示例>>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;未经允许,请勿转载。