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


Java CriteriaQuery.from方法代码示例

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


在下文中一共展示了CriteriaQuery.from方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAllRasterPoints

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
@Override
public List<RasterPoint> getAllRasterPoints() {
    // set up potentially long running transaction!
    try {
        // TODO refactor out
        ut.setTransactionTimeout(2000);
        ut.begin();

        CriteriaBuilder cb = entityManager.getCriteriaBuilder();
        CriteriaQuery<RasterPoint> c = cb.createQuery(RasterPoint.class);
        Root<RasterPoint> root = c.from(RasterPoint.class);
        CriteriaQuery<RasterPoint> all = c.select(root);
        TypedQuery<RasterPoint> allQuery = entityManager.createQuery(all);
        List<RasterPoint> resultList = allQuery.getResultList();

        ut.commit();
        return resultList;

    } catch (Exception e) {
        //throw new DatabaseException("Could not load raster from database! Reason: " + e.getMessage());
        log.error("Could not load raster from database! Reason: {}", e.getMessage());
        return Collections.emptyList();
    }
}
 
开发者ID:RWTH-i5-IDSG,项目名称:xsharing-services-router,代码行数:25,代码来源:RasterRepositoryImpl.java

示例2: findPoliciesById

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
/**
 * Verifies if the request contains valid policies supported by security manager available on the OSC.
 * If the request contains one or more invalid policies, throw an exception.
 */
// TODO Larkins: Improve the method not to do the validation
public static Set<Policy> findPoliciesById(EntityManager em, Set<Long> ids, ApplianceManagerConnector mc)
		throws VmidcBrokerValidationException, Exception {
	Set<Policy> policies = new HashSet<>();
	Set<String> invalidPolicies = new HashSet<>();
	for (Long id : ids) {
		CriteriaBuilder cb = em.getCriteriaBuilder();
		CriteriaQuery<Policy> query = cb.createQuery(Policy.class);
		Root<Policy> root = query.from(Policy.class);
		query = query.select(root).where(cb.equal(root.get("id"), id),
				cb.equal(root.join("applianceManagerConnector").get("id"), mc.getId()));
		try {
			Policy policy = em.createQuery(query).getSingleResult();
			policies.add(policy);
		} catch (NoResultException nre) {
			invalidPolicies.add(id.toString());
		}
	}
	if (invalidPolicies.size() > 0) {
		throw new VmidcBrokerValidationException(
				"Invalid Request. Request contains invalid policies: " + String.join(", ", invalidPolicies));
	}
	return policies;
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:29,代码来源:PolicyEntityMgr.java

示例3: getPlayersNotOnTeam

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
public List<PlayerDetails> getPlayersNotOnTeam() {
    logger.info("getPlayersNotOnTeam");
    List<Player> players = null;

    try {
        CriteriaQuery<Player> cq = cb.createQuery(Player.class);
        if (cq != null) {
            Root<Player> player = cq.from(Player.class);

            // Get MetaModel from Root
            //EntityType<Player> Player_ = player.getModel();

            // set the where clause
            cq.where(cb.isNull(player.get(Player_.team)));
            cq.select(player).distinct(true);
            TypedQuery<Player> q = em.createQuery(cq);
            players = q.getResultList();
        }
        return copyPlayersToDetails(players);
    } catch (Exception ex) {
        throw new EJBException(ex);
    }
}
 
开发者ID:wwu-pi,项目名称:tap17-muggl-javaee,代码行数:24,代码来源:RequestBeanQueries.java

示例4: search

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
@Override
public Optional<SearchResponse> search(final ServiceUser user,
                                       final SearchRequest request){
    final String dataSourceUuid = request.getQuery().getDataSource().getUuid();

    try (final Session session = database.openSession()) {
        final CriteriaBuilder cb = session.getCriteriaBuilder();

        final CriteriaQuery<Tuple> cq = cb.createTupleQuery();
        final Root<T> root = cq.from(this.dtoClass);

        cq.multiselect(this.fields.stream()
                .map(f -> root.get(f.getName()))
                .collect(Collectors.toList()));

        final Predicate requestPredicate = getPredicate(cb, root, request.getQuery().getExpression());
        final Predicate dataSourcePredicate = cb.equal(root.get(QueryableEntity.DATA_SOURCE_UUID), dataSourceUuid);

        cq.where(cb.and(requestPredicate, dataSourcePredicate));
        final List<Tuple> tuples = session.createQuery(cq).getResultList();
        final SearchResponse searchResponse = projectResults(request, tuples);

        return Optional.of(searchResponse);
    }
}
 
开发者ID:gchq,项目名称:stroom-query,代码行数:26,代码来源:QueryServiceCriteriaImpl.java

示例5: getGuardianByEmail

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
@GET
@Path("/guardian/{guardianEmail}")
@Produces({"application/xml", "application/json"})
@RolesAllowed({"Guardian", "Administrator"})
public Guardian getGuardianByEmail(@PathParam("guardianEmail") String email) {
    logger.log(Level.INFO, "Principal is: {0}", ctx.getCallerPrincipal().getName());

    CriteriaQuery<Guardian> cq = cb.createQuery(Guardian.class);
    Root<Guardian> guardian = cq.from(Guardian.class);

    cq.select(guardian);
    cq.where(cb.equal(guardian.get(Guardian_.email), email));
    cq.distinct(true);

    TypedQuery<Guardian> q = em.createQuery(cq);
    return q.getSingleResult();
}
 
开发者ID:wwu-pi,项目名称:tap17-muggl-javaee,代码行数:18,代码来源:RequestBean.java

示例6: readByName

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
public UserDataSet readByName(String name) {
    CriteriaBuilder builder = session.getCriteriaBuilder();
    CriteriaQuery<UserDataSet> criteria = builder.createQuery(UserDataSet.class);
    Root<UserDataSet> from = criteria.from(UserDataSet.class);
    criteria.where(builder.equal(from.get("name"), name));
    Query<UserDataSet> query = session.createQuery(criteria);
    return query.uniqueResult();
}
 
开发者ID:vitaly-chibrikov,项目名称:otus_java_2017_06,代码行数:9,代码来源:UserDataSetDAO.java

示例7: stream

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
public Stream<T> stream() {
    CriteriaBuilder cb = this.entityManager().getCriteriaBuilder();
    CriteriaQuery<T> q = cb.createQuery(entityClass());
    Root<T> c = q.from(entityClass());

    return entityManager().createQuery(q).getResultStream();
}
 
开发者ID:hantsy,项目名称:javaee8-jsf-sample,代码行数:8,代码来源:AbstractRepository.java

示例8: findAllByFieldIn

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
@Override
public List<T> findAllByFieldIn(String Field, Iterable<?> values) {
	CriteriaBuilder cb = entityManager.getCriteriaBuilder();
	CriteriaQuery<T> query = cb.createQuery(getDomainClass());
	Root<T> e = query.from(getDomainClass());
	query.where(cb.in(e.get(Field)).value(values));
	return entityManager.createQuery(query).getResultList();
}
 
开发者ID:geeker-lait,项目名称:tasfe-framework,代码行数:9,代码来源:BaseRepositoryImpl.java

示例9: getUncompletedJobs

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的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

示例10: getQuery

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
private CriteriaQuery<User> getQuery(User po) {
	CriteriaBuilder cb = entityManager.getCriteriaBuilder();
	CriteriaQuery<User> query = cb.createQuery(User.class);
	Root<User> root = query.from(User.class);
	query.select(root);
	query.where(cb.and(getPredicates(cb, root, po)));
	return query;
}
 
开发者ID:lf23617358,项目名称:training-sample,代码行数:9,代码来源:JPAUserRepository.java

示例11: getTodaysSession

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
public TutoringSession getTodaysSession() {

        // get today's date and trim the time information
        Calendar today = Calendar.getInstance();
        CalendarUtil.stripTime(today);
        // find today's session

        SimpleDateFormat formatter = new SimpleDateFormat("E, MMM d, yyyy");
        logger.log(Level.INFO, "Finding tutoring session for {0}", formatter.format(today.getTime()));

        CriteriaQuery<TutoringSession> cq = cb.createQuery(TutoringSession.class);
        Root<TutoringSession> tutoringSession = cq.from(TutoringSession.class);

        cq.select(tutoringSession);
        cq.where(cb.equal(tutoringSession.get(TutoringSession_.sessionDate), today));
        cq.distinct(true);

        TypedQuery<TutoringSession> q = em.createQuery(cq);
        TutoringSession session;
        try {
            session = q.getSingleResult();
            logger.info("Found session for today.");
        } catch (NoResultException e) {
            logger.info("Today's session not found. Creating a new session.");
            session = new TutoringSession();
            em.persist(session);
        }

        return session;
    }
 
开发者ID:wwu-pi,项目名称:tap17-muggl-javaee,代码行数:31,代码来源:RequestBean.java

示例12: findAll

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的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

示例13: validarUsuario

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的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("login"), log));
	condicoes.add(cb.equal(root.get("senha"), pass));
	
	cquery.select(root).where(condicoes.toArray(new Predicate[]{}));
	Pessoa pessoa = null;

	try{
		pessoa = getEntityManager().createQuery(cquery).getSingleResult();
		
		for(Menu m : pessoa.getPerfil().getMenus()) {
			m.getItens().size();
		}
	} catch (Exception e) {
		e.printStackTrace();
	}	
   	
	
	
   	return pessoa;
}
 
