当前位置: 首页>>代码示例>>Java>>正文


Java CriteriaBuilder.createQuery方法代码示例

本文整理汇总了Java中javax.persistence.criteria.CriteriaBuilder.createQuery方法的典型用法代码示例。如果您正苦于以下问题:Java CriteriaBuilder.createQuery方法的具体用法?Java CriteriaBuilder.createQuery怎么用?Java CriteriaBuilder.createQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.persistence.criteria.CriteriaBuilder的用法示例。


在下文中一共展示了CriteriaBuilder.createQuery方法的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: 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

示例3: _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

示例4: isControllerTypeUsed

import javax.persistence.criteria.CriteriaBuilder; //导入方法依赖的package包/类
public static boolean isControllerTypeUsed(String controllerType, EntityManager em) {

        Long count = 0L;
        try {
            CriteriaBuilder cb = em.getCriteriaBuilder();

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

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

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

            count = em.createQuery(query).getSingleResult();
        } catch (Exception e) {
            // Ignore this exception
        }

        return count > 0;
    }
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:21,代码来源:VirtualizationConnectorEntityMgr.java

示例5: 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

示例6: findByOpenstackId

import javax.persistence.criteria.CriteriaBuilder; //导入方法依赖的package包/类
public static Subnet findByOpenstackId(EntityManager em, String id) {

        CriteriaBuilder cb = em.getCriteriaBuilder();

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

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

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

        try {
            return em.createQuery(query).getSingleResult();
        } catch (NoResultException nre) {
            return null;
        }
    }
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:18,代码来源:SubnetEntityManager.java

示例7: findByOpenstackId

import javax.persistence.criteria.CriteriaBuilder; //导入方法依赖的package包/类
public static VMPort findByOpenstackId(EntityManager em, String id) {

        CriteriaBuilder cb = em.getCriteriaBuilder();

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

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

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

        try {
            return em.createQuery(query).getSingleResult();
        } catch (NoResultException nre) {
            return null;
        }
    }
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:18,代码来源:VMPortEntityManager.java

示例8: findAll

import javax.persistence.criteria.CriteriaBuilder; //导入方法依赖的package包/类
public List<T> findAll() {
    final CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    final CriteriaQuery<T> criteria = builder.createQuery(entityClass);
    final Root<T> root = criteria.from(entityClass);
    criteria.select(root);

    final TypedQuery<T> query = entityManager.createQuery(criteria);

    return query.getResultList();
}
 
开发者ID:cerner,项目名称:jwala,代码行数:11,代码来源:AbstractCrudServiceImpl.java

示例9: findAll

import javax.persistence.criteria.CriteriaBuilder; //导入方法依赖的package包/类
/**
 * 分页查询
 * @param domainClass 领域类(实体类)
 * @param pageable 分页信息
 * @param <T> 领域类(实体类)范型
 * @return 分页结果信息
 */
public static <T> Page<T> findAll(Class<T> domainClass, Pageable pageable) {
	EntityManager em = getEntityManager(domainClass);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<T> cq = cb.createQuery(domainClass);
	cq.from(domainClass);
	return findAll(cq, pageable);
}
 
开发者ID:muxiangqiu,项目名称:linq,代码行数:15,代码来源:JpaUtil.java

示例10: listByProjectId

import javax.persistence.criteria.CriteriaBuilder; //导入方法依赖的package包/类
public static List<SecurityGroup> listByProjectId(EntityManager em, String projectId) {
    CriteriaBuilder cb = em.getCriteriaBuilder();

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

    Root<SecurityGroup> root = query.from(SecurityGroup.class);
    query = query.select(root)
            .distinct(true)
            .where(cb.equal(root.get("projectId"), projectId));

    return em.createQuery(query).getResultList();
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:13,代码来源:SecurityGroupEntityMgr.java

示例11: findRecentRegion

import javax.persistence.criteria.CriteriaBuilder; //导入方法依赖的package包/类
@GET
@Produces({"application/xml", "application/json"})
@Path("/recent/region/{regionName}")
public List<LiveSalesList> findRecentRegion(@PathParam("regionName") String regionName) {
    CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
    javax.persistence.criteria.CriteriaQuery cq = cb.createQuery();
    Root<LiveSalesList> liveSalesList = cq.from(LiveSalesList.class);
    cq.select(liveSalesList);
    cq.where(cb.equal(liveSalesList.get(LiveSalesList_.region), regionName));
    Query q = getEntityManager().createQuery(cq);
    q.setMaxResults(500);
    return q.getResultList();
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:14,代码来源:LiveSalesListFacadeREST.java

示例12: findUserById

import javax.persistence.criteria.CriteriaBuilder; //导入方法依赖的package包/类
public User findUserById(Long id) {
    try (Session session = HibernateUtil.getSessionFactory().openSession()) {
        CriteriaBuilder builder = session.getCriteriaBuilder();
        CriteriaQuery<User> criteria = builder.createQuery(User.class);
        Root<User> root = criteria.from(User.class);
        criteria.select(root).where(builder.equal(root.get("id"), id));
        Query<User> q = session.createQuery(criteria);
        return q.getSingleResult();
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return null;
}
 
开发者ID:Petrakus,项目名称:java-jwt-auth,代码行数:14,代码来源:UserDao.java

示例13: filtrarPorNome

import javax.persistence.criteria.CriteriaBuilder; //导入方法依赖的package包/类
public List<Pessoa> filtrarPorNome(String filtro){
	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>();

	Expression<String> path = root.get("nome");
	condicoes.add(cb.like(path, "%"+filtro+"%"));
	
	cquery.select(root).where(condicoes.toArray(new Predicate[]{}));
	List<Pessoa> pessoas = getEntityManager().createQuery(cquery).getResultList();
		    	
   	return pessoas;
}
 
开发者ID:kashm1r,项目名称:photoiff,代码行数:16,代码来源:PerfilService.java

示例14: getUncompletedJobs

import javax.persistence.criteria.CriteriaBuilder; //导入方法依赖的package包/类
public List<JobRecord> getUncompletedJobs(EntityManager em) {
    CriteriaBuilder cb = em.getCriteriaBuilder();

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

    Root<JobRecord> from = query.from(JobRecord.class);
    query = query.select(from)
            .where(cb.notEqual(from.get("state"), COMPLETED));
    return em.createQuery(query).getResultList();
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:11,代码来源:JobEntityManager.java

示例15: hasSGMRemoved

import javax.persistence.criteria.CriteriaBuilder; //导入方法依赖的package包/类
/**
 * @param em
 *            Hibernate EntityManager
 * @param sg
 *            Security Group
 * @return
 *         true if any SGM was deleted
 *         false if no SGM was deleted
 */
public static boolean hasSGMRemoved(EntityManager em, SecurityGroup sg) {
    CriteriaBuilder cb = em.getCriteriaBuilder();

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

    Root<SecurityGroup> root = query.from(SecurityGroup.class);
    Join<SecurityGroup, Object> join = root.join("securityGroupMembers");
    query = query.select(root)
            .distinct(true)
            .where(cb.equal(join.get("markedForDeletion"), true));

    return !em.createQuery(query).setMaxResults(1).getResultList().isEmpty();
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:23,代码来源:SecurityGroupEntityMgr.java


注:本文中的javax.persistence.criteria.CriteriaBuilder.createQuery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。