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


Java Predicate类代码示例

本文整理汇总了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;
}
 
开发者ID:ATLANTBH,项目名称:owl,代码行数:12,代码来源:TestSuiteFilterSpecification.java

示例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()]));
    };
}
 
开发者ID:hantsy,项目名称:spring-microservice-sample,代码行数:25,代码来源:UserSpecifications.java

示例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()]));
    };
}
 
开发者ID:hantsy,项目名称:spring-microservice-sample,代码行数:22,代码来源:PostSpecifications.java

示例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();
    }
 
开发者ID:CLARIN-PL,项目名称:WordnetLoom,代码行数:27,代码来源:ExtGraphRepository.java

示例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);
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:17,代码来源:LeveringsautorisatieFilterFactory.java

示例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;
}
 
开发者ID:kashm1r,项目名称:photoiff,代码行数:21,代码来源:PerfilService.java

示例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);


}
 
开发者ID:vitaly-chibrikov,项目名称:otus_java_2017_10,代码行数:25,代码来源:ConnectionHelper.java

示例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;
}
 
开发者ID:ATLANTBH,项目名称:owl,代码行数:26,代码来源:TestRunFilterSpecification.java

示例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);
}
 
开发者ID:szsucok,项目名称:sucok-framework,代码行数:11,代码来源:NotIn.java

示例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);
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:12,代码来源:VerConvRepositoryImpl.java

示例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()]));
        };
    }
 
开发者ID:CLARIN-PL,项目名称:WordnetLoom,代码行数:34,代码来源:SenseSpecification.java

示例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()]));
    };
}
 
开发者ID:JonkiPro,项目名称:REST-Web-Services,代码行数:31,代码来源:MessageSpecs.java

示例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()]));
    };
}
 
开发者ID:JonkiPro,项目名称:REST-Web-Services,代码行数:31,代码来源:MessageSpecs.java

示例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);
        }
    }
}
 
开发者ID:coodoo-io,项目名称:coodoo-listing,代码行数:23,代码来源:ListingQuery.java

示例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);
}
 
开发者ID:szsucok,项目名称:sucok-framework,代码行数:11,代码来源:BetweenField.java


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