Java Code Examples for com.querydsl.jpa.impl.JPAQuery#orderBy()

The following examples show how to use com.querydsl.jpa.impl.JPAQuery#orderBy() . 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: AdminAccessLogService.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
public Page<AdminAccessLog> page(List<BooleanExpression> predicates, PageModel pageModel){
    JPAQuery<AdminAccessLog>  query = queryFactory.select(
            Projections.fields(AdminAccessLog.class,
                    QAdminAccessLog.adminAccessLog.id.as("id"),
                    QAdminAccessLog.adminAccessLog.accessIp.as("accessIp"),
                    QAdminAccessLog.adminAccessLog.accessMethod.as("accessMethod"),
                    QAdminAccessLog.adminAccessLog.accessTime.as("accessTime"),
                    QAdminAccessLog.adminAccessLog.adminId.as("adminId"),
                    QAdminAccessLog.adminAccessLog.uri.as("uri"),
                    QAdminAccessLog.adminAccessLog.module.as("module"),
                    QAdminAccessLog.adminAccessLog.operation.as("operation"),
                    QAdmin.admin.username.as("adminName"))
    ).from(QAdminAccessLog.adminAccessLog,QAdmin.admin).where(predicates.toArray(new BooleanExpression[predicates.size()])) ;
    List<OrderSpecifier> orderSpecifiers = pageModel.getOrderSpecifiers() ;
    query.orderBy(orderSpecifiers.toArray(new OrderSpecifier[orderSpecifiers.size()]));
    long total = query.fetchCount() ;
    query.offset(pageModel.getPageSize()*(pageModel.getPageNo()-1)).limit(pageModel.getPageSize());
    List<AdminAccessLog> list = query.fetch() ;
    return new PageImpl<AdminAccessLog>(list,pageModel.getPageable(),total);
}
 
Example 2
Source File: MemberApplicationService.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
/**
 * 条件查询对象 pageNo pageSize 同时传时分页
 *
 * @param predicateList
 * @param pageNo
 * @param pageSize
 * @return
 */
@Transactional(readOnly = true)
public PageResult<MemberApplication> query(List<Predicate> predicateList, Integer pageNo, Integer pageSize) {
    List<MemberApplication> list;
    JPAQuery<MemberApplication> jpaQuery = queryFactory.selectFrom(memberApplication);
    if (predicateList != null) {
        jpaQuery.where(predicateList.toArray(new Predicate[predicateList.size()]));
    }
    jpaQuery.orderBy(memberApplication.createTime.desc());
    if (pageNo != null && pageSize != null) {
        list = jpaQuery.offset((pageNo - 1) * pageSize).limit(pageSize).fetch();
    } else {
        list = jpaQuery.fetch();
    }
    return new PageResult<>(list, jpaQuery.fetchCount());
}
 
Example 3
Source File: ExchangeOrderService.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
@Transactional(readOnly = true)
public PageResult<ExchangeOrder> queryWhereOrPage(List<Predicate> predicates, Integer pageNo, Integer pageSize) {
    List<ExchangeOrder> list;
    JPAQuery<ExchangeOrder> jpaQuery = queryFactory.selectFrom(QExchangeOrder.exchangeOrder);
    if (predicates != null) {
        jpaQuery.where(predicates.toArray(new BooleanExpression[predicates.size()]));
    }
    jpaQuery.orderBy(QExchangeOrder.exchangeOrder.time.desc());
    if (pageNo != null && pageSize != null) {
        list = jpaQuery.offset((pageNo - 1) * pageSize).limit(pageSize).fetch();
    } else {
        list = jpaQuery.fetch();
    }
    PageResult<ExchangeOrder> result = new PageResult<>(list, jpaQuery.fetchCount());
    result.setNumber(pageNo);
    result.setSize(pageSize);
    return result;
}
 
