Search in sources :

Example 6 with JPAQuery

use of com.querydsl.jpa.impl.JPAQuery in project kylo by Teradata.

the class DefaultAlertCriteria method createSummaryQuery.

public JPAQuery<AlertSummary> createSummaryQuery() {
    QJpaAlert alert = QJpaAlert.jpaAlert;
    JPAQuery query = queryFactory.select(Projections.bean(DefaultAlertSummary.class, alert.typeString.as("type"), alert.subtype.as("subtype"), alert.level.as("level"), alert.count().as("count"), alert.createdTimeMillis.max().as("lastAlertTimestamp"))).from(alert).groupBy(alert.typeString, alert.subtype, alert.level);
    List<Predicate> preds = filter(alert);
    BooleanBuilder orFilter = orFilter(alert);
    return (JPAQuery<AlertSummary>) addWhere(query, preds, orFilter);
}
Also used : QJpaAlert(com.thinkbiganalytics.metadata.jpa.alerts.QJpaAlert) BooleanBuilder(com.querydsl.core.BooleanBuilder) DefaultAlertSummary(com.thinkbiganalytics.metadata.jpa.alerts.DefaultAlertSummary) JPAQuery(com.querydsl.jpa.impl.JPAQuery) Predicate(com.querydsl.core.types.Predicate)

Example 7 with JPAQuery

use of com.querydsl.jpa.impl.JPAQuery in project crnk-framework by crnk-project.

the class DtoMappingTest method setupModule.

@Override
protected void setupModule(JpaModule module, boolean server) {
    super.setupModule(module, server);
    if (server) {
        EntityManager entityManager = module.getEntityManager();
        QuerydslExpressionFactory<QTestEntity> basicComputedValueFactory = new QuerydslExpressionFactory<QTestEntity>() {

            @Override
            public Expression<String> getExpression(QTestEntity parent, JPAQuery<?> jpaQuery) {
                return parent.stringValue.upper();
            }
        };
        QuerydslExpressionFactory<QTestEntity> complexComputedValueFactory = new QuerydslExpressionFactory<QTestEntity>() {

            @Override
            public Expression<Long> getExpression(QTestEntity parent, JPAQuery<?> jpaQuery) {
                QTestEntity root = QTestEntity.testEntity;
                QTestEntity sub = new QTestEntity("subquery");
                return JPAExpressions.select(sub.id.count()).from(sub).where(sub.id.lt(root.id));
            }
        };
        QuerydslQueryFactory queryFactory = (QuerydslQueryFactory) module.getQueryFactory();
        queryFactory.registerComputedAttribute(TestEntity.class, TestDTO.ATTR_COMPUTED_UPPER_STRING_VALUE, String.class, basicComputedValueFactory);
        queryFactory.registerComputedAttribute(TestEntity.class, TestDTO.ATTR_COMPUTED_NUMBER_OF_SMALLER_IDS, Long.class, complexComputedValueFactory);
        module.addRepository(JpaRepositoryConfig.builder(TestEntity.class, TestDTO.class, new TestDTOMapper(entityManager)).build());
        module.addRepository(JpaRepositoryConfig.builder(RelatedEntity.class, RelatedDTO.class, new RelatedDTOMapper(entityManager)).build());
        module.addFilter(new JpaRepositoryFilterBase() {

            @Override
            public <T> JpaQuery<T> filterQuery(Object repository, QuerySpec querySpec, JpaQuery<T> query) {
                query.setDistinct(true);
                return query;
            }
        });
    }
}
Also used : QuerydslQueryFactory(io.crnk.jpa.query.querydsl.QuerydslQueryFactory) JPAQuery(com.querydsl.jpa.impl.JPAQuery) JpaQuery(io.crnk.jpa.query.JpaQuery) QuerydslExpressionFactory(io.crnk.jpa.query.querydsl.QuerydslExpressionFactory) EntityManager(javax.persistence.EntityManager) QTestEntity(io.crnk.jpa.model.QTestEntity) JpaRepositoryFilterBase(io.crnk.jpa.JpaRepositoryFilterBase) QuerySpec(io.crnk.core.queryspec.QuerySpec)

