本文整理汇总了Java中org.springframework.data.jpa.domain.Specifications.and方法的典型用法代码示例。如果您正苦于以下问题:Java Specifications.and方法的具体用法?Java Specifications.and怎么用?Java Specifications.and使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.data.jpa.domain.Specifications
的用法示例。
在下文中一共展示了Specifications.and方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getHarvestReportFieldses
import org.springframework.data.jpa.domain.Specifications; //导入方法依赖的package包/类
private List<HarvestReportFields> getHarvestReportFieldses(
@Nullable final LocalDate date, @Nullable final Integer gameSpeciesCode) {
final Specification<HarvestReportFields> withSpeciesCode = gameSpeciesCode == null
? JpaSpecs.conjunction()
: JpaSpecs.equal(HarvestReportFields_.species, GameSpecies_.officialCode, gameSpeciesCode);
Specifications<HarvestReportFields> spec =
where(JpaSpecs.equal(HarvestReportFields_.usedWithPermit, true))
.and(withSpeciesCode);
if (date != null) {
spec = spec.and(
JpaSpecs.withinInterval(HarvestReportFields_.beginDate, HarvestReportFields_.endDate, date));
}
return harvestReportFieldsRepository.findAll(spec);
}
示例2: 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);
}
示例3: loadAllAccounts
import org.springframework.data.jpa.domain.Specifications; //导入方法依赖的package包/类
@Override
@Transactional(readOnly = true)
public List<Account> loadAllAccounts(boolean visibleOnly, AccountPaymentType paymentMethod, AccountBillingCycle billingCycle) {
List<Account> accounts;
boolean noSpecifications = !visibleOnly && paymentMethod == null && billingCycle == null;
if (noSpecifications) {
accounts = accountRepository.findAll();
} else {
Specifications<Account> specifications = null;
if (visibleOnly) {
specifications = where(isVisible());
}
if (paymentMethod != null) {
specifications = (specifications == null) ? where(defaultPaymentType(paymentMethod)) :
specifications.and(defaultPaymentType(paymentMethod));
}
if (billingCycle != null) {
specifications = (specifications == null) ? where(billingCycle(billingCycle)) :
specifications.and(billingCycle(billingCycle));
}
accounts = accountRepository.findAll(specifications);
}
accounts.sort(Comparator.comparing(Account::getAccountName));
return accounts;
}
示例4: 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);
}
示例5: 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);
}
示例6: 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);
}
示例7: getSpecs
import org.springframework.data.jpa.domain.Specifications; //导入方法依赖的package包/类
private Specifications<SrvaEvent> getSpecs(final SrvaEventSearchDTO dto) {
final Riistanhoitoyhdistys currentRhy = requireEntityService.requireRiistanhoitoyhdistys(dto.getCurrentRhyId(),
RiistanhoitoyhdistysAuthorization.Permission.LIST_SRVA);
Specifications<SrvaEvent> specs = Specifications
.where(SrvaSpecs.anyOfEventNames(dto.getEventNames())).and(SrvaSpecs.equalRhy(currentRhy))
.or(getOtherRhySpecs(dto));
if (Objects.nonNull(dto.getRhyId())) {
final Riistanhoitoyhdistys rhy = riistanhoitoyhdistysRepository.findOne(dto.getRhyId());
specs = specs.and(SrvaSpecs.equalRhy(rhy));
} else if (Objects.nonNull(dto.getRkaId())) {
specs = specs.and(SrvaSpecs.equalRka(dto.getRkaId()));
}
if (Objects.nonNull(dto.getStates())) {
specs = specs.and(SrvaSpecs.anyOfStates(dto.getStates()));
}
if (Objects.nonNull(dto.getGameSpeciesCode())) {
// 0 stands for other species
if (dto.getGameSpeciesCode() == 0) {
specs = specs.and(SrvaSpecs.equalSpecies(null));
} else {
specs = specs.and(SrvaSpecs.equalSpecies(gameDiaryService.getGameSpeciesByOfficialCode(dto.getGameSpeciesCode())));
}
}
if (dto.hasBeginOrEndDate()) {
specs = specs.and(SrvaSpecs.withinInterval(dto.getBeginDate(), dto.getEndDate()));
}
return specs;
}
示例8: 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));
}
示例9: 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;
}
示例10: 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;
}
示例11: 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;
}
示例12: 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;
}
示例13: findNewlyChangedGroups
import org.springframework.data.jpa.domain.Specifications; //导入方法依赖的package包/类
@Timed
@Override
@Transactional(readOnly = true)
public Set<GroupTimeChangedDTO> findNewlyChangedGroups(String userUid, Map<String, Long> excludedGroupsByTimeChanged) {
User user = userRepository.findOneByUid(userUid);
// major todo: do all this through specifications instead of typed query, and consolidate to one query
Specifications<Group> specifications = Specifications
.where(GroupSpecifications.isActive())
.and(GroupSpecifications.userIsMember(user));
if (excludedGroupsByTimeChanged != null && !excludedGroupsByTimeChanged.isEmpty()) {
specifications = specifications.and(
Specifications.not(GroupSpecifications.uidIn(excludedGroupsByTimeChanged.keySet())));
}
Set<String> newGroupUids = groupRepository.findAll(specifications)
.stream()
.map(Group::getUid)
.collect(Collectors.toSet());
Set<String> uidsToLookUp = new HashSet<>(excludedGroupsByTimeChanged.keySet());
uidsToLookUp.addAll(newGroupUids);
TypedQuery<GroupTimeChangedDTO> changedGroupQuery = entityManager.createQuery("" +
"select new za.org.grassroot.core.dto.group.GroupTimeChangedDTO(g, g.lastGroupChangeTime) " +
"from Group g where g.uid in :groupUids", GroupTimeChangedDTO.class)
.setParameter("groupUids", uidsToLookUp);
return changedGroupQuery.getResultList()
.stream()
.filter(gl -> {
Instant storedLastChange = excludedGroupsByTimeChanged.containsKey(gl.getGroupUid()) ?
Instant.ofEpochMilli(excludedGroupsByTimeChanged.get(gl.getGroupUid())) : Instant.MIN;
return storedLastChange.isBefore(gl.getLastGroupChange()); // keep eye out for microsecond differences...
})
.collect(Collectors.toSet());
}
示例14: fetchTodosForGroup
import org.springframework.data.jpa.domain.Specifications; //导入方法依赖的package包/类
@Override
@Transactional(readOnly = true)
public List<Todo> fetchTodosForGroup(String userUid, String groupUid, boolean limitToNeedingResponse, boolean limitToIncomplete,
Instant start, Instant end, Sort sort) {
Objects.requireNonNull(userUid);
Objects.requireNonNull(groupUid);
User user = userRepository.findOneByUid(userUid);
Group group = uidIdentifiableRepository.findOneByUid(Group.class, JpaEntityType.GROUP, groupUid);
permissionBroker.validateGroupPermission(user, group, Permission.GROUP_PERMISSION_READ_UPCOMING_EVENTS);
Specifications<Todo> specs;
if (limitToNeedingResponse) {
specs = TodoSpecifications.todosForUserResponse(user).and(TodoSpecifications.hasGroupAsParent(group));
} else {
specs = Specifications.where(TodoSpecifications.hasGroupAsParent(group));
}
specs = specs.and((root, query, cb) -> cb.isFalse(root.get(Todo_.cancelled)));
if (limitToIncomplete) {
specs = specs.and((root, query, cb) -> cb.isFalse(root.get(Todo_.completed)));
}
if (start != null) {
specs = specs.and((root, query, cb) -> cb.greaterThan(root.get(Todo_.actionByDate), start));
}
if (end != null) {
specs = specs.and((root, query, cb) -> cb.lessThan(root.get(Todo_.actionByDate), end));
}
return sort != null ? todoRepository.findAll(specs, sort) : todoRepository.findAll(specs);
}
示例15: fetchAssignedUserResponses
import org.springframework.data.jpa.domain.Specifications; //导入方法依赖的package包/类
@Override
@Transactional(readOnly = true)
public List<TodoAssignment> fetchAssignedUserResponses(String userUid, String todoUid, boolean respondedOnly, boolean assignedOnly, boolean witnessOnly) {
Objects.requireNonNull(userUid);
Objects.requireNonNull(todoUid);
User user = userRepository.findOneByUid(userUid);
Todo todo = todoRepository.findOneByUid(todoUid);
if (!todo.getCreatedByUser().equals(user) || todoAssignmentRepository.count(TodoSpecifications.userAssignment(user, todo)) == 0) {
throw new AccessDeniedException("Error, only creating or assigned user can see todo details");
}
Specifications<TodoAssignment> specs = Specifications.where((root, query, cb) -> cb.equal(root.get(TodoAssignment_.todo), todo));
if (respondedOnly) {
specs = specs.and((root, query, cb) -> cb.isTrue(root.get(TodoAssignment_.hasResponded)));
}
if (assignedOnly) {
specs = specs.and((root, query, cb) -> cb.isTrue(root.get(TodoAssignment_.assignedAction)));
}
if (witnessOnly) {
specs = specs.and((root, query, cb) -> cb.isTrue(root.get(TodoAssignment_.validator)));
}
List<Sort.Order> orders = Arrays.asList(new Sort.Order("hasResponded"), new Sort.Order(Sort.Direction.DESC, "responseTime"));
return todoAssignmentRepository.findAll(specs, new Sort(orders));
}