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


Java Root.get方法代码示例

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


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

示例1: toPredicate

import javax.persistence.criteria.Root; //导入方法依赖的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: findByDateRange

import javax.persistence.criteria.Root; //导入方法依赖的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

示例3: accountExpiresBefore

import javax.persistence.criteria.Root; //导入方法依赖的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

示例4: getSort

import javax.persistence.criteria.Root; //导入方法依赖的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: getPath

import javax.persistence.criteria.Root; //导入方法依赖的package包/类
public static <X, T> Expression<X> getPath(Root<T> root, String name) {
	String[] array = name.split("[.]");
	Expression<X> expr = root.get(array[0]);
	for (int i = 1; i < array.length; i++) {
		expr = ((Path<X>) expr).get(array[i]);
	}
	return expr;
}
 
开发者ID:szsucok,项目名称:sucok-framework,代码行数:9,代码来源:QueryFormHelper.java

示例6: buscarTodos

import javax.persistence.criteria.Root; //导入方法依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"})
public List<T> buscarTodos(String... atributos) {
    CriteriaBuilder cb = entityManager.getCriteriaBuilder();
    CriteriaQuery cq = entityManager.getCriteriaBuilder().createQuery();
    Root<T> root = cq.from(entityClass);
    Selection[] selections = new Selection[atributos.length];
    for (int i = 0; i < atributos.length; i++) {
        selections[i] = root.get(atributos[i]);
    }
    cq.select(cb.construct(entityClass, selections));
    cq.orderBy(cb.desc(root.get("id")));
    return entityManager.createQuery(cq).getResultList();
}
 
开发者ID:JDanielT,项目名称:search-doc,代码行数:14,代码来源:DAOGenerico.java

示例7: getIsMemberOfPredicate

import javax.persistence.criteria.Root; //导入方法依赖的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

示例8: getFilterPredicate

import javax.persistence.criteria.Root; //导入方法依赖的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

示例9: updateTask

import javax.persistence.criteria.Root; //导入方法依赖的package包/类
public void updateTask(final ToDoList pToDoList) {
	
       final CriteriaBuilder lCriteriaBuilder = entityManager.getCriteriaBuilder();
       
       //Creation de la requête d'update
       final CriteriaUpdate<ToDoList> lCriteriaUpdate = lCriteriaBuilder.createCriteriaUpdate(ToDoList.class);
       final Root<ToDoList> lRoot = lCriteriaUpdate.from(ToDoList.class);
       final Path<ToDoList> lPath = lRoot.get("id");
       //On utilise la variable pToDoList transmise en parametre de la methode
       final Expression<Boolean> lExpression = lCriteriaBuilder.equal(lPath, pToDoList.getId());
       lCriteriaUpdate.where(lExpression);
       lCriteriaUpdate.set("libelle", pToDoList.getLibelle());
       
       final Query lQuery = entityManager.createQuery(lCriteriaUpdate);
       final int lRowCount = lQuery.executeUpdate();
       
       //Si la requête modifie un nombre d'occurrences différent de 1 > erreur
       //Sinon update fait.
       if (lRowCount != 1) {
           final org.hibernate.Query lHQuery = lQuery.unwrap(org.hibernate.Query.class);
           final String lSql = lHQuery.getQueryString();
           throw new RuntimeException("Nombre d'occurences (" + lRowCount + 
                   ") modifiés différent de 1 pour " + lSql);
       }
	
}
 
开发者ID:Julien35,项目名称:dev-courses,代码行数:27,代码来源:ToDoListDAO.java

示例10: filtrarPorNome

import javax.persistence.criteria.Root; //导入方法依赖的package包/类
public List<Pessoa> filtrarPorNome(String filtro){
	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>();

	Expression<String> path = root.get("nome");
	condicoes.add(cb.like(path, "%"+filtro+"%"));
	
	cquery.select(root).where(condicoes.toArray(new Predicate[]{}));
	List<Pessoa> pessoas = getEntityManager().createQuery(cquery).getResultList();
		    	
   	return pessoas;
}
 
开发者ID:kashm1r,项目名称:photoiff,代码行数:16,代码来源:PessoaService.java

示例11: getExpression

import javax.persistence.criteria.Root; //导入方法依赖的package包/类
/**
 * Cree une expression Criteria API avec l'atribut de l'entité passé en parametre
 * 
 * @param root
 *            entité JPA contenant le champ
 * @param columnData
 *            nom du champ
 * @param clazz
 *            class du champ
 * @param <S>
 *            type du champ
 * @return l'expression de l'atribut
 */
public static <S> Path<S> getExpression(final Root<?> root, final String columnData, final Class<S> clazz) {
    if (!columnData.contains(DatatableSpecification.ATTRIBUTE_SEPARATOR)) {
        // columnData is like "attribute" so nothing particular to do
        return root.get(columnData);
    }
    // columnData is like "joinedEntity.attribute" so add a join clause
    final String[] values = columnData.split(DatatableSpecification.ESCAPED_ATTRIBUTE_SEPARATOR);
    final Attribute<?, ?> attribute = root.getModel().getAttribute(values[0]);
    if (attribute == null) {
        throw new IllegalArgumentException(
            "Colonne '" + values[0] + "' (" + columnData + ") introuvable depuis l'entité '" + root.getJavaType()
                + "'");
    }
    if (attribute.getPersistentAttributeType() == PersistentAttributeType.EMBEDDED) {
        // with @Embedded attribute
        return root.get(values[0]).get(values[1]);
    }
    From<?, ?> from = root;
    for (int i = 0; i < values.length - 1; i++) {

        Join<?, ?> join = null;
        for (final Join<?, ?> joinCandidate : from.getJoins()) {
            if (joinCandidate.getAttribute().getName().equals(values[i])) {
                // LOGGER.debug("Trouve joint d'entite: '{}'", values[i]);
                join = joinCandidate;
            }
        }
        if (join == null) {
            // LOGGER.debug("Joigant entite '{}'...", values[i]);
            join = from.join(values[i], JoinType.INNER);
        }
        from = join;
    }
    return from.get(values[values.length - 1]);
}
 
开发者ID:andresoviedo,项目名称:datatable-java,代码行数:49,代码来源:DatatableHelper.java

示例12: hibernatePluralPathTest

import javax.persistence.criteria.Root; //导入方法依赖的package包/类
@Test
public void hibernatePluralPathTest() {
	CriteriaBuilder build = em.getCriteriaBuilder();
	CriteriaQuery<OneToManyInstance> critQ = build.createQuery(OneToManyInstance.class);
	Root<OneToManyInstance> resultRoot = critQ.from(OneToManyInstance.class);
	Path pluralPath = resultRoot.get("many");
	Bindable shouldBePluralAttribute = pluralPath.getModel();
	assertNotNull(shouldBePluralAttribute);

	assertTrue(shouldBePluralAttribute instanceof PluralAttribute);
}
 
开发者ID:gdjennings,项目名称:elrest-java,代码行数:12,代码来源:JPAFilterImplTest.java

示例13: toPredicate

import javax.persistence.criteria.Root; //导入方法依赖的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


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