Search in sources :

Example 6 with JPAQueryFactory

use of com.querydsl.jpa.impl.JPAQueryFactory in project tutorials by eugenp.

the class QueryDSLIntegrationTest method setUp.

@Before
public void setUp() {
    em = emf.createEntityManager();
    em.getTransaction().begin();
    queryFactory = new JPAQueryFactory(em);
}
Also used : JPAQueryFactory(com.querydsl.jpa.impl.JPAQueryFactory)

Example 7 with JPAQueryFactory

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

the class JPAQueryFactoryTest method setUp.

@Before
public void setUp() {
    factoryMock = EasyMock.createMock(EntityManagerFactory.class);
    mock = EasyMock.createMock(EntityManager.class);
    Supplier<EntityManager> provider = () -> mock;
    queryFactory = new JPAQueryFactory(JPQLTemplates.DEFAULT, provider);
    queryFactory2 = queryFactory;
    queryFactory3 = new JPAQueryFactory(provider);
}
Also used : EntityManager(javax.persistence.EntityManager) EntityManagerFactory(javax.persistence.EntityManagerFactory) JPAQueryFactory(com.querydsl.jpa.impl.JPAQueryFactory) Before(org.junit.Before)

Example 8 with JPAQueryFactory

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

the class CatalogItemFinder method countAll.

public Long countAll(EntityPath<? extends CatalogItem> entityPath) {
    QCatalogItem qCatalogItem = new QCatalogItem(entityPath);
    JPAQuery query = new JPAQueryFactory(entityManager).selectFrom(qCatalogItem);
    return query.fetchCount();
}
Also used : JPAQuery(com.querydsl.jpa.impl.JPAQuery) JPAQueryFactory(com.querydsl.jpa.impl.JPAQueryFactory)

Example 9 with JPAQueryFactory

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

the class CatalogItemFinder method findVisibleCatalogItems.

public <T extends CatalogItem> List<T> findVisibleCatalogItems(EntityPath<T> entityPath, List<T> items, String locale) {
    QCatalogItem qCatalogItem = new QCatalogItem(entityPath);
    Date now = new Date();
    List<T> results = new JPAQueryFactory(entityManager).selectFrom(entityPath).where(qCatalogItem.disabled.isFalse(), qCatalogItem.endDate.after(now).or(qCatalogItem.endDate.isNull()), qCatalogItem.startDate.before(now).or(qCatalogItem.startDate.isNull()), qCatalogItem.in(items)).fetch();
    results.forEach((catalogItem) -> {
        catalogItem.setLocalizedPresentation(locale);
        mapCatalogItemChildrenPresentation(catalogItem, locale);
    });
    return results;
}
Also used : JPAQueryFactory(com.querydsl.jpa.impl.JPAQueryFactory) Date(java.util.Date)

Example 10 with JPAQueryFactory

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

the class CatalogItemFinder method findAll.

public <T extends CatalogItem> List<T> findAll(EntityPath<T> entityPath, Integer offset, Integer limit, String orderBy, Boolean isDesc, String locale) {
    QCatalogItem qCatalogItem = new QCatalogItem(entityPath);
    JPAQuery<T> query = new JPAQueryFactory(entityManager).selectFrom(entityPath);
    addOffsetAndLimitToQuery(offset, limit, query, orderBy, isDesc, qCatalogItem);
    List<T> catalogItems = query.fetch();
    return locale != null ? catalogItems.stream().peek(c -> {
        c.setLocalizedPresentation(locale);
        mapCatalogItemChildrenPresentation(c, locale);
    }).collect(Collectors.toList()) : catalogItems;
}
Also used : JPAQueryFactory(com.querydsl.jpa.impl.JPAQueryFactory)

Aggregations

JPAQueryFactory (com.querydsl.jpa.impl.JPAQueryFactory)11 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 QCatalogItem (org.rembx.jeeshop.catalog.model.QCatalogItem)1 MailTemplate (org.rembx.jeeshop.user.model.MailTemplate)1 User (org.rembx.jeeshop.user.model.User)1