com.querydsl.core.types.dsl.EntityPathBase Java Examples

The following examples show how to use com.querydsl.core.types.dsl.EntityPathBase. 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: BaseService.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
/**
 * 查询列表
 *
 * @param pageNo             分页参数
 * @param pageSize           分页大小
 * @param predicateList      查询条件
 * @param entityPathBase     查询表
 * @param orderSpecifierList 排序条件
 * @return
 */
@Transactional(readOnly = true)
public PageResult<T> queryDsl(Integer pageNo, Integer pageSize, List<Predicate> predicateList, EntityPathBase<T> entityPathBase, List<OrderSpecifier> orderSpecifierList) {
    List<T> list;
    //查询表
    JPAQuery<T> jpaQuery = queryFactory.selectFrom(entityPathBase);
    //查询条件
    if (predicateList != null && predicateList.size() > 0) {
        jpaQuery.where(predicateList.toArray(new Predicate[predicateList.size()]));
    }
    //排序方式
    if (orderSpecifierList != null && orderSpecifierList.size() > 0) {
        jpaQuery.orderBy(orderSpecifierList.toArray(new OrderSpecifier[orderSpecifierList.size()]));
    }
    //分页查询
    if (pageNo != null && pageSize != null) {
        list = jpaQuery.offset((pageNo - 1) * pageSize).limit(pageSize).fetch();
    } else {
        list = jpaQuery.fetch();
    }
    return new PageResult<>(list, pageNo, pageSize, jpaQuery.fetchCount());
}
 
Example #2
Source File: BaseService.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
/**
 * 查询列表
 *
 * @param pageNo             分页参数
 * @param pageSize           分页大小
 * @param predicateList      查询条件
 * @param entityPathBase     查询表
 * @param orderSpecifierList 排序条件
 * @return
 */
@Transactional(readOnly = true)
public PageResult<T> queryDsl(Integer pageNo, Integer pageSize, List<Predicate> predicateList, EntityPathBase<T> entityPathBase, List<OrderSpecifier> orderSpecifierList) {
    List<T> list;
    //查询表
    JPAQuery<T> jpaQuery = queryFactory.selectFrom(entityPathBase);
    //查询条件
    if (predicateList != null && predicateList.size() > 0) {
        jpaQuery.where(predicateList.toArray(new Predicate[predicateList.size()]));
    }
    //排序方式
    if (orderSpecifierList != null && orderSpecifierList.size() > 0) {
        jpaQuery.orderBy(orderSpecifierList.toArray(new OrderSpecifier[orderSpecifierList.size()]));
    }
    //分页查询
    if (pageNo != null && pageSize != null) {
        list = jpaQuery.offset((pageNo - 1) * pageSize).limit(pageSize).fetch();
    } else {
        list = jpaQuery.fetch();
    }
    return new PageResult<>(list, pageNo, pageSize, jpaQuery.fetchCount());
}
 
Example #3
Source File: QuerydslUtil.java    From eds-starter6-jpa with Apache License 2.0 5 votes vote down vote up
public static void addPagingAndSorting(JPQLQuery<?> query,
		ExtDirectStoreReadRequest request, Class<?> clazz,
		EntityPathBase<?> entityPathBase, Map<String, String> mapGuiColumn2Dbfield,
		Set<String> sortIgnoreProperties) {

	if (request.getStart() != null && request.getLimit() != null
			&& request.getLimit() > 0) {
		query.offset(request.getStart()).limit(request.getLimit());
	}

	addSorting(query, request, clazz, entityPathBase, mapGuiColumn2Dbfield,
			sortIgnoreProperties);
}
 
Example #4
Source File: QuerydslUtil.java    From eds-starter6-jpa with Apache License 2.0 5 votes vote down vote up
public static void addSorting(JPQLQuery<?> query, ExtDirectStoreReadRequest request,
		Class<?> clazz, EntityPathBase<?> entityPathBase,
		Map<String, String> mapGuiColumn2Dbfield, Set<String> sortIgnoreProperties) {

	if (!request.getSorters().isEmpty()) {
		query.orderBy(createOrderSpecifiers(request, clazz, entityPathBase,
				mapGuiColumn2Dbfield, sortIgnoreProperties));
	}

}
 
Example #5
Source File: QuerydslUtil.java    From eds-starter6-jpa with Apache License 2.0 5 votes vote down vote up
@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 #6
Source File: QuerydslUtil.java    From eds-starter6-jpa with Apache License 2.0 4 votes vote down vote up
public static void addPagingAndSorting(JPQLQuery<?> query,
		ExtDirectStoreReadRequest request, Class<?> clazz,
		EntityPathBase<?> entityPathBase) {
	addPagingAndSorting(query, request, clazz, entityPathBase,
			Collections.<String, String>emptyMap(), Collections.<String>emptySet());
}
 
Example #7
Source File: QuerydslUtil.java    From eds-starter6-jpa with Apache License 2.0 4 votes vote down vote up
public static void addSorting(JPQLQuery<?> query, ExtDirectStoreReadRequest request,
		Class<?> clazz, EntityPathBase<?> entityPathBase) {
	addSorting(query, request, clazz, entityPathBase,
			Collections.<String, String>emptyMap(), Collections.<String>emptySet());
}
 
Example #8
Source File: BaseService.java    From ZTuoExchange_framework with MIT License 2 votes vote down vote up
/**
 * 查询单个
 *
 * @param predicate      查询条件
 * @param entityPathBase 查询表
 * @return
 */
@Transactional(readOnly = true)
public T queryOneDsl(Predicate predicate, EntityPathBase<T> entityPathBase) {
    return queryFactory.selectFrom(entityPathBase).where(predicate).fetchFirst();
}
 
Example #9
Source File: BaseService.java    From ZTuoExchange_framework with MIT License 2 votes vote down vote up
/**
 * 查询单个
 *
 * @param predicate      查询条件
 * @param entityPathBase 查询表
 * @return
 */
@Transactional(readOnly = true)
public T queryOneDsl(Predicate predicate, EntityPathBase<T> entityPathBase) {
    return queryFactory.selectFrom(entityPathBase).where(predicate).fetchFirst();
}
 
Example #10
Source File: QueryDSLRepository.java    From library with Apache License 2.0 2 votes vote down vote up
/**
 * Get the {@link EntityPathBase} to be used as root object for this repository
 *
 * @return an {@link EntityPathBase} with the same type of this interface
 */
default EntityPathBase<T> getQType() {
    throw new RuntimeException("getQType not implemented for query");
}
 
Example #11
Source File: BookRepository.java    From library with Apache License 2.0 2 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @return
 */
@Override
default EntityPathBase<Book> getQType() {
    return QBook.book;
}
 
Example #12
Source File: AuthorRepository.java    From library with Apache License 2.0 2 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @return
 */
@Override
default EntityPathBase<Author> getQType() {
    return QAuthor.author;
}