當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。