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


Java Path.get方法代码示例

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


在下文中一共展示了Path.get方法的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: 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

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

示例5: buildPredicate

import javax.persistence.criteria.Path; //导入方法依赖的package包/类
@SuppressWarnings ({ "unchecked", "rawtypes" })
protected Predicate buildPredicate(Path<T> root, SearchField field)
{
	Path<T> tt = (!field.getField().contains(".")) ? root.get(field.getField()) : fetchNestedPath(root, field.getField());
	CriteriaBuilder criteriaBuilder = this.entitymanager.getCriteriaBuilder();
	
	Class<?> javaType = tt.getJavaType();
	
	if (!classCompatibleWithOperator(javaType, field.getOperator()))
	{
		throw new RuntimeException("operator incompatible with field");
	}
	
	Object valueObject = convertStringValueToObject(field.getValue(), javaType);
	switch (field.getOperator())
	{
		case GE:
			return criteriaBuilder.greaterThan((Expression) tt, (Comparable) valueObject);
		case GTE:
			return criteriaBuilder.greaterThanOrEqualTo((Expression) tt, (Comparable) valueObject);
		case LE:
			return criteriaBuilder.lessThan((Expression) tt, (Comparable) valueObject);
		case LTE:
			return criteriaBuilder.lessThanOrEqualTo((Expression) tt, (Comparable) valueObject);
		case NE: 
               return criteriaBuilder.notEqual(tt, valueObject); 
		case EX:
			return criteriaBuilder.like((Expression) tt, "%"+field.getValue()+"%");
		default:
		{
			//EQ
			return criteriaBuilder.equal(tt, valueObject);
		}
	}
}
 
开发者ID:tairmansd,项目名称:CriteriaBuilder,代码行数:36,代码来源:CriteriaServiceImpl.java

示例6: getIsMemberOfPredicate

import javax.persistence.criteria.Path; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
private <C,T> Predicate getIsMemberOfPredicate(Root<C> p_root, CriteriaBuilder p_builder, Filter p_filter) {
	if (p_filter == null)
		return null;
	
	Path<? extends Collection> property_path = null;	
	
	for (String hop : p_filter.getPropertyPath()) {
		if (property_path == null)
			property_path = p_root.get(hop);
		else
			property_path = property_path.get(hop);
	}		
	return p_builder.isMember(p_filter.getValue(), property_path);
}
 
开发者ID:awslabs,项目名称:aws-photosharing-example,代码行数:16,代码来源:ServiceFacade.java

示例7: getFilterPredicate

import javax.persistence.criteria.Path; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private <T> Predicate getFilterPredicate(Function<Predicate[], Predicate>  p_method, Root<T> p_root, CriteriaBuilder p_builder, Filter[] p_filter) {
	 
	 Predicate predicate = null;
	 
	 if (p_filter != null && p_filter.length > 0) {	
			Path<?> property_path = null;							
			LinkedList<Predicate> predicates = new LinkedList<Predicate>();				
			
			for (Filter filter: p_filter) {							
				for (String hop : filter.getPropertyPath()) {
					if (property_path == null)
						property_path = p_root.get(hop);
					else
						property_path = property_path.get(hop);
				}
				if (filter.getValue() != null) {
					if (filter.isExact())
						predicates.add(p_builder.equal(property_path, filter.getValue()));
					else
						predicates.add(p_builder.like((Expression<String>) property_path, filter.getValue()+"%"));
				} else {
					if (filter.isInverse())
						predicates.add(p_builder.isNotNull(property_path));
					else
						predicates.add(p_builder.isNull(property_path));
				}
				
				property_path = null;					
			}											
			
			if (predicates.size() > 1)
				predicate = p_method.apply(predicates.toArray(new Predicate[predicates.size()]));
			else
				predicate = predicates.get(0);							
	}				 
	return predicate;
 }
 
开发者ID:awslabs,项目名称:aws-photosharing-example,代码行数:39,代码来源:ServiceFacade.java

示例8: 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(".")) {
        
        System.out.println(root);
        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 RLIKE:
        return builder.like((Expression<String>) expression, value + "%");
    case LLIKE:
        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);
    case ISNULL:
        return builder.isNull(expression);
    case NOTNULL:
        return builder.isNotNull(expression);
    default:
        return null;
    }
}
 