开发者ID:kashm1r,项目名称:photoiff,代码行数:28,代码来源:PessoaService.java

示例14: executeCountQuery

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
private long executeCountQuery(QueryWrapper queryWrapper) {
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Long> query = cb.createQuery(Long.class);
	Root<T> root = query.from(entityClass);
	query.select(cb.count(root));
	queryWrapper.wrap(root, query, cb, false);
	TypedQuery<Long> typedQuery = em.createQuery(query);
	long total = 0;
	for (long value : typedQuery.getResultList()) {
		total += value;
	}
	return total;
}
 
开发者ID:szsucok,项目名称:sucok-framework,代码行数:14,代码来源:BaseDao.java

示例15: findSystem

import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
@Override
@Transactional
public SystemEntity findSystem(String system) {

    CriteriaBuilder builder = em.getCriteriaBuilder();

    SystemEntity systemEntity = null;
    CriteriaQuery<SystemEntity> criteria = builder.createQuery(SystemEntity.class);

    Root<SystemEntity> root = criteria.from(SystemEntity.class);
    List<Predicate> predList = new LinkedList<Predicate>();
    log.debug("Looking for System = " + system);

    Predicate p = builder.equal(root.<String>get("codeSystemUri"),system);
    predList.add(p);
    Predicate[] predArray = new Predicate[predList.size()];
    predList.toArray(predArray);
    if (predList.size()>0)
    {
        log.debug("Found System "+system);
        criteria.select(root).where(predArray);

        List<SystemEntity> qryResults = em.createQuery(criteria).getResultList();

        for (SystemEntity cme : qryResults) {
            systemEntity = cme;
            break;
        }
    }
    if (systemEntity == null) {
        log.info("Not found. Adding SystemEntity = "+system);
        systemEntity = new SystemEntity();
        systemEntity.setUri(system);

        em.persist(systemEntity);
    }
    return systemEntity;
}
 
开发者ID:nhsconnect,项目名称:careconnect-reference-implementation,代码行数:39,代码来源:RICodeSystemRepository.java


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