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


Java Path类代码示例

本文整理汇总了Java中javax.persistence.criteria.Path的典型用法代码示例。如果您正苦于以下问题:Java Path类的具体用法?Java Path怎么用?Java Path使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: toPredicate

import javax.persistence.criteria.Path; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })  
public Predicate toPredicate(Root<?> root, CriteriaQuery<?> query,  
        CriteriaBuilder builder) {  
    Path expression = null;  
    if(fieldName.contains(".")){  
        String[] names = StringUtils.split(fieldName, ".");  
        expression = root.get(names[0]);  
        for (int i = 1; i < names.length; i++) {  
            expression = expression.get(names[i]);  
        }  
    }else{  
        expression = root.get(fieldName);  
    }  
    
    switch (operator) {  
    case EQ:  
        return builder.equal(expression, value);  
    case NE:  
        return builder.notEqual(expression, value);  
    case LIKE:  
        return builder.like((Expression<String>) expression, "%" + value + "%");  
    case LT:  
        return builder.lessThan(expression, (Comparable) value);  
    case GT:  
        return builder.greaterThan(expression, (Comparable) value);  
    case LTE:  
        return builder.lessThanOrEqualTo(expression, (Comparable) value);  
    case GTE:  
        return builder.greaterThanOrEqualTo(expression, (Comparable) value);  
    default:  
        return null;  
    }  
}
 
开发者ID:wengwh,项目名称:plumdo-work,代码行数:34,代码来源:SimpleExpression.java

示例2: getPath

import javax.persistence.criteria.Path; //导入依赖的package包/类
/**
 * Geef de Path voor de gegeven naam (kan punten bevatten om door objecten te lopen).
 *
 * @param base
 *            basis
 * @param naam
 *            naam
 * @param <T>
 *            attribuut type
 * @return path
 */
