本文整理汇总了Java中org.springframework.data.jpa.domain.Specifications.where方法的典型用法代码示例。如果您正苦于以下问题:Java Specifications.where方法的具体用法?Java Specifications.where怎么用?Java Specifications.where使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.data.jpa.domain.Specifications
的用法示例。
在下文中一共展示了Specifications.where方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getHousingUnits
import org.springframework.data.jpa.domain.Specifications; //导入方法依赖的package包/类
public List<HousingInventory> getHousingUnits(UUID projectId,boolean isFamily,Integer members){
Object[] capacity = new Integer[]{members,members-1};
Specification<HousingInventory> spec = Specifications.where(new Specification<HousingInventory>() {
@Override
public Predicate toPredicate(Root<HousingInventory> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
return criteriaBuilder.and(criteriaBuilder.equal(root.get("projectId"),projectId),
criteriaBuilder.equal(root.get("familyUnit"), isFamily),
criteriaBuilder.upper(root.get("bedsCapacity")).in(capacity));
}
});
return serviceFactory.getRepositoryFactory().getHousingUnitsRepository().findAll(spec);
}
示例2: getScoreStatus
import org.springframework.data.jpa.domain.Specifications; //导入方法依赖的package包/类
public BatchProcessModel getScoreStatus(String projectGroup){
Specification<BatchProcessEntity> specification = Specifications.where(new Specification<BatchProcessEntity>() {
@Override
public Predicate toPredicate(Root<BatchProcessEntity> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
return criteriaBuilder.and(
criteriaBuilder.equal(root.get("projectGroupCode"),projectGroup),
criteriaBuilder.equal(root.get("processType"),Constants.SCORES_PROCESS_BATCH)
);
}
});
Sort sort = new Sort(Direction.DESC,"dateUpdated");
List<BatchProcessEntity> entities = repositoryFactory.getBatchProcessRepository().findAll(specification,sort);
if(!entities.isEmpty())
return batchProcessTranslator.translate(entities.get(0));
return null;
}
示例3: getScoreStatusHistory
import org.springframework.data.jpa.domain.Specifications; //导入方法依赖的package包/类
public Page<BatchProcessEntity> getScoreStatusHistory(String projectGroup,Pageable pageable){
Specification<BatchProcessEntity> specification = Specifications.where(new Specification<BatchProcessEntity>() {
@Override
public Predicate toPredicate(Root<BatchProcessEntity> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
return criteriaBuilder.and(
criteriaBuilder.equal(root.get("projectGroupCode"),projectGroup),
criteriaBuilder.equal(root.get("processType"),Constants.SCORES_PROCESS_BATCH)
);
}
});
Sort sort = new Sort(Direction.DESC,"dateUpdated");
PageRequest pageRequest = new PageRequest(pageable.getPageNumber(), pageable.getPageSize(),sort);
Page<BatchProcessEntity> entities = repositoryFactory.getBatchProcessRepository().findAll(specification,pageRequest);
return entities;
}
示例4: getEligibleClients
import org.springframework.data.jpa.domain.Specifications; //导入方法依赖的package包/类
public List<EligibleClient> getEligibleClients(Integer programType, String projectGroup,String spdatLabel) {
Specification<EligibleClient> specification = Specifications.where(new Specification<EligibleClient>() {
@Override
public Predicate toPredicate(Root<EligibleClient> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
return criteriaBuilder.and(
criteriaBuilder.equal(root.get("programType"),programType+""),
criteriaBuilder.equal(root.get("projectGroupCode"),projectGroup),
criteriaBuilder.equal(root.get("spdatLabel"),spdatLabel),
criteriaBuilder.equal(root.get("deleted"), false),
criteriaBuilder.equal(root.get("ignoreMatchProcess"),false),
criteriaBuilder.equal(root.get("matched"),false));
}
});
Sort sort = new Sort(Direction.ASC,"cocScore","surveyDate");
return repositoryFactory.getEligibleClientsRepository().findAll(specification,sort);
}
示例5: loadLiveWireContacts
import org.springframework.data.jpa.domain.Specifications; //导入方法依赖的package包/类
@Override
public List<LiveWireContactDTO> loadLiveWireContacts(String userUid) {
Objects.requireNonNull(userUid);
if (!dataSubscriberRepository.userUidsOfDataSubscriberUsers().contains(userUid)) {
throw new AccessDeniedException("Error! Querying user is not authorized");
}
Specifications<User> lwireContactSpecs = Specifications.where(UserSpecifications.isLiveWireContact());
Set<String> userUids = userRepository.findAll(lwireContactSpecs).stream()
.map(User::getUid)
.collect(Collectors.toSet());
if (expansiveContactFind) {
userUids.addAll(fetchOrganizerUidsOfLargePublicGroups());
}
return userRepository
.findAll(Specifications.where(UserSpecifications.uidIn(userUids)))
.stream()
.map(this::generateFromUser)
.sorted(Comparator.comparing(LiveWireContactDTO::getContactName))
.collect(Collectors.toList());
}
示例6: loadBillingRecords
import org.springframework.data.jpa.domain.Specifications; //导入方法依赖的package包/类
@Override
@Transactional(readOnly = true)
public List<AccountBillingRecord> loadBillingRecords(String accountUid, boolean unpaidOnly, Sort sort) {
Account account = accountRepository.findOneByUid(accountUid);
Specifications<AccountBillingRecord> specs;
if (!StringUtils.isEmpty(accountUid)) {
specs = Specifications.where(forAccount(account));
if (unpaidOnly) {
specs = specs.and(isPaid(false));
}
} else {
specs = unpaidOnly ? Specifications.where(isPaid(false)) : Specifications.where(paymentDateNotNull());
}
return billingRepository.findAll(specs, sort);
}
示例7: fetchTodosForUser
import org.springframework.data.jpa.domain.Specifications; //导入方法依赖的package包/类
@Override
@Transactional(readOnly = true)
public List<Todo> fetchTodosForUser(String userUid, boolean forceIncludeCreated, boolean limitToNeedingResponse, Instant intervalStart, Instant intervalEnd, Sort sort) {
Objects.requireNonNull(userUid);
User user = userRepository.findOneByUid(userUid);
Specifications<Todo> specs = limitToNeedingResponse ?
TodoSpecifications.todosForUserResponse(user) :
Specifications.where(TodoSpecifications.userPartOfParent(user));
if (forceIncludeCreated) {
specs = specs.or((root, query, cb) -> cb.equal(root.get(Todo_.createdByUser), user));
}
if (intervalStart != null) {
specs = specs.and((root, query, cb) -> cb.greaterThan(root.get(Todo_.actionByDate), intervalStart));
}
if (intervalEnd != null) {
specs = specs.and((root, query, cb) -> cb.lessThan(root.get(Todo_.actionByDate), intervalEnd));
}
specs = specs.and((root, query, cb) -> cb.isFalse(root.get(Todo_.cancelled)));
return sort == null ? todoRepository.findAll(specs) : todoRepository.findAll(specs, sort);
}
示例8: toPredicate
import org.springframework.data.jpa.domain.Specifications; //导入方法依赖的package包/类
@Override
public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
initializeFakes(root, query, cb);
Specifications<T> combinedSpecs = null;
for (Specification<T> spec : innerSpecs) {
if (spec instanceof Fake) {
continue;
}
if (combinedSpecs == null) {
combinedSpecs = Specifications.where(spec);
} else {
combinedSpecs = combinedSpecs.and(spec);
}
}
return combinedSpecs == null ? null : combinedSpecs.toPredicate(root, query, cb);
}
示例9: findPostsByStage
import org.springframework.data.jpa.domain.Specifications; //导入方法依赖的package包/类
public Page<Post> findPostsByStage(int stage, int page, String keyword) throws DataAccessException {
Specifications<Post> spec = null;
// Due to operator precedence, trailing "or" condition can cause true
// regardless of stage.
if (keyword != null && keyword.trim().length() > 0) {
spec = Specifications.where(PostSpecs.titleLike(keyword)).or(PostSpecs.bodyLike(keyword));
;
}
if (spec == null) {
spec = Specifications.where(PostSpecs.stageEqual(stage));
} else {
spec = spec.and(PostSpecs.stageEqual(stage));
}
Pageable pageable = new PageRequest(page - 1, PAGE_SIZE, Sort.Direction.DESC, "createdDate");
return this.postRepository.findAll(spec, pageable);
}
示例10: getSrvaEventsForActiveUser
import org.springframework.data.jpa.domain.Specifications; //导入方法依赖的package包/类
@Nonnull
protected List<SrvaEvent> getSrvaEventsForActiveUser(@Nullable Interval dateInterval) {
final Person person = activeUserService.requireActivePerson();
Specifications<SrvaEvent> specs = Specifications.where(SrvaSpecs.author(person));
if (dateInterval != null) {
specs = specs.and(SrvaSpecs.withinInterval(dateInterval));
}
return srvaEventRepository.findAll(specs,
new JpaSort(Sort.Direction.DESC, SrvaEvent_.pointOfTime, SrvaEvent_.id));
}
示例11: createSpec
import org.springframework.data.jpa.domain.Specifications; //导入方法依赖的package包/类
private static Specifications<HarvestPermit> createSpec(final HarvestPermitRhySearchDTO dto) {
if (StringUtils.isNotBlank(dto.getPermitNumber())) {
return Specifications.where(HarvestPermitSpecs.withPermitNumber(dto.getPermitNumber()))
.and(HarvestPermitSpecs.withRhyId(dto.getRhyId()));
}
Specifications<HarvestPermit> spec = Specifications.where(HarvestPermitSpecs.withRhyId(dto.getRhyId()));
if (dto.getSpeciesCode() != null) {
spec = spec.and(HarvestPermitSpecs.withSpeciesCode(dto.getSpeciesCode()));
}
if (StringUtils.isNotBlank(dto.getYear())) {
spec = spec.and(HarvestPermitSpecs.withYear(dto.getYear()));
}
return spec;
}
示例12: specificationWithProjection
import org.springframework.data.jpa.domain.Specifications; //导入方法依赖的package包/类
@Test
public void specificationWithProjection() {
Specifications<Document> where = Specifications.where(DocumentSpecs.idEq(1L));
Page<DocumentRepository.DocumentWithoutParent> all = documentRepository.findAll(where, DocumentRepository.DocumentWithoutParent.class, null);
Assertions.assertThat(all).isNotEmpty();
System.out.println(all.getContent());
Assertions.assertThat(all.getContent().get(0).getDocumentType()).isEqualTo("ต้นฉบับ");
}
开发者ID:pramoth,项目名称:specification-with-projection,代码行数:9,代码来源:SpecificationExecutorProjectionTests.java
示例13: buildRangeSpecification
import org.springframework.data.jpa.domain.Specifications; //导入方法依赖的package包/类
/**
* Helper function to return a specification for filtering on a single {@link Comparable}, where equality, less
* than, greater than and less-than-or-equal-to and greater-than-or-equal-to and null/non-null conditions are
* supported.
*
* @param filter the individual attribute filter coming from the frontend.
* @param field the JPA static metamodel representing the field.
* @param <X> The type of the attribute which is filtered.
* @return a Specification
*/
protected <X extends Comparable<? super X>> Specification<ENTITY> buildRangeSpecification(RangeFilter<X> filter,
SingularAttribute<? super ENTITY, X> field) {
if (filter.getEquals() != null) {
return equalsSpecification(field, filter.getEquals());
} else if (filter.getIn() != null) {
return valueIn(field, filter.getIn());
}
Specifications<ENTITY> result = Specifications.where(null);
if (filter.getSpecified() != null) {
result = result.and(byFieldSpecified(field, filter.getSpecified()));
}
if (filter.getGreaterThan() != null) {
result = result.and(greaterThan(field, filter.getGreaterThan()));
}
if (filter.getGreaterOrEqualThan() != null) {
result = result.and(greaterThanOrEqualTo(field, filter.getGreaterOrEqualThan()));
}
if (filter.getLessThan() != null) {
result = result.and(lessThan(field, filter.getLessThan()));
}
if (filter.getLessOrEqualThan() != null) {
result = result.and(lessThanOrEqualTo(field, filter.getLessOrEqualThan()));
}
return result;
}
示例14: combineWithAnd
import org.springframework.data.jpa.domain.Specifications; //导入方法依赖的package包/类
/**
* Combine all given specification with and. The first specification is the
* where clause.
*
* @param specList
* all specification which will combine
* @return <null> if the given specification list is empty
*/
public static <T> Specifications<T> combineWithAnd(final List<Specification<T>> specList) {
if (specList.isEmpty()) {
return null;
}
Specifications<T> specs = Specifications.where(specList.get(0));
for (final Specification<T> specification : specList.subList(1, specList.size())) {
specs = specs.and(specification);
}
return specs;
}
示例15: createSpecification
import org.springframework.data.jpa.domain.Specifications; //导入方法依赖的package包/类
public Specification<T> createSpecification(Iterable<QueryCriteria> queryCriterias){
Specifications<T> specifications = null;
for (QueryCriteria queryCriteria: queryCriterias){
if (queryCriteria != null){
Specification<T> specification = new QueryCriteriaSpecification<>(queryCriteria);
if (specifications == null){
specifications = Specifications.where(specification);
} else {
specifications = specifications.and(specification);
}
}
}
return specifications;
}