Example 4
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 5
Source File: ExchangeOrderService.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
@Transactional(readOnly = true)
public PageResult<ExchangeOrder> queryWhereOrPage(List<Predicate> predicates, Integer pageNo, Integer pageSize) {
    List<ExchangeOrder> list;
    JPAQuery<ExchangeOrder> jpaQuery = queryFactory.selectFrom(QExchangeOrder.exchangeOrder);
    if (predicates != null) {
        jpaQuery.where(predicates.toArray(new BooleanExpression[predicates.size()]));
    }
    jpaQuery.orderBy(QExchangeOrder.exchangeOrder.time.desc());
    if (pageNo != null && pageSize != null) {
        list = jpaQuery.offset((pageNo - 1) * pageSize).limit(pageSize).fetch();
    } else {
        list = jpaQuery.fetch();
    }
    PageResult<ExchangeOrder> result = new PageResult<>(list, jpaQuery.fetchCount());
    result.setNumber(pageNo);
    result.setSize(pageSize);
    return result;
}
 
Example 6
Source File: MemberService.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
/**
 * 条件查询对象 pageNo pageSize 同时传时分页
 *
 * @param booleanExpressionList
 * @param pageNo
 * @param pageSize
 * @return
 */
@Transactional(readOnly = true)
public PageResult<Member> queryWhereOrPage(List<BooleanExpression> booleanExpressionList, Integer pageNo, Integer pageSize) {
    List<Member> list;
    JPAQuery<Member> jpaQuery = queryFactory.selectFrom(QMember.member)
            .where(booleanExpressionList.toArray(new BooleanExpression[booleanExpressionList.size()]));
    jpaQuery.orderBy(QMember.member.id.desc());
    if (pageNo != null && pageSize != null) {
        list = jpaQuery.offset((pageNo - 1) * pageSize).limit(pageSize).fetch();
    } else {
        list = jpaQuery.fetch();
    }
    return new PageResult<>(list, jpaQuery.fetchCount());
}
 
Example 7
Source File: SysHelpService.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
/**
 * 条件查询对象 pageNo pageSize 同时传时分页
 *
 * @param booleanExpressionList
 * @param pageNo
 * @param pageSize
 * @return
 */
@Transactional(readOnly = true)
public PageResult<SysHelp> queryWhereOrPage(List<BooleanExpression> booleanExpressionList, Integer pageNo, Integer pageSize) {
    JPAQuery<SysHelp> jpaQuery = queryFactory.selectFrom(QSysHelp.sysHelp);
    if (booleanExpressionList != null) {
        jpaQuery.where(booleanExpressionList.toArray(new BooleanExpression[booleanExpressionList.size()]));
    }
    jpaQuery.orderBy(QSysHelp.sysHelp.createTime.desc());
    List<SysHelp> list = jpaQuery.offset((pageNo - 1) * pageSize).limit(pageSize).fetch();
    long count = jpaQuery.fetchCount();
    PageResult<SysHelp> page = new PageResult<>(list, pageNo, pageSize, count);
    return page;
}
 
Example 8
Source File: OrderService.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
public Page<OtcOrderVO> outExcel(List<Predicate> predicates , PageModel pageModel){
    List<OrderSpecifier> orderSpecifiers = pageModel.getOrderSpecifiers();
    JPAQuery<OtcOrderVO> query = queryFactory.select(
            Projections.fields(OtcOrderVO.class,
                    QOrder.order.id.as("id"),
                    QOrder.order.orderSn.as("orderSn"),
                    QOrder.order.advertiseType.as("advertiseType"),
                    QOrder.order.createTime.as("createTime"),
                    QOrder.order.memberName.as("memberName"),
                    QOrder.order.customerName.as("customerName"),
                    QOrder.order.coin.unit,
                    QOrder.order.money,
                    QOrder.order.number,
                    QOrder.order.commission.as("fee"),
                    QOrder.order.payMode.as("payMode"),
                    QOrder.order.releaseTime.as("releaseTime"),
                    QOrder.order.cancelTime.as("cancelTime"),
                    QOrder.order.payTime.as("payTime"),
                    QOrder.order.status.as("status"))
    ).from(QOrder.order).where(predicates.toArray(new BooleanExpression[predicates.size()]));
    query.orderBy(orderSpecifiers.toArray(new OrderSpecifier[orderSpecifiers.size()]));
    List<OtcOrderVO> list = query.offset((pageModel.getPageNo()-1)*pageModel.getPageSize()).limit(pageModel.getPageSize()).fetch();
    long total = query.fetchCount() ;
    return new PageImpl<>(list,pageModel.getPageable(),total);
}
 
