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);
}
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;
}
});
}
}
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();
}
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();
}
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();
}
Aggregations