@SuppressWarnings("unchecked") public static <T> Expression defaultGetEntityField(CriteriaQuery<T> query, String listId, Attribute attr) { Expression entityField = null; if( attr != null ) { Class attrType = attr.getDeclaringType().getJavaType(); for( From from : query.getRoots() ) { if( from.getJavaType().equals(attrType) ) { if( attr != null ) { if( attr instanceof SingularAttribute ) { entityField = from.get((SingularAttribute) attr); } else if( attr instanceof PluralAttribute ) { entityField = from.get((PluralAttribute) attr); } else { throw new IllegalStateException("Unexpected attribute type when processing criteria with list id " + listId + ": " + attr.getClass().getName() ); } break; } } } } // if entityField == null, this is because this QueryCriteria is a implementation specific criteria, such as "LAST_VARIABLE_LIST" return entityField; }
From [] taskRoots = { taskRoot, taskDataJoin }; for( From from : taskRoots ) { if( from.getJavaType().equals(attrType) ) { if( attr != null ) { if( attr instanceof SingularAttribute ) {
/** * Creates a criteria API {@link javax.persistence.criteria.Order} from the given {@link Order}. * * @param order the order to transform into a JPA {@link javax.persistence.criteria.Order} * @param from the {@link From} the {@link Order} expression is based on * @param cb the {@link CriteriaBuilder} to build the {@link javax.persistence.criteria.Order} with * @return */ @SuppressWarnings("unchecked") private static javax.persistence.criteria.Order toJpaOrder(Order order, From<?, ?> from, CriteriaBuilder cb) { PropertyPath property = PropertyPath.from(order.getProperty(), from.getJavaType()); Expression<?> expression = toExpressionRecursively(from, property); if (order.isIgnoreCase() && String.class.equals(expression.getJavaType())) { Expression<String> lower = cb.lower((Expression<String>) expression); return order.isAscending() ? cb.asc(lower) : cb.desc(lower); } else { return order.isAscending() ? cb.asc(expression) : cb.desc(expression); } }
From [] taskRoots = { taskRoot, taskDataJoin }; for( From from : taskRoots ) { if( from.getJavaType().equals(attrType) ) { if( attr != null ) { if( attr instanceof SingularAttribute ) {
if (frame.getMethod().equals(desc.getReadMethod())) { Predicate joinPredicate; if (joinRoot.get(property).getJavaType().equals(getFrom().getJavaType())) { joinPredicate = getBuilder().equal(getFrom(), joinRoot.get(property)); } else {
if (frame.getMethod().equals(desc.getReadMethod())) { Predicate joinPredicate; if (getFrom().get(property).getJavaType().equals(jointRoot.getJavaType())) { joinPredicate = getBuilder().equal(getFrom().get(property), jointRoot); } else {
/** * Creates a criteria API {@link javax.persistence.criteria.Order} from the given {@link Order}. * * @param order the order to transform into a JPA {@link javax.persistence.criteria.Order} * @param from the {@link From} the {@link Order} expression is based on * @param cb the {@link CriteriaBuilder} to build the {@link javax.persistence.criteria.Order} with * @return */ @SuppressWarnings("unchecked") private static javax.persistence.criteria.Order toJpaOrder(Order order, From<?, ?> from, CriteriaBuilder cb) { PropertyPath property = PropertyPath.from(order.getProperty(), from.getJavaType()); Expression<?> expression = toExpressionRecursively(from, property); if (order.isIgnoreCase() && String.class.equals(expression.getJavaType())) { Expression<String> lower = cb.lower((Expression<String>) expression); return order.isAscending() ? cb.asc(lower) : cb.desc(lower); } else { return order.isAscending() ? cb.asc(expression) : cb.desc(expression); } }
@SuppressWarnings("unchecked") final Subquery<Object> sq = (Subquery<Object>) cq.subquery(entityType.getKeyType()); final Root<?> sr = sq.from(root.getJavaType()); final Expression<Object> sel = sr.get(keyPath.getPath().get(0).getInternalName()); sq.select(sel);
protected void createRoots(final JPAAssociationPath association) throws ODataJPAQueryException { if (association.getJoinTable() != null) { if (association.getJoinTable().getEntityType() != null) { if (aggregationType != null) { this.queryJoinTable = subQuery.from(from.getJavaType()); From<?, ?> p = queryJoinTable; for (int i = 0; i < association.getPath().size() - 1; i++) p = p.join(association.getPath().get(i).getInternalName()); this.queryRoot = p.join(association.getLeaf().getInternalName(), JoinType.LEFT); } else { this.queryRoot = subQuery.from(this.jpaEntity.getTypeClass()); this.queryJoinTable = subQuery.from(association.getJoinTable().getEntityType().getTypeClass()); } } else { throw new ODataJPAQueryException(ODataJPAQueryException.MessageKeys.QUERY_PREPARATION_NOT_IMPLEMENTED, HttpStatusCode.NOT_IMPLEMENTED, association.getAlias()); } } else { this.queryRoot = subQuery.from(this.jpaEntity.getTypeClass()); } }