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();
}
use of com.querydsl.jpa.impl.JPAQuery in project kylo by Teradata.
the class JpaBatchJobExecutionProvider method getJobStatusCountByDateFromNow.
/**
* gets job executions grouped by status and Day looking back from Now - the supplied {@code period}
*
* @param period period to look back from the current time to get job execution status
*/
@Override
public List<JobStatusCount> getJobStatusCountByDateFromNow(ReadablePeriod period, String filter) {
QJpaBatchJobExecution jobExecution = QJpaBatchJobExecution.jpaBatchJobExecution;
QJpaBatchJobInstance jobInstance = QJpaBatchJobInstance.jpaBatchJobInstance;
QJpaOpsManagerFeed feed = QJpaOpsManagerFeed.jpaOpsManagerFeed;
BooleanBuilder whereBuilder = new BooleanBuilder();
whereBuilder.and(jobExecution.startTime.goe(DateTimeUtil.getNowUTCTime().minus(period)));
if (StringUtils.isNotBlank(filter)) {
whereBuilder.and(GenericQueryDslFilter.buildFilter(jobExecution, filter));
}
JPAQuery query = factory.select(Projections.constructor(JpaBatchJobExecutionStatusCounts.class, JobStatusDslQueryExpressionBuilder.jobState().as("status"), jobExecution.startYear, jobExecution.startMonth, jobExecution.startDay, jobExecution.count().as("count"))).from(jobExecution).innerJoin(jobInstance).on(jobExecution.jobInstance.jobInstanceId.eq(jobInstance.jobInstanceId)).innerJoin(feed).on(jobInstance.feed.id.eq(feed.id)).where(whereBuilder.and(FeedAclIndexQueryAugmentor.generateExistsExpression(feed.id, controller.isEntityAccessControlled()))).groupBy(jobExecution.status, jobExecution.startYear, jobExecution.startMonth, jobExecution.startDay);
return (List<JobStatusCount>) query.fetch();
}
Aggregations