Search in sources :

Example 1 with JPAQueryFactory

use of com.querydsl.jpa.impl.JPAQueryFactory in project jeeshop by remibantos.

the class CatalogItemFinder method findBySearchCriteria.

public <T extends CatalogItem> List<T> findBySearchCriteria(EntityPath<T> entityPath, String searchCriteria, Integer offset, Integer limit, String orderBy, Boolean isDesc) {
    QCatalogItem qCatalogItem = new QCatalogItem(entityPath);
    JPAQuery<T> query = new JPAQueryFactory(entityManager).selectFrom(entityPath).where(buildSearchPredicate(searchCriteria, qCatalogItem));
    addOffsetAndLimitToQuery(offset, limit, query, orderBy, isDesc, qCatalogItem);
    return query.fetch();
}
Also used : QCatalogItem(org.rembx.jeeshop.catalog.model.QCatalogItem) JPAQueryFactory(com.querydsl.jpa.impl.JPAQueryFactory)

Example 2 with JPAQueryFactory

use of com.querydsl.jpa.impl.JPAQueryFactory in project jeeshop by remibantos.

the class CatalogItemFinder method countBySearchCriteria.

public Long countBySearchCriteria(EntityPath<? extends CatalogItem> entityPath, String searchCriteria) {
    QCatalogItem qCatalogItem = new QCatalogItem(entityPath);
    JPAQuery query = new JPAQueryFactory(entityManager).selectFrom(qCatalogItem).where(buildSearchPredicate(searchCriteria, qCatalogItem));
    return query.fetchCount();
}
Also used : QCatalogItem(org.rembx.jeeshop.catalog.model.QCatalogItem) JPAQuery(com.querydsl.jpa.impl.JPAQuery) JPAQueryFactory(com.querydsl.jpa.impl.JPAQueryFactory)

Example 3 with JPAQueryFactory

use of com.querydsl.jpa.impl.JPAQueryFactory in project jeeshop by remibantos.

the class DiscountFinder method findEligibleOrderDiscounts.

/*
     * Returns all discounts eligible for end-user
     * @param applicableTo the applicable type of discount
     * @param locale the locale for results localization
     * @return the visible discounts: not disabled, with startDate and endDate respectively before and after now and without
     * voucher code, applicable to given number of orders
     */
public List<Discount> findEligibleOrderDiscounts(String locale, Long completedOrderNumbers) {
    Date now = new Date();
    List<Discount> results = new JPAQueryFactory(entityManager).selectFrom(discount).where(discount.disabled.isFalse(), discount.endDate.after(now).or(discount.endDate.isNull()), discount.startDate.before(now).or(discount.startDate.isNull()), discount.applicableTo.eq(ApplicableTo.ORDER), discount.triggerRule.ne(Discount.Trigger.ORDER_NUMBER).or(discount.triggerValue.eq(completedOrderNumbers.doubleValue() + 1)), discount.voucherCode.isNull()).fetch();
    results.forEach((discount) -> discount.setLocalizedPresentation(locale));
    return results;
}
Also used : Discount(org.rembx.jeeshop.catalog.model.Discount) JPAQueryFactory(com.querydsl.jpa.impl.JPAQueryFactory) Date(java.util.Date)

Example 4 with JPAQueryFactory

use of com.querydsl.jpa.impl.JPAQueryFactory in project jeeshop by remibantos.

the class DiscountFinder method findVisibleDiscounts.

/*
     * Returns all discounts visible to end user
     * @param applicableTo the applicable type of discount
     * @param locale the locale for results localization
     * @return the visible discounts: not disabled, with startDate and endDate respectively before and after now and without
     * voucher code
     */
public List<Discount> findVisibleDiscounts(ApplicableTo applicableTo, String locale) {
    Date now = new Date();
    List<Discount> results = new JPAQueryFactory(entityManager).selectFrom(discount).where(discount.disabled.isFalse(), discount.endDate.after(now).or(discount.endDate.isNull()), discount.startDate.before(now).or(discount.startDate.isNull()), discount.applicableTo.eq(applicableTo), discount.voucherCode.isNull()).fetch();
    results.forEach((discount) -> discount.setLocalizedPresentation(locale));
    return results;
}
Also used : Discount(org.rembx.jeeshop.catalog.model.Discount) JPAQueryFactory(com.querydsl.jpa.impl.JPAQueryFactory) Date(java.util.Date)

Example 5 with JPAQueryFactory

use of com.querydsl.jpa.impl.JPAQueryFactory in project jeeshop by remibantos.

the class UserFinder method findAll.

public List<User> findAll(Integer offset, Integer limit, String orderBy, Boolean isDesc) {
    JPAQuery<User> query = new JPAQueryFactory(entityManager).selectFrom(user);
    if (offset != null)
        query.offset(offset);
    if (limit != null)
        query.limit(limit);
    sortBy(orderBy, isDesc, query);
    return query.fetch();
}
Also used : User(org.rembx.jeeshop.user.model.User) JPAQueryFactory(com.querydsl.jpa.impl.JPAQueryFactory)

Aggregations

JPAQueryFactory (com.querydsl.jpa.impl.JPAQueryFactory)11 QCatalogItem (org.rembx.jeeshop.catalog.model.QCatalogItem)5 Date (java.util.Date)3 JPAQuery (com.querydsl.jpa.impl.JPAQuery)2 Discount (org.rembx.jeeshop.catalog.model.Discount)2 EntityManager (javax.persistence.EntityManager)1 EntityManagerFactory (javax.persistence.EntityManagerFactory)1 Before (org.junit.Before)1 MailTemplate (org.rembx.jeeshop.user.model.MailTemplate)1 User (org.rembx.jeeshop.user.model.User)1