Example 9
Source File: WithdrawRecordService.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
public Page<WithdrawRecordVO> joinFind(List<Predicate> predicates, PageModel pageModel) {
    List<OrderSpecifier> orderSpecifiers = pageModel.getOrderSpecifiers();
    JPAQuery<WithdrawRecordVO> query = queryFactory.select(
            Projections.fields(WithdrawRecordVO.class,
                    QWithdrawRecord.withdrawRecord.id.as("id"),
                    QWithdrawRecord.withdrawRecord.memberId.as("memberId"),
                    QWithdrawRecord.withdrawRecord.coin.unit,
                    QMember.member.username.as("memberUsername"),
                    QMember.member.realName.as("memberRealName"),
                    QMember.member.mobilePhone.as("phone"),
                    QMember.member.email,
                    QWithdrawRecord.withdrawRecord.dealTime.as("dealTime"),
                    QWithdrawRecord.withdrawRecord.totalAmount.as("totalAmount"),
                    QWithdrawRecord.withdrawRecord.arrivedAmount.as("arrivedAmount"),
                    QWithdrawRecord.withdrawRecord.status,
                    QWithdrawRecord.withdrawRecord.isAuto.as("isAuto"),
                    QWithdrawRecord.withdrawRecord.address,
                    QWithdrawRecord.withdrawRecord.createTime.as("createTime"),
                    QWithdrawRecord.withdrawRecord.fee,
                    QWithdrawRecord.withdrawRecord.transactionNumber.as("transactionNumber"),
                    QWithdrawRecord.withdrawRecord.remark)
    ).from(QWithdrawRecord.withdrawRecord, QMember.member).where(predicates.toArray(new BooleanExpression[predicates.size()]));
    query.orderBy(orderSpecifiers.toArray(new OrderSpecifier[orderSpecifiers.size()]));
    List<WithdrawRecordVO> list = query.offset((pageModel.getPageNo() - 1) * pageModel.getPageSize()).limit(pageModel.getPageSize()).fetch();
    long total = query.fetchCount();
    return new PageImpl<>(list, pageModel.getPageable(), total);

}
 
Example 10
Source File: MailTemplateFinder.java    From jeeshop with Apache License 2.0 5 votes vote down vote up
private void sortBy(String orderby, Boolean isDesc, JPAQuery<MailTemplate> query) {
    if (orderby != null && sortProperties.containsKey(orderby)) {
        if (isDesc) {
            query.orderBy(sortProperties.get(orderby).desc());
        } else {
            query.orderBy(sortProperties.get(orderby).asc());
        }
    }
}
 
Example 11
Source File: OrderFinder.java    From jeeshop with Apache License 2.0 5 votes vote down vote up
private void sortBy(String orderby, Boolean isDesc, JPAQuery<Order> query) {
    if (orderby != null && sortProperties.containsKey(orderby)) {
        if (isDesc) {
            query.orderBy(sortProperties.get(orderby).desc());
        } else {
            query.orderBy(sortProperties.get(orderby).asc());
        }
    }
}
 
Example 12
Source File: SysHelpService.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
/**
 * 条件查询对象 pageNo pageSize 同时传时分页
 *
 * @param booleanExpressionList
 * @param pageNo
 * @param pageSize
 * @return
 */
@Transactional(readOnly = true)
public PageResult<SysHelp> queryWhereOrPage(List<BooleanExpression> booleanExpressionList, Integer pageNo, Integer pageSize) {
    JPAQuery<SysHelp> jpaQuery = queryFactory.selectFrom(QSysHelp.sysHelp);
    if (booleanExpressionList != null) {
        jpaQuery.where(booleanExpressionList.toArray(new BooleanExpression[booleanExpressionList.size()]));
    }
    jpaQuery.orderBy(QSysHelp.sysHelp.createTime.desc());
    List<SysHelp> list = jpaQuery.offset((pageNo - 1) * pageSize).limit(pageSize).fetch();
    long count = jpaQuery.fetchCount();
    PageResult<SysHelp> page = new PageResult<>(list, pageNo, pageSize, count);
    return page;
}
 