public static <T> Path<T> getPath(final Path<?> base, final String naam) {
    final Path<T> result;
    final int index = naam.indexOf('.');
    if (index == -1) {
        result = base.get(naam);
    } else {
        final String part = naam.substring(0, index);
        final String rest = naam.substring(index + 1);

        final Path<?> partPath = base.get(part);
        if (partPath.getModel() == null) {
            // Dan kunnen we hier niet door, maar moeten we via een join
            final Join<?, ?> join = ((From<?, ?>) base).join(part);
            result = getPath(join, rest);
        } else {
            result = getPath(partPath, rest);
        }
    }
    return result;
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:32,代码来源:PredicateBuilderUtil.java

示例3: findByDateRange

import javax.persistence.criteria.Path; //导入依赖的package包/类
public Collection<EndPointCheck> findByDateRange(final EndPoint endPoint, final Date startDate,
        final Date endDate) {
    final CriteriaBuilder criteriaBuilder = getEntityManager().getCriteriaBuilder();
    final CriteriaQuery<EndPointCheck> criteriaQuery = criteriaBuilder.createQuery(getEntityClass());
    final Root<EndPointCheck> root = criteriaQuery
            .from(getEntityManager().getMetamodel().entity(getEntityClass()));

    final ParameterExpression<EndPoint> endPointParameter = criteriaBuilder.parameter(EndPoint.class);
    final ParameterExpression<Date> startDateParameter = criteriaBuilder.parameter(Date.class);
    final ParameterExpression<Date> endDateParameter = criteriaBuilder.parameter(Date.class);

    final Predicate endPointIdPredicate = criteriaBuilder
            .equal(root.get("endPoint"), endPointParameter);

    final Path<Date> checkDatePath = root.<Date> get("checkDate");

    final Predicate startDatePredicate = criteriaBuilder
            .greaterThanOrEqualTo(checkDatePath, startDateParameter);

    final Predicate endDatePredicate = criteriaBuilder.lessThanOrEqualTo(
        checkDatePath,
        endDateParameter);

    criteriaQuery.where(criteriaBuilder.and(endPointIdPredicate, startDatePredicate, endDatePredicate));

    criteriaQuery.orderBy(Arrays.asList(criteriaBuilder.asc(checkDatePath)));

    return getEntityManager().createQuery(criteriaQuery)
            .setParameter(endPointParameter, endPoint)
            .setParameter(startDateParameter, startDate, TemporalType.DATE)
            .setParameter(endDateParameter, endDate, TemporalType.DATE)
            .getResultList();
}
 
开发者ID:spypunk,项目名称:endpoint-health,代码行数:34,代码来源:EndPointCheckDao.java

示例4: accountExpiresBefore

import javax.persistence.criteria.Path; //导入依赖的package包/类
/**
 * All customers with an {@link Account} expiring before the given date.
 * 
 * @param date
 * @return
 */
public static Specification<Customer> accountExpiresBefore(final LocalDate date) {

	return new Specification<Customer>() {

		@Override
		public Predicate toPredicate(Root<Customer> root, CriteriaQuery<?> query, CriteriaBuilder cb) {

			Root<Account> accounts = query.from(Account.class);
			Path<Date> expiryDate = accounts.<Date> get("expiryDate");
			Predicate customerIsAccountOwner = cb.equal(accounts.<Customer> get("customer"), root);
			Predicate accountExpiryDateBefore = cb.lessThan(expiryDate, date.toDateTimeAtStartOfDay().toDate());

			return cb.and(customerIsAccountOwner, accountExpiryDateBefore);
		}
	};
}
 
开发者ID:Just-Fun,项目名称:spring-data-examples,代码行数:23,代码来源:CustomerSpecifications.java

示例5: fetchNestedPath

import javax.persistence.criteria.Path; //导入依赖的package包/类
private Path<T> fetchNestedPath(Path<T> root, String fieldname) {
	String[] fields = fieldname.split("\\.");
	Path<T> result = null;
	for (String field : fields) {
		if(result == null) {
			result = root.get(field);
		} else {
			result = result.get(field);
		}
	}
	return result;
}
 
开发者ID:tairmansd,项目名称:CriteriaBuilder,代码行数:13,代码来源:CriteriaServiceImpl.java

示例6: getSort

import javax.persistence.criteria.Path; //导入依赖的package包/类
private <T> List<Order> getSort(Root<T> p_root, CriteriaBuilder p_builder, Sort[] p_sort) {
	
	List<Order> order = new LinkedList<Order>();
	
	if (p_sort != null && p_sort.length > 0) {				
		
		for (Sort sort : p_sort) {
			Path<?> property_path = null;		
			
			for (String hop : sort.getPropertyPath()) {
				if (property_path == null)
					property_path = p_root.get(hop);
				else
					property_path = property_path.get(hop);
			}
			if (sort.getOrderAscending()) {
				order.add(p_builder.asc(property_path));
			} else {
				order.add(p_builder.desc(property_path));
			}
		}			
	}
	
	return order;
}
 
开发者ID:awslabs,项目名称:aws-photosharing-example,代码行数:26,代码来源:ServiceFacade.java

示例7: getPath

import javax.persistence.criteria.Path; //导入依赖的package包/类
private Path<?> getPath(List<String> fieldNames, Root<T> root) {
    javax.persistence.criteria.Path<?> entity = root;
    
    for (String fieldName : fieldNames) {
        Path<Object> fieldAsPath = entity.get(fieldName);
        if ( Collection.class.isAssignableFrom( fieldAsPath.getJavaType() ) ) {
            if ( ! joinsMap.containsKey(fieldAsPath) ) {
                joinsMap.put(fieldAsPath, ((From<?, ?>) entity).join(fieldName));
            }
            entity = joinsMap.get(fieldAsPath);
        } else {
            entity = entity.get(fieldName);
        }
    }

    return entity;
}
 
开发者ID:jhonystein,项目名称:Pedidex,代码行数:18,代码来源:JpaCriteriaHelper.java

示例8: fetchUsedQuotas

import javax.persistence.criteria.Path; //导入依赖的package包/类
private Map<Long, Integer> fetchUsedQuotas() {
    final CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    final CriteriaQuery<Tuple> query = builder.createTupleQuery();
    final Root<HarvestReport> root = query.from(HarvestReport.class);

    Join<Harvest, HarvestQuota> joinedQuotas = root.join(HarvestReport_.harvests).join(Harvest_.harvestQuota, JoinType.LEFT);
    Path<Long> quotaId = joinedQuotas.get(HarvestQuota_.id);

    Expression<Long> count = builder.count(root.get(HarvestReport_.id));

    Predicate onlyApproved = builder.equal(root.get(HarvestReport_.state), HarvestReport.State.APPROVED);
    Predicate quotaNotNull = builder.isNotNull(quotaId);

    CriteriaQuery<Tuple> q = query
            .multiselect(quotaId, count)
            .where(onlyApproved, quotaNotNull)
            .groupBy(quotaId);
    return map(entityManager.createQuery(q).getResultList());
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:20,代码来源:PublicHarvestSeasonFeature.java

示例9: hasEndOfHuntingReportAndFieldsSpeciesIsPermitSpecies

import javax.persistence.criteria.Path; //导入依赖的package包/类
public static Specification<HarvestReport> hasEndOfHuntingReportAndFieldsSpeciesIsPermitSpecies(final Long fieldsId) {
    return (root, query, cb) -> {
        final Subquery<Integer> permitQuery = query.subquery(Integer.class);
        final Root<HarvestPermit> permitRoot = permitQuery.from(HarvestPermit.class);

        final ListJoin<HarvestPermit, HarvestPermitSpeciesAmount> speciesAmounts = permitRoot.join(HarvestPermit_.speciesAmounts);
        final Path<GameSpecies> speciesAmountsSpecies = speciesAmounts.get(HarvestPermitSpeciesAmount_.gameSpecies);

        final Subquery<Integer> fieldsQuery = query.subquery(Integer.class);
        final Root<HarvestReportFields> fieldsRoot = fieldsQuery.from(HarvestReportFields.class);

        final Predicate permitSpeciesEqualToFieldsSpecies = cb.and(
                cb.equal(fieldsRoot.get(HarvestReportFields_.id), fieldsId),
                cb.equal(fieldsRoot.get(HarvestReportFields_.species), speciesAmountsSpecies));
        final Predicate fieldsExists = cb.exists(fieldsQuery.select(cb.literal(1)).where(permitSpeciesEqualToFieldsSpecies));

        return cb.exists(permitQuery
                .select(cb.literal(1))
                .where(cb.and(
                        cb.equal(permitRoot.join(HarvestPermit_.endOfHuntingReport), permitQuery.correlate(root)),
                        fieldsExists))
        );
    };
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:25,代码来源:HarvestReportSpecs.java

示例10: withinInterval

import javax.persistence.criteria.Path; //导入依赖的package包/类
@Nonnull
public static Predicate withinInterval(
        @Nonnull final CriteriaBuilder cb,
        @Nonnull final Path<Date> path,
        @Nullable final LocalDate beginDate,
        @Nullable final LocalDate endDate) {

    Date _endDate = null;

    if (endDate != null) {
        if (beginDate != null) {
            Preconditions.checkArgument(!beginDate.isAfter(endDate), "beginDate must not be after endDate");
        }

        _endDate = DateUtil.toDateNullSafe(endDate.plusDays(1));
    }

    final Date _beginDate = DateUtil.toDateNullSafe(beginDate);

    return withinInterval(cb, path, _beginDate, _endDate);
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:22,代码来源:JpaPreds.java

示例11: withinHuntingYear

import javax.persistence.criteria.Path; //导入依赖的package包/类
@Nonnull
public static Predicate withinHuntingYear(
        @Nonnull final Path<Date> date,
        @Nonnull final Expression<Integer> huntingYear,
        @Nonnull final CriteriaBuilder cb) {

    final Expression<Integer> year = cb.function("year", Integer.class, date);
    final Expression<Integer> month = cb.function("month", Integer.class, date);

    final Predicate currentHuntingYearBeganLastYear = cb.lessThan(month, DateUtil.HUNTING_YEAR_BEGIN_MONTH);

    return cb.and(
            cb.isNotNull(date),
            cb.isNotNull(huntingYear),
            cb.or(
                    cb.and(cb.equal(year, huntingYear), cb.not(currentHuntingYearBeganLastYear)),
                    cb.and(cb.equal(year, cb.sum(huntingYear, 1)), currentHuntingYearBeganLastYear)));
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:19,代码来源:JpaPreds.java

示例12: findByName

import javax.persistence.criteria.Path; //导入依赖的package包/类
@Override
@Transactional(readOnly = true)
public User findByName(String name)	{
	final CriteriaBuilder builder = this.getEntityManager().getCriteriaBuilder();
	final CriteriaQuery<User> criteriaQuery = builder.createQuery(this.entityClass);

	Root<User> root = criteriaQuery.from(this.entityClass);
	Path<String> namePath = root.get("name");
	criteriaQuery.where(builder.equal(namePath, name));

	TypedQuery<User> typedQuery = this.getEntityManager().createQuery(criteriaQuery);
	List<User> users = typedQuery.getResultList();

	if (users.isEmpty()) {
		return null;
	}

	return users.iterator().next();
}
 
开发者ID:edu-xored,项目名称:memorise,代码行数:20,代码来源:JpaUserDao.java

示例13: byExample

import javax.persistence.criteria.Path; //导入依赖的package包/类
/**
 * Add a predicate for each simple property whose value is not null.
 */
public <T> List<Predicate> byExample(ManagedType<T> mt, Path<T> mtPath, final T mtValue, SearchParameters sp, CriteriaBuilder builder) {
    List<Predicate> predicates = newArrayList();
    for (SingularAttribute<? super T, ?> attr : mt.getSingularAttributes()) {
        if (attr.getPersistentAttributeType() == MANY_TO_ONE //
                || attr.getPersistentAttributeType() == ONE_TO_ONE //
                || attr.getPersistentAttributeType() == EMBEDDED) {
            continue;
        }

        Object attrValue = getValue(mtValue, attr);
        if (attrValue != null) {
            if (attr.getJavaType() == String.class) {
                if (isNotEmpty((String) attrValue)) {
                    predicates.add(JpaUtil.stringPredicate(mtPath.get(stringAttribute(mt, attr)), attrValue, sp, builder));
                }
            } else {
                predicates.add(builder.equal(mtPath.get(attribute(mt, attr)), attrValue));
            }
        }
    }
    return predicates;
}
 
开发者ID:ddRPB,项目名称:rpb,代码行数:26,代码来源:ByExampleUtil.java

示例14: byExampleOnXToOne

import javax.persistence.criteria.Path; //导入依赖的package包/类
/**
 * Invoke byExample method for each not null x-to-one association when their pk is not set. This allows you to search entities based on an associated
 * entity's properties value.
 */
@SuppressWarnings("unchecked")
public <T extends Identifiable<?>, M2O extends Identifiable<?>> List<Predicate> byExampleOnXToOne(ManagedType<T> mt, Root<T> mtPath, final T mtValue,
        SearchParameters sp, CriteriaBuilder builder) {
    List<Predicate> predicates = newArrayList();
    for (SingularAttribute<? super T, ?> attr : mt.getSingularAttributes()) {
        if (attr.getPersistentAttributeType() == MANY_TO_ONE || attr.getPersistentAttributeType() == ONE_TO_ONE) { //
            M2O m2oValue = (M2O) getValue(mtValue, mt.getAttribute(attr.getName()));
            if (m2oValue != null && !m2oValue.isIdSet()) {
                Class<M2O> m2oType = (Class<M2O>) attr.getBindableJavaType();
                ManagedType<M2O> m2oMt = em.getMetamodel().entity(m2oType);
                Path<M2O> m2oPath = (Path<M2O>) mtPath.get(attr);
                predicates.addAll(byExample(m2oMt, m2oPath, m2oValue, sp, builder));
            }
        }
    }
    return predicates;
}
 
开发者ID:ddRPB,项目名称:rpb,代码行数:22,代码来源:ByExampleUtil.java

示例15: getFilterSpecification

import javax.persistence.criteria.Path; //导入依赖的package包/类
private Specification<User> getFilterSpecification(Map<String, String> filterValues) {
	return (Root<User> root, CriteriaQuery<?> query, CriteriaBuilder builder) -> {
		Optional<Predicate> predicate = filterValues.entrySet().stream()
				.filter(v -> v.getValue() != null && v.getValue().length() > 0)
				.map(entry -> {
					Path<?> path = root;
					String key = entry.getKey();
					if (entry.getKey().contains(".")) {
						String[] splitKey = entry.getKey().split("\\.");
						path = root.join(splitKey[0]);
						key = splitKey[1];
					}
					return builder.like(path.get(key).as(String.class), "%" + entry.getValue() + "%");
				})
				.collect(Collectors.reducing((a, b) -> builder.and(a, b)));
		return predicate.orElseGet(() -> alwaysTrue(builder));
	};
}
 
开发者ID:Javatar81,项目名称:code-examples,代码行数:19,代码来源:UserService.java


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