开发者ID:ccfish86,项目名称:sctalk,代码行数:43,代码来源:SimpleExpression.java

示例9: organisationEqual

import javax.persistence.criteria.Path; //导入方法依赖的package包/类
private static Predicate organisationEqual(final Path<Organisation> organisationJoin,
                                           final CriteriaBuilder cb,
                                           final String officialCode,
                                           final OrganisationType organisationType) {
    final Path<OrganisationType> organisationTypePath = organisationJoin.get(Organisation_.organisationType);
    final Path<String> organisationCodePath = organisationJoin.get(Organisation_.officialCode);

    return cb.and(
            cb.equal(organisationTypePath, organisationType),
            cb.equal(organisationCodePath, officialCode));
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:12,代码来源:PublicOccupationSearchParameters.java

示例10: getPropertyOrderPath

import javax.persistence.criteria.Path; //导入方法依赖的package包/类
/**
 * Convert the passed propertyPath into a JPA path. <br>
 * Note: JPA will do joins if the property is in an associated entity.
 */
@SuppressWarnings("unchecked")
private static <E> Path<?> getPropertyOrderPath(Root<E> root, String propertyPath, SearchParameters sp) {
    String[] pathItems = StringUtils.split(propertyPath, ".");

    Path<?> path = null;

    String pathItem = pathItems[0];
    if (sp.getDistinct()) {
        // handle case when order on already fetched attribute
        for (Fetch<E, ?> fetch : root.getFetches()) {
            if (pathItem.equals(fetch.getAttribute().getName()) && fetch instanceof Join<?, ?>) {
                path = (Join<E, ?>) fetch;
            }
        }
        for (Join<E, ?> join : root.getJoins()) {
            if (pathItem.equals(join.getAttribute().getName()) && join instanceof Join<?, ?>) {
                path = (Join<E, ?>) join;
            }
        }
    }

    // if no fetch matches the required path item, load it from root
    if (path == null) {
        path = root.get(pathItem);
    }

    for (int i = 1; i < pathItems.length; i++) {
        path = path.get(pathItems[i]);
    }
    return path;
}
 
开发者ID:ddRPB,项目名称:rpb,代码行数:36,代码来源:JpaUtil.java

示例11: getPath

import javax.persistence.criteria.Path; //导入方法依赖的package包/类
public Path<?> getPath(Alias alias) {
    List<String> pathElements = new ArrayList<String>();
    From<?, ?> from = getFrom(alias);
    while (from instanceof Join) {
        Join<?, ?> join = (Join<?, ?>)from;
        pathElements.add(0, join.getAttribute().getName());
        from = join.getParent();
    }
    Root<?> root = (Root<?>)from;
    Path<?> path = root;
    for (String pathElement: pathElements) {
        path = path.get(pathElement);
    }
    return path;
}
 
开发者ID:ArneLimburg,项目名称:jpasecurity,代码行数:16,代码来源:CriteriaHolder.java

示例12: getPropertyPath

import javax.persistence.criteria.Path; //导入方法依赖的package包/类
/**
 * Convert the passed propertyPath into a JPA path. Note: JPA will do joins
 * if the property is in an associated
 * entity.
 */
private static <E> Path<?> getPropertyPath(final Path<E> root, final String propertyPath) {
    String[] pathItems = StringUtils.split(propertyPath, ".");

    Path<?> path = root.get(pathItems[0]);
    for (int i = 1; i < pathItems.length; i++) {
        path = path.get(pathItems[i]);
    }
    return path;
}
 
开发者ID:antoniomaria,项目名称:karaf4-eclipselink-jpa,代码行数:15,代码来源:JpaUtil.java

示例13: getPath

import javax.persistence.criteria.Path; //导入方法依赖的package包/类
/**
 * Convert the passed propertyPath into a JPA path.
 * <p>
 * Note: JPA will do joins if the property is in an associated entity.
 */
@SuppressWarnings("unchecked")
public static <E, F> Path<F> getPath(Root<E> root, List<Attribute<?, ?>> attributes) {
    Path<?> path = root;
    for (Attribute<?, ?> attribute : attributes) {
        boolean found = false;
        // handle case when order on already fetched attribute
        for (Fetch<E, ?> fetch : root.getFetches()) {
            if (attribute.getName().equals(fetch.getAttribute().getName()) && (fetch instanceof Join<?, ?>)) {
                path = (Join<E, ?>) fetch;
                found = true;
                break;
            }
        }
        for (Join<E, ?> join : root.getJoins()) {
            if (attribute.getName().equals(join.getAttribute().getName())) {
                path = join;
                found = true;
                break;
            }
        }
        if (!found) {
            path = path.get(attribute.getName());
        }
    }
    return (Path<F>) path;
}
 
开发者ID:antoniomaria,项目名称:karaf4-eclipselink-jpa,代码行数:32,代码来源:JpaUtil.java

示例14: getFieldPath

import javax.persistence.criteria.Path; //导入方法依赖的package包/类
/**
 * Resolves the Path for a field in the persistence layer and joins the
 * required models. This operation is part of a tree traversal through
 * an RSQL expression. It creates for every field that is not part of
 * the root model a join to the foreign model. This behavior is
 * optimized when several joins happen directly under an OR node in the
 * traversed tree. The same foreign model is only joined once.
 *
 * Example: tags.name==M;(tags.name==A,tags.name==B,tags.name==C) This
 * example joins the tags model only twice, because for the OR node in
 * brackets only one join is used.
 *
 * @param enumField
 *            field from a FieldNameProvider to resolve on the
 *            persistence layer
 * @param finalProperty
 *            dot notated field path
 * @return the Path for a field
 */
private Path<Object> getFieldPath(final A enumField, final String finalProperty) {
    Path<Object> fieldPath = null;
    final String[] split = finalProperty.split("\\" + FieldNameProvider.SUB_ATTRIBUTE_SEPERATOR);

    for (int i = 0; i < split.length; i++) {
        final boolean isMapKeyField = enumField.isMap() && i == (split.length - 1);
        if (isMapKeyField) {
            return fieldPath;
        }

        final String fieldNameSplit = split[i];
        fieldPath = (fieldPath != null) ? fieldPath.get(fieldNameSplit) : root.get(fieldNameSplit);
        if (fieldPath instanceof PluralJoin) {
            final Join<Object, ?> join = (Join<Object, ?>) fieldPath;
            final From<?, Object> joinParent = join.getParent();
            final Optional<Join<Object, Object>> currentJoinOfType = findCurrentJoinOfType(join.getJavaType());
            if (currentJoinOfType.isPresent() && isOrLevel) {
                // remove the additional join and use the existing one
                joinParent.getJoins().remove(join);
                fieldPath = currentJoinOfType.get();
            } else {
                final Join<Object, Object> newJoin = joinParent.join(fieldNameSplit, JoinType.LEFT);
                addCurrentJoin(newJoin);
                fieldPath = newJoin;
            }

        }
    }
    return fieldPath;
}
 
开发者ID:eclipse,项目名称:hawkbit,代码行数:50,代码来源:RSQLUtility.java

示例15: getPropertyPathByDotName

import javax.persistence.criteria.Path; //导入方法依赖的package包/类
private Path getPropertyPathByDotName(Root<T> table, String propertyName)
{
	if (logger != null && logger.isDebugEnabled())
	{
		logger.debug(LOG_TAG, "ODataFilterToJpaQueryBuilder.getPropertyPathByDotName \"" + propertyName + "\"");
	}

	Path<Object> ret = null;
	int i = 0;
	while (propertyName.length() > 0 && ((i = propertyName.indexOf('.')) > 0))
	{
		final String nextProperty = propertyName.substring(0, i);
		if (logger != null && logger.isDebugEnabled())
		{
			logger.debug(LOG_TAG,
				"ODataFilterToJpaQueryBuilder.getPropertyPathByDotName nextProperty=\"" + nextProperty + "\"");
		}
		if (ret == null)
		{
			ret = table.get(nextProperty);
		}
		else
		{
			ret = ret.get(nextProperty);
		}
		propertyName = propertyName.substring(i + 1);
	}
	if (logger != null && logger.isDebugEnabled())
	{
		logger.debug(LOG_TAG, "ODataFilterToJpaQueryBuilder.getPropertyPathByDotName ret=" + ret);
	}
	return ret == null ? table.get(propertyName) : ret.get(propertyName);
}
 
开发者ID:giraone,项目名称:pms-sample-jee-01,代码行数:34,代码来源:ODataToJpaQueryBuilder.java


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