本文整理汇总了Java中com.querydsl.jpa.impl.JPAQuery类的典型用法代码示例。如果您正苦于以下问题:Java JPAQuery类的具体用法?Java JPAQuery怎么用?Java JPAQuery使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JPAQuery类属于com.querydsl.jpa.impl包,在下文中一共展示了JPAQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findAll
import com.querydsl.jpa.impl.JPAQuery; //导入依赖的package包/类
/**
* Returns a portion of all instances.
* Limit 0 for limitless.
*
* <p>
* Possibly less costly operation. Should be used especially if we know there is many instances or for
* debugging purposes.
* </p>
* @return {@link Collection} of instances
*/
public Collection<T> findAll(long offset, long limit) {
JPAQuery<T> query = query().select(qObject());
applyWhereExpression(query);
if (offset != 0) {
query.offset(offset);
}
if (limit != 0) {
query.limit(limit);
}
List<T> list = query.fetch();
detachAll();
return list;
}
示例2: findAllInList
import com.querydsl.jpa.impl.JPAQuery; //导入依赖的package包/类
/**
* Finds all the instances corresponding to the specified {@link List} of ids.
*
* <p>
* The returned {@link List} of instances is ordered according to the order of provided ids. If the instance
* with provided id is not found, it is skipped, therefore the size of returned {@link List} might be of
* different size that of the provided ids {@link List}.
* </p>
* @param ids Ordered {@link List} of ids
* @return ordered {@link List} of instances
*/
public List<T> findAllInList(List<String> ids) {
if (ids.isEmpty()) {
return emptyList();
}
StringPath idPath = propertyPath("id");
JPAQuery<T> query = query().select(qObject).where(idPath.in(ids));
applyWhereExpression(query);
List<T> list = query.fetch();
detachAll();
return sortByIdList(ids, list);
}
示例3: findClubOfficialCodesWithActiveContactPerson
import com.querydsl.jpa.impl.JPAQuery; //导入依赖的package包/类
private Map<String, Person> findClubOfficialCodesWithActiveContactPerson(final Collection<String> officialCodes) {
final QOccupation occupation = QOccupation.occupation;
final QOrganisation organisation = QOrganisation.organisation;
final BooleanExpression clubOfficialCodeMatches = organisation.officialCode.in(officialCodes);
final BooleanExpression isContactPerson = occupation.occupationType.eq(OccupationType.SEURAN_YHDYSHENKILO);
// NOTE: If multiple occupation exist with same callOrder -> selects contactPerson randomly
return new JPAQuery<>(entityManager)
.from(occupation)
.join(occupation.organisation, organisation)
.where(occupation.validAndNotDeleted()
.and(clubOfficialCodeMatches)
.and(isContactPerson))
.select(organisation.officialCode, occupation.person)
.orderBy(occupation.callOrder.asc().nullsLast())
.transform(GroupBy.groupBy(organisation.officialCode).as(occupation.person));
}
示例4: findHarvestsLinkedToHuntingDayAndPermitOfRhy
import com.querydsl.jpa.impl.JPAQuery; //导入依赖的package包/类
@Override
@Transactional(readOnly = true)
public List<Harvest> findHarvestsLinkedToHuntingDayAndPermitOfRhy(final Riistanhoitoyhdistys rhy,
final GameSpecies species,
final Interval interval) {
final QHarvest harvest = QHarvest.harvest;
final QGroupHuntingDay huntingDay = QGroupHuntingDay.groupHuntingDay;
final QHuntingClubGroup group = QHuntingClubGroup.huntingClubGroup;
final QHarvestPermit permit = QHarvestPermit.harvestPermit;
return new JPAQuery<>(entityManager)
.from(harvest)
.join(harvest.huntingDayOfGroup, huntingDay)
.join(huntingDay.group, group)
.join(group.harvestPermit, permit)
.select(harvest)
.where(permit.rhy.eq(rhy)
.and(harvest.species.eq(species))
.and(harvest.pointOfTime.between(
new Timestamp(interval.getStart().getMillis()),
new Timestamp(interval.getEnd().getMillis()))))
.fetch();
}
示例5: testQueryDsl
import com.querydsl.jpa.impl.JPAQuery; //导入依赖的package包/类
@Test
public void testQueryDsl() {
QRegularUser qru = QRegularUser.regularUser;
JPAQuery<RegularUser> query = new JPAQuery<>(em());
BooleanExpression searchPredicate = qru
.contactInformation.email.eq("[email protected]")
.and(qru.company.organisationName.startsWithIgnoreCase("aqua"));
List<RegularUser> res = query
.select(qru)
.from(qru)
.where(searchPredicate)
.fetch();
// Loop and process results - res
}
示例6: listDataUpgradeAutoPerfom
import com.querydsl.jpa.impl.JPAQuery; //导入依赖的package包/类
@Override
public List<String> listDataUpgradeAutoPerfom() {
List<Parameter> listParameter = new JPAQuery<>(getEntityManager())
.select(qParameter).distinct()
.from(qParameter)
.where(qParameter.name.like(DATA_UPGRADE_AUTOPERFOM_PREFIX + ".%." + DATA_UPGRADE_AUTOPERFOM_SUFFIX),
qParameter.stringValue.eq("true"),
qParameter.dateValue.isNotNull())
.orderBy(qParameter.dateValue.desc())
.fetch();
List<String> listUpgrades = Lists.transform(listParameter, new Function<Parameter, String>() {
@Override
public String apply(Parameter input) {
return input.getName();
}
});
return listUpgrades;
}
示例7: listNextCheckingBatch
import com.querydsl.jpa.impl.JPAQuery; //导入依赖的package包/类
@Override
public List<ExternalLinkWrapper> listNextCheckingBatch(int batchSize, int minDelayBetweenTwoChecks) {
JPQLQuery<ExternalLinkWrapper> query = new JPAQuery<>(getEntityManager());
// Query to list the next <batchsize> URLs
// Must be a separate query, not a subquery, since JPQL doesn't support limit in subqueries
List<String> nextUrlsToCheckSubquery = listNextCheckingBatchUrls(batchSize, minDelayBetweenTwoChecks);
if (nextUrlsToCheckSubquery.isEmpty()) {
return Lists.newArrayListWithCapacity(0);
}
// Query to list the matching linkwrappers (may be more than <batchsize>)
query.from(qExternalLinkWrapper)
.where(qExternalLinkWrapper.url.lower().in(nextUrlsToCheckSubquery))
// Only links without the following statuses are to be checked
.where(qExternalLinkWrapper.status.notIn(ExternalLinkStatus.INACTIVES))
.orderBy(qExternalLinkWrapper.id.asc());
return query.fetch();
}
示例8: listEntityUnsafe
import com.querydsl.jpa.impl.JPAQuery; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private <K extends Serializable & Comparable<K>, E extends GenericEntity<?, ?>>
List<E> listEntityUnsafe(Class<? extends E> clazz, Collection<?> ids) {
if (ids == null || ids.isEmpty()) {
return Lists.newArrayListWithCapacity(0);
}
PathBuilder<E> path = new PathBuilder<E>(clazz, clazz.getSimpleName());
QGenericEntity qGenericEntity = new QGenericEntity(path);
return new JPAQuery<E>(entityManager).select(path)
.from(path)
.where(qGenericEntity.id.in((Collection<? extends K>)ids))
.orderBy(qGenericEntity.id.asc())
.fetch();
}
示例9: queryByPredicate
import com.querydsl.jpa.impl.JPAQuery; //导入依赖的package包/类
protected <T> JPAQuery<T> queryByPredicate(EntityPath<T> entityPath, Predicate predicate, Long limit, Long offset) {
JPAQuery<T> query = new JPAQuery<>(getEntityManager());
query.select(entityPath)
.from(entityPath);
if (predicate != null) {
query.where(predicate);
}
if (offset != null) {
query.offset(offset);
}
if (limit != null) {
query.limit(limit);
}
return query;
}
示例10: list
import com.querydsl.jpa.impl.JPAQuery; //导入依赖的package包/类
@Override
public <E extends GE> List<E> list(Class<E> clazz, EnabledFilter enabledFilter, Comparator<? super E> comparator) {
PathBuilder<E> pathBuilder = new PathBuilder<E>(clazz, "rootAlias");
QGenericLocalizedGenericListItem entityPath = new QGenericLocalizedGenericListItem(pathBuilder);
JPAQuery<E> query;
if (EnabledFilter.ENABLED_ONLY.equals(enabledFilter)) {
query = queryByPredicate(pathBuilder, entityPath.enabled.isTrue());
} else {
query = queryByPredicate(pathBuilder, null);
}
List<E> entities = (List<E>) query.fetch();
Collections.sort(entities, comparator);
return entities;
}
示例11: queryByField
import com.querydsl.jpa.impl.JPAQuery; //导入依赖的package包/类
/**
* @deprecated Utiliser QueryDSL
*/
@Deprecated
private <E extends GE, V extends Comparable<?>> Pair<EntityPath<E>, JPAQuery<E>> queryByField(Class<E> clazz, SingularAttribute<? super E, V> field, V fieldValue,
EnabledFilter enabledFilter) {
PathBuilder<E> pathBuilder = new PathBuilder<E>(clazz, "entityAlias");
QGenericLocalizedGenericListItem entityPath = new QGenericLocalizedGenericListItem(pathBuilder);
JPAQuery<E> query;
if (field != null) {
query = queryEntityByField(pathBuilder, field.getBindableJavaType(), field.getName(), fieldValue);
} else {
query = queryByPredicate(pathBuilder, null);
}
if (EnabledFilter.ENABLED_ONLY.equals(enabledFilter)) {
// l'appel au where ajoute la condition aux conditions précédentes
query = query.where(entityPath.enabled.isTrue());
}
return Pair.with((EntityPath<E>) pathBuilder, query);
}
示例12: list
import com.querydsl.jpa.impl.JPAQuery; //导入依赖的package包/类
@Override
public <E extends GenericListItem<?>> List<E> list(Class<E> clazz, EnabledFilter enabledFilter, Comparator<? super E> comparator) {
PathBuilder<GenericListItem<?>> pathBuilder = new PathBuilder<GenericListItem<?>>(clazz, "rootAlias");
QGenericListItem entityPath = new QGenericListItem(pathBuilder);
JPAQuery<GenericListItem<?>> query;
if (EnabledFilter.ENABLED_ONLY.equals(enabledFilter)) {
query = queryByPredicate(entityPath, entityPath.enabled.isTrue());
} else {
query = queryByPredicate(entityPath, null);
}
@SuppressWarnings("unchecked")
List<E> entities = (List<E>) query.fetch();
Collections.sort(entities, comparator);
return entities;
}
示例13: queryByField
import com.querydsl.jpa.impl.JPAQuery; //导入依赖的package包/类
@Deprecated
private <E extends GenericListItem<?>, V extends Comparable<?>> Pair<EntityPath<E>, JPAQuery<E>> queryByField(Class<E> clazz, SingularAttribute<? super E, V> field, V fieldValue,
EnabledFilter enabledFilter) {
PathBuilder<E> pathBuilder = new PathBuilder<E>(clazz, "entityAlias");
QGenericListItem entityPath = new QGenericListItem(pathBuilder);
JPAQuery<E> query;
if (field != null) {
query = queryEntityByField(pathBuilder, field.getBindableJavaType(), field.getName(), fieldValue);
} else {
query = queryByPredicate(pathBuilder, null);
}
if (EnabledFilter.ENABLED_ONLY.equals(enabledFilter)) {
// l'appel au where ajoute la condition aux conditions précédentes
query = query.where(entityPath.enabled.isTrue());
}
return Pair.with((EntityPath<E>) pathBuilder, query);
}
示例14: listByContextOrObject
import com.querydsl.jpa.impl.JPAQuery; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public List<T> listByContextOrObject(GenericEntity<Long, ?> entity) {
PathBuilder<T> path = new PathBuilder<T>(getObjectClass(), "abstractAudit");
QAbstractAudit qAbstractAudit = new QAbstractAudit(path);
return new JPAQuery<T>(getEntityManager()).select((BeanPath<T>) qAbstractAudit).from(qAbstractAudit)
.where(
(
qAbstractAudit.contextClass.eq(Hibernate.getClass(entity).getName())
.and(qAbstractAudit.contextId.eq(entity.getId()))
).or(
qAbstractAudit.objectClass.eq(Hibernate.getClass(entity).getName())
.and(qAbstractAudit.objectId.eq(entity.getId()))
)
).orderBy(qAbstractAudit.date.desc()).fetch();
}
示例15: getNextTaskForExecution
import com.querydsl.jpa.impl.JPAQuery; //导入依赖的package包/类
@Override
public QueuedTaskHolder getNextTaskForExecution(String taskType) {
Date now = new Date();
QQueuedTaskHolder qQueuedTask = QQueuedTaskHolder.queuedTaskHolder;
JPQLQuery<QueuedTaskHolder> query = new JPAQuery<QueuedTaskHolder>(getEntityManager());
query.from(qQueuedTask)
.where(qQueuedTask.taskType.eq(taskType)
.and(qQueuedTask.startDate.isNull())
.and(qQueuedTask.triggeringDate.isNull()
.or(qQueuedTask.triggeringDate.before(now))))
.orderBy(qQueuedTask.version.asc(), qQueuedTask.creationDate.asc());
List<QueuedTaskHolder> tasksForExecution = query.fetch();
if (tasksForExecution.isEmpty()) {
return null;
} else {
return tasksForExecution.get(0);
}
}