com.querydsl.core.types.dsl.PathBuilder Java Examples
The following examples show how to use
com.querydsl.core.types.dsl.PathBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KeyValueQuerydslUtils.java From spring-data-keyvalue with Apache License 2.0 | 6 votes |
/** * Transforms a plain {@link Order} into a QueryDsl specific {@link OrderSpecifier}. * * @param sort must not be {@literal null}. * @param builder must not be {@literal null}. * @return empty {@code OrderSpecifier<?>[]} when sort is {@literal null}. */ static OrderSpecifier<?>[] toOrderSpecifier(Sort sort, PathBuilder<?> builder) { Assert.notNull(sort, "Sort must not be null."); Assert.notNull(builder, "Builder must not be null."); List<OrderSpecifier<?>> specifiers = null; if (sort instanceof QSort) { specifiers = ((QSort) sort).getOrderSpecifiers(); } else { specifiers = new ArrayList<>(); for (Order order : sort) { specifiers.add(toOrderSpecifier(order, builder)); } } return specifiers.toArray(new OrderSpecifier<?>[specifiers.size()]); }
Example #2
Source File: KeyValueQuerydslUtils.java From spring-data-keyvalue with Apache License 2.0 | 6 votes |
/** * Creates an {@link Expression} for the given {@link Order} property. * * @param order must not be {@literal null}. * @param builder must not be {@literal null}. * @return */ private static Expression<?> buildOrderPropertyPathFrom(Order order, PathBuilder<?> builder) { Assert.notNull(order, "Order must not be null!"); Assert.notNull(builder, "Builder must not be null!"); PropertyPath path = PropertyPath.from(order.getProperty(), builder.getType()); Expression<?> sortPropertyExpression = builder; while (path != null) { if (!path.hasNext() && order.isIgnoreCase()) { // if order is ignore-case we have to treat the last path segment as a String. sortPropertyExpression = Expressions.stringPath((Path<?>) sortPropertyExpression, path.getSegment()).lower(); } else { sortPropertyExpression = Expressions.path(path.getType(), (Path<?>) sortPropertyExpression, path.getSegment()); } path = path.next(); } return sortPropertyExpression; }
Example #3
Source File: QueryDslRepositorySupportExt.java From springlets with Apache License 2.0 | 5 votes |
/** * Returns the path of entity identifier field * * @return path of entity Identifier */ protected PathBuilder<Object> getEntityId() { if (entityIdPath == null) { EntityType<T> entity = getEntityMetaModel(); SingularAttribute<?, ?> id = entity.getId(entity.getIdType().getJavaType()); entityIdPath = getBuilder().get(id.getName()); } return entityIdPath; }
Example #4
Source File: QuerydslUtil.java From eds-starter6-jpa with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) public static OrderSpecifier[] createOrderSpecifiers( ExtDirectStoreReadRequest request, Class<?> clazz, EntityPathBase<?> entityPathBase, Map<String, String> mapGuiColumn2Dbfield, Set<String> sortIgnoreProperties) { List<OrderSpecifier> orders; if (!request.getSorters().isEmpty()) { orders = new ArrayList<>(); PathBuilder<?> entityPath = new PathBuilder<>(clazz, entityPathBase.getMetadata()); for (SortInfo sortInfo : request.getSorters()) { if (!sortIgnoreProperties.contains(sortInfo.getProperty())) { Order order; if (sortInfo.getDirection() == SortDirection.ASCENDING) { order = Order.ASC; } else { order = Order.DESC; } String property = mapGuiColumn2Dbfield.get(sortInfo.getProperty()); if (property == null) { property = sortInfo.getProperty(); } orders.add(new OrderSpecifier(order, entityPath.get(property))); } } } else { orders = Collections.emptyList(); } return orders.toArray(new OrderSpecifier[orders.size()]); }
Example #5
Source File: PredicateBuilder.java From spring-data-jpa-datatables with Apache License 2.0 | 5 votes |
private void initPredicatesRecursively(Node<Filter> node, PathBuilder<?> pathBuilder) { if (node.isLeaf()) { boolean hasColumnFilter = node.getData() != null; if (hasColumnFilter) { Filter columnFilter = node.getData(); columnPredicates.add(columnFilter.createPredicate(pathBuilder, node.getName())); } else if (hasGlobalFilter) { Filter globalFilter = tree.getData(); globalPredicates.add(globalFilter.createPredicate(pathBuilder, node.getName())); } } for (Node<Filter> child : node.getChildren()) { initPredicatesRecursively(child, child.isLeaf() ? pathBuilder : pathBuilder.get(child.getName())); } }
Example #6
Source File: QuerydslKeyValueRepository.java From spring-data-keyvalue with Apache License 2.0 | 5 votes |
/** * Creates a new {@link QuerydslKeyValueRepository} for the given {@link EntityInformation}, * {@link KeyValueOperations} and {@link EntityPathResolver}. * * @param entityInformation must not be {@literal null}. * @param operations must not be {@literal null}. * @param resolver must not be {@literal null}. */ public QuerydslKeyValueRepository(EntityInformation<T, ID> entityInformation, KeyValueOperations operations, EntityPathResolver resolver) { super(entityInformation, operations); Assert.notNull(resolver, "EntityPathResolver must not be null!"); EntityPath<T> path = resolver.createPath(entityInformation.getJavaType()); this.builder = new PathBuilder<>(path.getType(), path.getMetadata()); }
Example #7
Source File: QDataTablesRepositoryImpl.java From spring-data-jpa-datatables with Apache License 2.0 | 4 votes |
public QDataTablesRepositoryImpl(JpaEntityInformation<T, ID> entityInformation, EntityManager entityManager, EntityPathResolver resolver) { super(entityInformation, entityManager); EntityPath<T> path = resolver.createPath(entityInformation.getJavaType()); this.builder = new PathBuilder<>(path.getType(), path.getMetadata()); }
Example #8
Source File: GlobalFilter.java From spring-data-jpa-datatables with Apache License 2.0 | 4 votes |
@Override public com.querydsl.core.types.Predicate createPredicate(PathBuilder<?> pathBuilder, String attributeName) { StringOperation path = Expressions.stringOperation(Ops.STRING_CAST, pathBuilder.get(attributeName)); return path.lower().like(escapedRawValue, '~'); }
Example #9
Source File: PredicateBuilder.java From spring-data-jpa-datatables with Apache License 2.0 | 4 votes |
public PredicateBuilder(PathBuilder<?> entity, DataTablesInput input) { super(input); this.entity = entity; }
Example #10
Source File: KeyValueQuerydslUtils.java From spring-data-keyvalue with Apache License 2.0 | 4 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) private static OrderSpecifier<?> toOrderSpecifier(Order order, PathBuilder<?> builder) { return new OrderSpecifier( order.isAscending() ? com.querydsl.core.types.Order.ASC : com.querydsl.core.types.Order.DESC, buildOrderPropertyPathFrom(order, builder), toQueryDslNullHandling(order.getNullHandling())); }
Example #11
Source File: KeyValueQuerydslUtilsUnitTests.java From spring-data-keyvalue with Apache License 2.0 | 4 votes |
@Before public void setUp() { this.path = SimpleEntityPathResolver.INSTANCE.createPath(Person.class); this.builder = new PathBuilder<>(path.getType(), path.getMetadata()); }
Example #12
Source File: QueryDslRepositorySupportExt.java From springlets with Apache License 2.0 | 3 votes |
/** * Adds to a query an order by the entity identifier related to this repository. * This is useful as the default last order in queries where pagination is * applied, so you have always an absolute order. Otherwise, the order * of the results depends on the database criteria, which might change * even between pages, returning confusing results for the user. * @param query * @return the updated query */ @SuppressWarnings({"rawtypes", "unchecked"}) protected JPQLQuery<T> applyOrderById(JPQLQuery<T> query) { PathBuilder<Object> idPath = getEntityId(); return query.orderBy(new OrderSpecifier(Order.ASC, idPath, NullHandling.NullsFirst)); }
Example #13
Source File: Filter.java From spring-data-jpa-datatables with Apache License 2.0 | votes |
com.querydsl.core.types.Predicate createPredicate(PathBuilder<?> pathBuilder, String attributeName);