Example 13
Source File: MemberService.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
/**
 * 条件查询对象 pageNo pageSize 同时传时分页
 *
 * @param booleanExpressionList
 * @param pageNo
 * @param pageSize
 * @return
 */
@Transactional(readOnly = true)
public PageResult<Member> queryWhereOrPage(List<BooleanExpression> booleanExpressionList, Integer pageNo, Integer pageSize) {
    List<Member> list;
    JPAQuery<Member> jpaQuery = queryFactory.selectFrom(QMember.member)
            .where(booleanExpressionList.toArray(new BooleanExpression[booleanExpressionList.size()]));
    jpaQuery.orderBy(QMember.member.id.desc());
    if (pageNo != null && pageSize != null) {
        list = jpaQuery.offset((pageNo - 1) * pageSize).limit(pageSize).fetch();
    } else {
        list = jpaQuery.fetch();
    }
    return new PageResult<>(list, jpaQuery.fetchCount());
}
 
Example 14
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 15
Source File: AdminAccessLogService.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
public Page<AdminAccessLog> page(List<BooleanExpression> predicates, PageModel pageModel){
    JPAQuery<AdminAccessLog>  query = queryFactory.select(
            Projections.fields(AdminAccessLog.class,
                    QAdminAccessLog.adminAccessLog.id.as("id"),
                    QAdminAccessLog.adminAccessLog.accessIp.as("accessIp"),
                    QAdminAccessLog.adminAccessLog.accessMethod.as("accessMethod"),
                    QAdminAccessLog.adminAccessLog.accessTime.as("accessTime"),
                    QAdminAccessLog.adminAccessLog.adminId.as("adminId"),
                    QAdminAccessLog.adminAccessLog.uri.as("uri"),
                    QAdminAccessLog.adminAccessLog.module.as("module"),
                    QAdminAccessLog.adminAccessLog.operation.as("operation"),
                    QAdmin.admin.username.as("adminName"))
    ).from(QAdminAccessLog.adminAccessLog,QAdmin.admin).where(predicates.toArray(new BooleanExpression[predicates.size()])) ;
    List<OrderSpecifier> orderSpecifiers = pageModel.getOrderSpecifiers() ;
    query.orderBy(orderSpecifiers.toArray(new OrderSpecifier[orderSpecifiers.size()]));
    long total = query.fetchCount() ;
    query.offset(pageModel.getPageSize()*(pageModel.getPageNo()-1)).limit(pageModel.getPageSize());
    List<AdminAccessLog> list = query.fetch() ;
    return new PageImpl<AdminAccessLog>(list,pageModel.getPageable(),total);
}
 
Example 16
Source File: MemberDepositService.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
public Page<MemberDepositVO> page(List<BooleanExpression> predicates,PageModel pageModel){
    JPAQuery<MemberDepositVO> query = queryFactory.select(Projections.fields(MemberDepositVO.class,
            QMemberDeposit.memberDeposit.id.as("id"),
            QMember.member.username,
            QMember.member.id.as("memberId"),
            QMemberDeposit.memberDeposit.address,
            QMemberDeposit.memberDeposit.amount,
            QMemberDeposit.memberDeposit.createTime.as("createTime"),
            QMemberDeposit.memberDeposit.unit)).from(QMember.member,QMemberDeposit.memberDeposit)
            .where(predicates.toArray(new BooleanExpression[predicates.size()]));
    List<OrderSpecifier> orderSpecifiers = pageModel.getOrderSpecifiers();
    query.orderBy(orderSpecifiers.toArray(new OrderSpecifier[orderSpecifiers.size()])) ;
    long total = query.fetchCount() ;
    query.offset(pageModel.getPageSize()*(pageModel.getPageNo()-1)).limit(pageModel.getPageSize());
    List<MemberDepositVO> list = query.fetch() ;
    return new PageImpl<MemberDepositVO>(list,pageModel.getPageable(),total);
}
 
