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


Java CriteriaQuery.where方法代碼示例

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


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

示例1: _criteria

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

示例2: getPlayersBySport

import javax.persistence.criteria.CriteriaQuery; //導入方法依賴的package包/類
public List<PlayerDetails> getPlayersBySport(String sport) {
    logger.info("getPlayersByLeagueId");
    List<Player> players = null;

    try {
        CriteriaQuery<Player> cq = cb.createQuery(Player.class);
        if (cq != null) {
            Root<Player> player = cq.from(Player.class);
            Join<Player, Team> team = player.join(Player_.team);
            Join<Team, League> league = team.join(Team_.league);

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

            // set the where clause
            cq.where(cb.equal(league.get(League_.sport), sport));
            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,代碼行數:26,代碼來源:RequestBeanQueries.java

示例3: zoekLo3VoorkomenVoorActie

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

示例4: applySpecificationToQueryCriteria

import javax.persistence.criteria.CriteriaQuery; //導入方法依賴的package包/類
/**
 * Spec op query doen.
 * @param spec spec
 * @param query query
 * @param <S> query type
 * @return root
 */
protected final <S> Root<T> applySpecificationToQueryCriteria(final Specification<T> spec, final CriteriaQuery<S> query) {

    Assert.notNull(query, "Query mag niet null zijn.");
    final Root<T> root = query.from(getDomainClass());

    if (spec == null) {
        return root;
    }

    final CriteriaBuilder builder = em.getCriteriaBuilder();
    final Predicate predicate = spec.toPredicate(root, query, builder);

    if (predicate != null) {
        query.where(predicate);
    }

    return root;
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:26,代碼來源:CustomSimpleJpaRepository.java

示例5: AuthorizationService

import javax.persistence.criteria.CriteriaQuery; //導入方法依賴的package包/類
public AuthorizationService(@Context HttpHeaders headers) {
    authorization = false;

    String token = headers.getHeaderString("Authorization");
    if (token != null) {
        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);
            criteria.where(builder.equal(root.get(User_.token), token));

            authenticate = session.createQuery(criteria).getSingleResult();

            if (authenticate != null)
                authorization = true;
        } catch (Exception e) {
        }
    }
}
 
開發者ID:YMonnier,項目名稱:docker-restful-java,代碼行數:24,代碼來源:AuthorizationService.java

示例6: search

import javax.persistence.criteria.CriteriaQuery; //導入方法依賴的package包/類
public List<ClanEntity> search(String name, int minMembers, int maxMembers, int minTrophies, boolean onlyJoinable) {
	try (Session session = session()) {
		CriteriaBuilder builder = session.getCriteriaBuilder();
		CriteriaQuery<ClanEntity> query = builder.createQuery(ClanEntity.class);
		Root<ClanEntity> root = query.from(ClanEntity.class);
		query.select(root);

		if (name != null && !name.isEmpty()) {
			query.where(builder.like(root.get("name"), "%" + name + "%"));
		}

		// TODO: Check min and max members

		if (minTrophies != 0) {
			query.where(builder.greaterThan(root.get("score"), minTrophies));
		}

		if (onlyJoinable) {
			query.where(builder.equal(root.get("type"), builder.literal(ClanType.OPEN)));
			// TODO: Check members
		}

		return session.createQuery(query).getResultList();
	}
}
 
開發者ID:Tarik02,項目名稱:cr-private-server,代碼行數:26,代碼來源:ClanService.java

示例7: getPlayersByLeagueId

import javax.persistence.criteria.CriteriaQuery; //導入方法依賴的package包/類
public List<PlayerDetails> getPlayersByLeagueId(String leagueId) {
    logger.info("getPlayersByLeagueId");
    List<Player> players = null;

    try {
        CriteriaQuery<Player> cq = cb.createQuery(Player.class);
        if (cq != null) {
            Root<Player> player = cq.from(Player.class);
            Join<Player, Team> team = player.join(Player_.teams);
            Join<Team, League> league = team.join(Team_.league);

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

            // set the where clause
            cq.where(cb.equal(league.get(League_.id), leagueId));
            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,代碼行數:26,代碼來源:RequestBean.java

示例8: getStatusEntriesByDate

import javax.persistence.criteria.CriteriaQuery; //導入方法依賴的package包/類
public List<StatusEntry> getStatusEntriesByDate(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    CriteriaQuery<StatusEntry> cq = cb.createQuery(StatusEntry.class);
    Root<StatusEntry> statusEntry = cq.from(StatusEntry.class);

    cq.select(statusEntry);
    cq.where(cb.equal(statusEntry.get(StatusEntry_.statusDate), cal));
    cq.distinct(true);

    TypedQuery<StatusEntry> q = em.createQuery(cq);
    return q.getResultList();
}
 
開發者ID:wwu-pi,項目名稱:tap17-muggl-javaee,代碼行數:14,代碼來源:RequestBean.java

示例9: createQueryWrapper

import javax.persistence.criteria.CriteriaQuery; //導入方法依賴的package包/類
public static <T> QueryWrapper createQueryWrapper(List<AbstractExpression> expressions) {
	return  (Root<?> root, CriteriaQuery<?> query, CriteriaBuilder cb, boolean sort)-> {
		List<Predicate> predicates = new ArrayList<>();
		expressions.forEach(expression->
			predicates.add(expression.buildJpaPredicate(cb,root))
		);
		Predicate[] array = new Predicate[predicates.size()];
		predicates.toArray(array);
		query.where(array);
	};
}
 
開發者ID:szsucok,項目名稱:sucok-framework,代碼行數:12,代碼來源:QueryFormHelper.java

示例10: getPlayersByHigherSalary

import javax.persistence.criteria.CriteriaQuery; //導入方法依賴的package包/類
public List<PlayerDetails> getPlayersByHigherSalary(String name) {
    logger.info("getPlayersByHigherSalary");
    List<Player> players = null;

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

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

            // create a Predicate object that finds players with a salary
            // greater than player1
            Predicate gtPredicate = cb.greaterThan(
                    player1.get(Player_.salary),
                    player2.get(Player_.salary));
            // create a Predicate object that finds the player based on
            // the name parameter
            Predicate equalPredicate = cb.equal(
                    player2.get(Player_.name),
                    name);
            // set the where clause with the predicates
            cq.where(gtPredicate, equalPredicate);
            // set the select clause, and return only unique entries
            cq.select(player1).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,代碼行數:36,代碼來源:RequestBean.java

示例11: txPortEntityByElementId

import javax.persistence.criteria.CriteriaQuery; //導入方法依賴的package包/類
public PortEntity txPortEntityByElementId(String elementId) {
    CriteriaBuilder cb = this.em.getCriteriaBuilder();

    CriteriaQuery<PortEntity> q = cb.createQuery(PortEntity.class);
    Root<PortEntity> r = q.from(PortEntity.class);
    q.where(cb.equal(r.get("elementId"), elementId));

    try {
        return this.em.createQuery(q).getSingleResult();
    } catch (Exception e) {
        LOG.error("Finding Network Element {} ", elementId, e);
        return null;
    }
}
 
開發者ID:opensecuritycontroller,項目名稱:sdn-controller-nsc-plugin,代碼行數:15,代碼來源:RedirectionApiUtils.java

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

示例13: applySpecificationToCriteria

import javax.persistence.criteria.CriteriaQuery; //導入方法依賴的package包/類
/**
 * Applies the given {@link Specification} to the given {@link CriteriaQuery}.
 */
private <S, T> Root<T> applySpecificationToCriteria(final Root<T> root, final Specification<T> spec, final CriteriaQuery<S> query) {

	Assert.notNull(query, "Query is requested");

	if (spec != null) {
		// There is at least one described filter
		final CriteriaBuilder builder = em.getCriteriaBuilder();
		final Predicate predicate = spec.toPredicate(root, query, builder);

		// There is at least one validated filter
		query.where(predicate);
	}
	return root;
}
 
開發者ID:ligoj,項目名稱:bootstrap,代碼行數:18,代碼來源:PaginationDao.java

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

示例15: 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_04,代碼行數:9,代碼來源:UserDataSetDAO.java


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