public class LectureRepositoryImpl implements LectureRepositoryCustom {
private final JPAQueryFactory queryFactory;
public LectureRepositoryImpl(EntityManager em) {
this.queryFactory = new JPAQueryFactory(em);
}
@Override
public List<Lecture> findAllPageSort(Pageable pageable) {
JPAQuery<Lecture> query = queryFactory
.selectFrom(lecture)
.offset(pageable.getOffset())
.limit(pageable.getPageSize());
for (Sort.Order o : pageable.getSort()) {
PathBuilder pathBuilder = new PathBuilder(lecture.getType(), lecture.getMetadata());
query.orderBy(new OrderSpecifier(o.isAscending() ? Order.ASC : Order.DESC,
pathBuilder.get(o.getProperty())));
}
List<Lecture> result = query.fetch();
return result;
}
}