Example 17
Source File: MemberTransactionService.java    From ZTuoExchange_framework with MIT License 5 votes vote down vote up
public Page<MemberTransactionVO> joinFind(List<Predicate> predicates, PageModel pageModel){
    List<OrderSpecifier> orderSpecifiers = pageModel.getOrderSpecifiers() ;
    JPAQuery<MemberTransactionVO> query = queryFactory.select(Projections.fields(MemberTransactionVO.class,
            QMemberTransaction.memberTransaction.address,
            QMemberTransaction.memberTransaction.amount,
            QMemberTransaction.memberTransaction.createTime.as("createTime"),
            QMemberTransaction.memberTransaction.fee,
            QMemberTransaction.memberTransaction.flag,
            QMemberTransaction.memberTransaction.id.as("id"),
            QMemberTransaction.memberTransaction.symbol,
            QMemberTransaction.memberTransaction.type,
            QMember.member.username.as("memberUsername"),
            QMember.member.mobilePhone.as("phone"),
            QMember.member.email,
            QMember.member.realName.as("memberRealName"),
            QMember.member.id.as("memberId")))
            .from(QMemberTransaction.memberTransaction, QMember.member);
    predicates.add(QMemberTransaction.memberTransaction.memberId.eq(QMember.member.id));
            query.where(predicates.toArray(new BooleanExpression[predicates.size()]));
    query.orderBy(orderSpecifiers.toArray(new OrderSpecifier[orderSpecifiers.size()]));
    List<MemberTransactionVO> list = query.offset((pageModel.getPageNo()-1)*pageModel.getPageSize()).limit(pageModel.getPageSize()).fetch();
    long total = query.fetchCount();
    return new PageImpl<>(list, pageModel.getPageable(), total);
}
 
Example 18
Source File: QueueRepository.java    From jump-the-queue with Apache License 2.0 4 votes vote down vote up
/**
 * Add sorting to the given query on the given alias
 *
 * @param query to add sorting to
 * @param alias to retrieve columns from for sorting
 * @param sort  specification of sorting
 */
public default void addOrderBy(JPAQuery<QueueEntity> query, QueueEntity alias, Sort sort) {
	if (sort != null && sort.isSorted()) {
		Iterator<Order> it = sort.iterator();
		while (it.hasNext()) {
			Order next = it.next();
			switch (next.getProperty()) {
			case "name":
				if (next.isAscending()) {
					query.orderBy($(alias.getName()).asc());
				} else {
					query.orderBy($(alias.getName()).desc());
				}
				break;
			case "logo":
				if (next.isAscending()) {
					query.orderBy($(alias.getLogo()).asc());
				} else {
					query.orderBy($(alias.getLogo()).desc());
				}
				break;
			case "currentNumber":
				if (next.isAscending()) {
					query.orderBy($(alias.getCurrentNumber()).asc());
				} else {
					query.orderBy($(alias.getCurrentNumber()).desc());
				}
				break;
			case "attentionTime":
				if (next.isAscending()) {
					query.orderBy($(alias.getAttentionTime()).asc());
				} else {
					query.orderBy($(alias.getAttentionTime()).desc());
				}
				break;
			case "minAttentionTime":
				if (next.isAscending()) {
					query.orderBy($(alias.getMinAttentionTime()).asc());
				} else {
					query.orderBy($(alias.getMinAttentionTime()).desc());
				}
				break;
			case "active":
				if (next.isAscending()) {
					query.orderBy($(alias.getActive()).asc());
				} else {
					query.orderBy($(alias.getActive()).desc());
				}
				break;
			case "customers":
				if (next.isAscending()) {
					query.orderBy($(alias.getCustomers()).asc());
				} else {
					query.orderBy($(alias.getCustomers()).desc());
				}
				break;
			default:
				throw new IllegalArgumentException("Sorted by the unknown property '" + next.getProperty() + "'");
			}
		}
	}
}
 