Example 8 with JPAQuery

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

the class PersonDaoImpl method findPersonsByFirstnameAndSurnameQueryDSL.

@Override
public List<Person> findPersonsByFirstnameAndSurnameQueryDSL(final String firstname, final String surname) {
    final JPAQuery<Person> query = new JPAQuery<>(em);
    final QPerson person = QPerson.person;
    return query.from(person).where(person.firstname.eq(firstname).and(person.surname.eq(surname))).fetch();
}
Also used : QPerson(org.baeldung.entity.QPerson) Person(org.baeldung.entity.Person) QPerson(org.baeldung.entity.QPerson) JPAQuery(com.querydsl.jpa.impl.JPAQuery)

Example 9 with JPAQuery

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

the class PersonDaoImpl method findPersonsByFirstnameInDescendingOrderQueryDSL.

@Override
public List<Person> findPersonsByFirstnameInDescendingOrderQueryDSL(final String firstname) {
    final JPAQuery<Person> query = new JPAQuery<>(em);
    final QPerson person = QPerson.person;
    return query.from(person).where(person.firstname.eq(firstname)).orderBy(person.surname.desc()).fetch();
}
Also used : QPerson(org.baeldung.entity.QPerson) Person(org.baeldung.entity.Person) QPerson(org.baeldung.entity.QPerson) JPAQuery(com.querydsl.jpa.impl.JPAQuery)

Example 10 with JPAQuery

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

the class SerializationBase method test.

@Test
public void test() throws IOException, ClassNotFoundException {
    // create query
    JPAQuery<?> query = query();
    query.from(cat).where(cat.name.eq("Kate")).select(cat).fetch();
    QueryMetadata metadata = query.getMetadata();
    assertFalse(metadata.getJoins().isEmpty());
    assertTrue(metadata.getWhere() != null);
    assertTrue(metadata.getProjection() != null);
    QueryMetadata metadata2 = Serialization.serialize(metadata);
    // validate it
    assertEquals(metadata.getJoins(), metadata2.getJoins());
    assertEquals(metadata.getWhere(), metadata2.getWhere());
    assertEquals(metadata.getProjection(), metadata2.getProjection());
    // create new query
    JPAQuery<?> query2 = new JPAQuery<Void>(entityManager, metadata2);
    assertEquals("select cat\nfrom Cat cat\nwhere cat.name = ?1", query2.toString());
    query2.select(cat).fetch();
}
Also used : QueryMetadata(com.querydsl.core.QueryMetadata) JPAQuery(com.querydsl.jpa.impl.JPAQuery) Test(org.junit.Test)

Aggregations

JPAQuery (com.querydsl.jpa.impl.JPAQuery)24 QJpaOpsManagerFeed (com.thinkbiganalytics.metadata.jpa.feed.QJpaOpsManagerFeed)9 List (java.util.List)9 BooleanBuilder (com.querydsl.core.BooleanBuilder)7 ArrayList (java.util.ArrayList)6 Person (org.baeldung.entity.Person)5 QPerson (org.baeldung.entity.QPerson)5 Predicate (com.querydsl.core.types.Predicate)4 JPAQueryFactory (com.querydsl.jpa.impl.JPAQueryFactory)4 JPQLQuery (com.querydsl.jpa.JPQLQuery)3 Stopwatch (com.google.common.base.Stopwatch)2 ConstructorExpression (com.querydsl.core.types.ConstructorExpression)2 Expression (com.querydsl.core.types.Expression)2 Projections (com.querydsl.core.types.Projections)2 JPAExpressions (com.querydsl.jpa.JPAExpressions)2 DateTimeUtil (com.thinkbiganalytics.DateTimeUtil)2 Alert (com.thinkbiganalytics.alerts.api.Alert)2 AlertProvider (com.thinkbiganalytics.alerts.api.AlertProvider)2 AlertManager (com.thinkbiganalytics.alerts.spi.AlertManager)2 DefaultAlertChangeEventContent (com.thinkbiganalytics.alerts.spi.DefaultAlertChangeEventContent)2