本文整理匯總了Java中javax.persistence.criteria.Predicate類的典型用法代碼示例。如果您正苦於以下問題:Java Predicate類的具體用法?Java Predicate怎麽用?Java Predicate使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Predicate類屬於javax.persistence.criteria包,在下文中一共展示了Predicate類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: toPredicate
import javax.persistence.criteria.Predicate; //導入依賴的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;
}
示例2: byKeyword
import javax.persistence.criteria.Predicate; //導入依賴的package包/類
public static Specification<User> byKeyword(String keyword, String role, String active){
return (Root<User> root, CriteriaQuery<?> query, CriteriaBuilder cb) -> {
List<Predicate> predicates = new ArrayList<>();
if (StringUtils.hasText(keyword)) {
predicates.add(
cb.or(
cb.like(root.get(User_.email), "%" + keyword + "%"),
cb.like(root.get(User_.username), "%" + keyword + "%")
));
}
if (StringUtils.hasText(role) && !"ALL".equals(role)) {
ListJoin<User, String> roleJoin = root.join(User_.roles);
predicates.add(cb.equal(roleJoin, role));
}
if (StringUtils.hasText(active)) {
predicates.add(cb.equal(root.get(User_.active), Boolean.valueOf(active)));
}
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
};
}
示例3: filterByKeywordAndStatus
import javax.persistence.criteria.Predicate; //導入依賴的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()]));
};
}
示例4: findByWordAndPackageNo
import javax.persistence.criteria.Predicate; //導入依賴的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();
}
示例5: toPredicate
import javax.persistence.criteria.Predicate; //導入依賴的package包/類
@Override
public Predicate toPredicate(final Root<?> leveringsautorisatieRoot, final CriteriaQuery<?> query, final CriteriaBuilder cb) {
final Root<Dienstbundel> dienstbundelRoot = query.from(Dienstbundel.class);
final Root<Dienst> dienstRoot = query.from(Dienst.class);
// Join dienst op dienstbundel
final Predicate joinPredicateDienstbundel = dienstbundelRoot.get(ID).in(dienstRoot.get("dienstbundel").get(ID));
// Join dienst op leveringsautorisatie
final Predicate joinPredicateLeveringsautorisatie = leveringsautorisatieRoot.get(ID).in(dienstbundelRoot.get(LEVERINGSAUTORISATIE).get(ID));
// OntvangendePartij
final Predicate soortDienstPredicate = cb.equal(dienstRoot.get("soortDienstId"), value);
return cb.and(joinPredicateDienstbundel, joinPredicateLeveringsautorisatie, soortDienstPredicate);
}
示例6: validarUsuario
import javax.persistence.criteria.Predicate; //導入依賴的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;
}
示例7: _criteria
import javax.persistence.criteria.Predicate; //導入依賴的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);
}
示例8: toPredicate
import javax.persistence.criteria.Predicate; //導入依賴的package包/類
@Override
public Predicate toPredicate(Root<TestRun> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
Predicate result = null;
if (!CollectionUtils.isEmpty(filter.getBuilds())) {
result = criteriaBuilder.in(root.get(BUILD_PROPERTY)).value(filter.getBuilds());
}
if (!CollectionUtils.isEmpty(filter.getTestSuites())) {
result = and(criteriaBuilder, result,
criteriaBuilder.in(root.get("testSuite").get("id")).value(filter.getTestSuites()));
}
if (!CollectionUtils.isEmpty(filter.getGit())) {
result = and(criteriaBuilder, result,
criteriaBuilder.or(
criteriaBuilder.in(root.get("gitHash")).value(filter.getGit()),
criteriaBuilder.in(root.get("gitBranch")).value(filter.getGit())
));
}
result = and(criteriaBuilder, result, criteriaBuilder.isNotNull(root.get("testSuite")));
return result;
}
示例9: buildJpaPredicate
import javax.persistence.criteria.Predicate; //導入依賴的package包/類
@Override
public Predicate buildJpaPredicate(CriteriaBuilder builder, Root<?> root) {
Expression<Object> path = QueryFormHelper.getPath(root, field);
CriteriaBuilder.In<Object> predicate = builder.in(path);
int length = Array.getLength(value);
for (int i = 0; i < length; i++) {
predicate.value(Array.get(value, i));
}
return builder.not(predicate);
}
示例10: zoekLo3VoorkomenVoorActie
import javax.persistence.criteria.Predicate; //導入依賴的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);
}
示例11: filter
import javax.persistence.criteria.Predicate; //導入依賴的package包/類
public static Specification<Sense> filter(SenseCriteriaDTO dto) {
return (root, query, cb) -> {
List<Predicate> criteria = new ArrayList<>();
if (dto.getLemma() != null && !dto.getLemma().isEmpty()) {
criteria.add(byLemma(dto.getLemma()).toPredicate(root, query, cb));
}
if (dto.getVariant() != null) {
criteria.add(byVarinat(dto.getVariant()).toPredicate(root, query, cb));
}
if (dto.getPartOfSpeechId() != null) {
criteria.add(byPartOfSpeech(dto.getPartOfSpeechId()).toPredicate(root, query, cb));
}
if (dto.getDomainId() != null) {
criteria.add(byDomain(dto.getDomainId()).toPredicate(root, query, cb));
}
if (dto.getSynsetId() != null) {
criteria.add(bySynsetId(dto.getSynsetId()).toPredicate(root, query, cb));
}
if (dto.getLexicons() != null && dto.getLexicons().size() > 0) {
criteria.add(byLexiconIds(dto.getLexicons()).toPredicate(root, query, cb));
}
return cb.and(criteria.toArray(new Predicate[criteria.size()]));
};
}
示例12: findSentMessagesForUser
import javax.persistence.criteria.Predicate; //導入依賴的package包/類
/**
* Get a specification using the specified parameters.
*
* @param user The sender's user
* @param subject The subject of the message
* @param text The text of the message
* @return The specification
*/
public static Specification<MessageEntity> findSentMessagesForUser(
final UserEntity user,
@Nullable final String subject,
@Nullable final String text
) {
return (final Root<MessageEntity> root, final CriteriaQuery<?> cq, final CriteriaBuilder cb) -> {
final List<Predicate> predicates = new ArrayList<>();
predicates.add(cb.equal(root.get(MessageEntity_.sender), user));
if (Optional.ofNullable(subject).isPresent()) {
predicates.add(cb.like(root.get(MessageEntity_.subject), "%" + subject + "%"));
}
if (Optional.ofNullable(text).isPresent()) {
predicates.add(cb.like(root.get(MessageEntity_.text), "%" + text + "%"));
}
predicates.add(cb.isTrue(root.get(MessageEntity_.isVisibleForSender)));
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
};
}
示例13: findReceivedMessagesForUser
import javax.persistence.criteria.Predicate; //導入依賴的package包/類
/**
* Get a specification using the specified parameters.
*
* @param user The recipient's user
* @param subject The subject of the message
* @param text The text of the message
* @return The specification
*/
public static Specification<MessageEntity> findReceivedMessagesForUser(
final UserEntity user,
@Nullable final String subject,
@Nullable final String text
) {
return (final Root<MessageEntity> root, final CriteriaQuery<?> cq, final CriteriaBuilder cb) -> {
final List<Predicate> predicates = new ArrayList<>();
predicates.add(cb.equal(root.get(MessageEntity_.recipient), user));
if (Optional.ofNullable(subject).isPresent()) {
predicates.add(cb.like(root.get(MessageEntity_.subject), "%" + subject + "%"));
}
if (Optional.ofNullable(text).isPresent()) {
predicates.add(cb.like(root.get(MessageEntity_.text), "%" + text + "%"));
}
predicates.add(cb.isTrue(root.get(MessageEntity_.isVisibleForRecipient)));
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
};
}
示例14: addToWhereConstraint
import javax.persistence.criteria.Predicate; //導入依賴的package包/類
private void addToWhereConstraint(ListingPredicate listingPredicate) {
if (listingPredicate != null) {
Predicate predicate = null;
List<ListingPredicate> filters = new ArrayList<>();
Map<String, Field> fieldMap = ListingUtil.getFields(domainClass).stream().collect(Collectors.toMap(field -> field.getName(), field -> field));
if (listingPredicate.hasPredicates()) {
filters.addAll(listingPredicate.getPredicates());
} else {
filters.add(new ListingPredicate().filter(listingPredicate.getAttribute(), listingPredicate.getFilter()));
}
predicate = filterByPredicateTree(listingPredicate.isDisjunctive(), listingPredicate.isNegation(), filters, fieldMap);
if (predicate != null) {
if (listingPredicate.isNegation()) {
predicate = criteriaBuilder.not(predicate);
}
whereConstraints.add(predicate);
}
}
}
示例15: buildJpaPredicate
import javax.persistence.criteria.Predicate; //導入依賴的package包/類
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public Predicate buildJpaPredicate(CriteriaBuilder cb, Root root) {
String field1 = (String) Array.get(value, 0);
String field2 = (String) Array.get(value, 1);
Expression<Comparable> path1 = QueryFormHelper.getPath(root, field1);
Expression<Comparable> path2 = QueryFormHelper.getPath(root, field2);
Expression<Comparable> parameter = cb.literal((Comparable) value);
return cb.between(parameter, path1, path2);
}