Example 19
Source File: AccessCodeRepository.java    From jump-the-queue with Apache License 2.0 4 votes vote down vote up
/**
 * Add sorting to the given query on the given alias
 *
 * @param query to add sorting to
 * @param alias to retrieve columns from for sorting
 * @param sort  specification of sorting
 */
public default void addOrderBy(JPAQuery<AccessCodeEntity> query, AccessCodeEntity alias, Sort sort) {
	if (sort != null && sort.isSorted()) {
		Iterator<Order> it = sort.iterator();
		while (it.hasNext()) {
			Order next = it.next();
			switch (next.getProperty()) {
			case "ticketNumber":
				if (next.isAscending()) {
					query.orderBy($(alias.getTicketNumber()).asc());
				} else {
					query.orderBy($(alias.getTicketNumber()).desc());
				}
				break;
			case "creationTime":
				if (next.isAscending()) {
					query.orderBy($(alias.getCreationTime()).asc());
				} else {
					query.orderBy($(alias.getCreationTime()).desc());
				}
				break;
			case "startTime":
				if (next.isAscending()) {
					query.orderBy($(alias.getStartTime()).asc());
				} else {
					query.orderBy($(alias.getStartTime()).desc());
				}
				break;
			case "endTime":
				if (next.isAscending()) {
					query.orderBy($(alias.getEndTime()).asc());
				} else {
					query.orderBy($(alias.getEndTime()).desc());
				}
				break;
			case "visitor":
				if (next.isAscending()) {
					query.orderBy($(alias.getVisitor().getId()).asc());
				} else {
					query.orderBy($(alias.getVisitor().getId()).desc());
				}
				break;
			case "queue":
				if (next.isAscending()) {
					query.orderBy($(alias.getQueue().getId()).asc());
				} else {
					query.orderBy($(alias.getQueue().getId()).desc());
				}
				break;
			default:
				throw new IllegalArgumentException("Sorted by the unknown property '" + next.getProperty() + "'");
			}
		}
	}
}
 
Example 20
Source File: VisitorRepository.java    From jump-the-queue with Apache License 2.0 4 votes vote down vote up
/**
 * Add sorting to the given query on the given alias
 * 
 * @param query to add sorting to
 * @param alias to retrieve columns from for sorting
 * @param sort  specification of sorting
 */
public default void addOrderBy(JPAQuery<VisitorEntity> query, VisitorEntity alias, Sort sort) {
	if (sort != null && sort.isSorted()) {
		Iterator<Order> it = sort.iterator();
		while (it.hasNext()) {
			Order next = it.next();
			switch (next.getProperty()) {
			case "username":
				if (next.isAscending()) {
					query.orderBy($(alias.getUsername()).asc());
				} else {
					query.orderBy($(alias.getUsername()).desc());
				}
				break;
			case "name":
				if (next.isAscending()) {
					query.orderBy($(alias.getName()).asc());
				} else {
					query.orderBy($(alias.getName()).desc());
				}
				break;
			case "phoneNumber":
				if (next.isAscending()) {
					query.orderBy($(alias.getPhoneNumber()).asc());
				} else {
					query.orderBy($(alias.getPhoneNumber()).desc());
				}
				break;
			case "password":
				if (next.isAscending()) {
					query.orderBy($(alias.getPassword()).asc());
				} else {
					query.orderBy($(alias.getPassword()).desc());
				}
				break;
			case "acceptedCommercial":
				if (next.isAscending()) {
					query.orderBy($(alias.getAcceptedCommercial()).asc());
				} else {
					query.orderBy($(alias.getAcceptedCommercial()).desc());
				}
				break;
			case "acceptedTerms":
				if (next.isAscending()) {
					query.orderBy($(alias.getAcceptedTerms()).asc());
				} else {
					query.orderBy($(alias.getAcceptedTerms()).desc());
				}
				break;
			case "userType":
				if (next.isAscending()) {
					query.orderBy($(alias.getUserType()).asc());
				} else {
					query.orderBy($(alias.getUserType()).desc());
				}
				break;
			default:
				throw new IllegalArgumentException("Sorted by the unknown property '" + next.getProperty() + "'");
			}
		}
	}
}