com.querydsl.core.BooleanBuilder Java Examples
The following examples show how to use
com.querydsl.core.BooleanBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UserService.java From eds-starter6-jpa with Apache License 2.0 | 6 votes |
private boolean isLastAdmin(Long id) { JPAQuery<Integer> query = this.jpaQueryFactory.select(Expressions.ONE) .from(QUser.user); BooleanBuilder bb = new BooleanBuilder(); bb.or(QUser.user.authorities.eq(Authority.ADMIN.name())); bb.or(QUser.user.authorities.endsWith("," + Authority.ADMIN.name())); bb.or(QUser.user.authorities.contains("," + Authority.ADMIN.name() + ",")); bb.or(QUser.user.authorities.startsWith(Authority.ADMIN.name() + ",")); query.where(QUser.user.id.ne(id).and(QUser.user.deleted.isFalse()) .and(QUser.user.enabled.isTrue()).and(bb)); return query.fetchFirst() == null; }
Example #2
Source File: UserService.java From eds-starter6-jpa with Apache License 2.0 | 6 votes |
@ExtDirectMethod(STORE_READ) @Transactional(readOnly = true) public ExtDirectStoreResult<User> read(ExtDirectStoreReadRequest request) { JPQLQuery<User> query = this.jpaQueryFactory.selectFrom(QUser.user); if (!request.getFilters().isEmpty()) { StringFilter filter = (StringFilter) request.getFilters().iterator().next(); BooleanBuilder bb = new BooleanBuilder(); bb.or(QUser.user.loginName.containsIgnoreCase(filter.getValue())); bb.or(QUser.user.lastName.containsIgnoreCase(filter.getValue())); bb.or(QUser.user.firstName.containsIgnoreCase(filter.getValue())); bb.or(QUser.user.email.containsIgnoreCase(filter.getValue())); query.where(bb); } query.where(QUser.user.deleted.isFalse()); QuerydslUtil.addPagingAndSorting(query, request, User.class, QUser.user); QueryResults<User> searchResult = query.fetchResults(); return new ExtDirectStoreResult<>(searchResult.getTotal(), searchResult.getResults()); }
Example #3
Source File: QueryDslRepositorySupportExt.java From springlets with Apache License 2.0 | 6 votes |
/** * Adds a global contains text filter on the provided attributes. * WARNING: this creates a very inefficient query. If you have many entity * instances to query, use instead an indexed text search solution for better * performance. * @param text the text to look for * @param query * @param globalSearchAttributes the list of attributes to perform the * filter on * @return the updated query */ protected JPQLQuery<T> applyGlobalSearch(String text, JPQLQuery<T> query, Path<?>... globalSearchAttributes) { if (text != null && !StringUtils.isEmpty(text) && globalSearchAttributes.length > 0) { BooleanBuilder searchCondition = new BooleanBuilder(); for (int i = 0; i < globalSearchAttributes.length; i++) { Path<?> path = globalSearchAttributes[i]; if (path instanceof StringPath) { StringPath stringPath = (StringPath) path; searchCondition.or(stringPath.containsIgnoreCase(text)); } else if (path instanceof NumberExpression) { searchCondition.or(((NumberExpression<?>) path).like("%".concat(text).concat("%"))); } } return query.where(searchCondition); } return query; }
Example #4
Source File: EventController.java From sos with Apache License 2.0 | 6 votes |
@GetMapping("events") HttpEntity<Resources<?>> events(PagedResourcesAssembler<AbstractEvent<?>> assembler, @SortDefault("publicationDate") Pageable pageable, @RequestParam(required = false) @DateTimeFormat(iso = ISO.DATE_TIME) LocalDateTime since, @RequestParam(required = false) String type) { QAbstractEvent $ = QAbstractEvent.abstractEvent; BooleanBuilder builder = new BooleanBuilder(); // Apply date Optional.ofNullable(since).ifPresent(it -> builder.and($.publicationDate.after(it))); // Apply type Optional.ofNullable(type) // .flatMap(events::findEventTypeByName) // .ifPresent(it -> builder.and($.instanceOf(it))); Page<AbstractEvent<?>> result = events.findAll(builder, pageable); PagedResources<Resource<AbstractEvent<?>>> resource = assembler.toResource(result, event -> toResource(event)); resource .add(links.linkTo(methodOn(EventController.class).events(assembler, pageable, since, type)).withRel("events")); return ResponseEntity.ok(resource); }
Example #5
Source File: QueryDslPredicates.java From spring4-sandbox with Apache License 2.0 | 5 votes |
public static Predicate pastConferences(Date _past) { QConference conf = QConference.conference; final Date now = new Date(); BooleanBuilder builder = new BooleanBuilder(); builder.and(conf.endedDate.before(now)); if (_past != null) { builder.and(conf.startedDate.after(_past)); } return builder.getValue(); }
Example #6
Source File: NasService.java From radman with MIT License | 5 votes |
private Predicate buildNasSearchPredicate(@Nullable String searchText) { BooleanBuilder booleanBuilder = new BooleanBuilder(); if (!StringUtils.isEmpty(searchText)) { booleanBuilder.or(QNas.nas.nasName.contains(searchText)); booleanBuilder.or(QNas.nas.shortName.contains(searchText)); booleanBuilder.or(QNas.nas.description.contains(searchText)); booleanBuilder.or(QNas.nas.ports.like(searchText)); booleanBuilder.or(QNas.nas.secret.contains(searchText)); booleanBuilder.or(QNas.nas.server.contains(searchText)); booleanBuilder.or(QNas.nas.type.contains(searchText)); } return booleanBuilder.getValue(); }
Example #7
Source File: QueryDslPredicates.java From spring4-sandbox with Apache License 2.0 | 5 votes |
public static Predicate inProgressConferences() { QConference conf = QConference.conference; final Date now = new Date(); BooleanBuilder builder = new BooleanBuilder(); return builder.and(conf.startedDate.before(now)) .and(conf.endedDate.after(now)).getValue(); }
Example #8
Source File: PredicateBuilder.java From spring-data-jpa-datatables with Apache License 2.0 | 5 votes |
private Predicate createFinalPredicate() { BooleanBuilder predicate = new BooleanBuilder(); for (Predicate columnPredicate : columnPredicates) { predicate = predicate.and(columnPredicate); } if (!globalPredicates.isEmpty()) { predicate = predicate.andAnyOf(globalPredicates.toArray(new Predicate[0])); } return predicate; }
Example #9
Source File: QDataTablesRepositoryImpl.java From spring-data-jpa-datatables with Apache License 2.0 | 5 votes |
@Override public <R> DataTablesOutput<R> findAll(DataTablesInput input, Predicate additionalPredicate, Predicate preFilteringPredicate, Function<T, R> converter) { DataTablesOutput<R> output = new DataTablesOutput<>(); output.setDraw(input.getDraw()); if (input.getLength() == 0) { return output; } try { long recordsTotal = preFilteringPredicate == null ? count() : count(preFilteringPredicate); if (recordsTotal == 0) { return output; } output.setRecordsTotal(recordsTotal); PredicateBuilder predicateBuilder = new PredicateBuilder(this.builder, input); BooleanBuilder booleanBuilder = new BooleanBuilder() .and(predicateBuilder.build()) .and(additionalPredicate) .and(preFilteringPredicate); Predicate predicate = booleanBuilder.getValue(); Page<T> data = predicate != null ? findAll(predicate, predicateBuilder.createPageable()) : findAll(predicateBuilder.createPageable()); @SuppressWarnings("unchecked") List<R> content = converter == null ? (List<R>) data.getContent() : data.map(converter).getContent(); output.setData(content); output.setRecordsFiltered(data.getTotalElements()); } catch (Exception e) { output.setError(e.toString()); } return output; }
Example #10
Source File: UserService.java From eds-starter6-jpa with Apache License 2.0 | 5 votes |
public static boolean isLoginNameUnique(JPAQueryFactory jpaQueryFactory, Long userId, String loginName) { if (StringUtils.hasText(loginName)) { BooleanBuilder bb = new BooleanBuilder( QUser.user.loginName.equalsIgnoreCase(loginName)); if (userId != null) { bb.and(QUser.user.id.ne(userId)); } return jpaQueryFactory.select(Expressions.ONE).from(QUser.user).where(bb) .fetchFirst() == null; } return true; }
Example #11
Source File: UserService.java From eds-starter6-jpa with Apache License 2.0 | 5 votes |
public static boolean isEmailUnique(JPAQueryFactory jpaQueryFactory, Long userId, String email) { if (StringUtils.hasText(email)) { BooleanBuilder bb = new BooleanBuilder( QUser.user.email.equalsIgnoreCase(email)); if (userId != null) { bb.and(QUser.user.id.ne(userId)); } return jpaQueryFactory.select(Expressions.ONE).from(QUser.user).where(bb) .fetchFirst() == null; } return true; }
Example #12
Source File: PersonController.java From blog-tutorials with MIT License | 5 votes |
@GetMapping public Page<Person> getPersons( @RequestParam(name = "page", defaultValue = "0") int page, @RequestParam(name = "size", defaultValue = "500") int size, @RequestParam(name = "firstname", required = false) String firstname, @RequestParam(name = "lastname", required = false) String lastname, @RequestParam(name = "budget", required = false) Integer budget, @RequestParam(name = "dobLimit", required = false) Long dobLimit) { BooleanBuilder booleanBuilder = new BooleanBuilder(); if (firstname != null && !firstname.isEmpty()) { booleanBuilder.and(QPerson.person.firstname.eq(firstname)); } if (lastname != null && !lastname.isEmpty()) { booleanBuilder.and(QPerson.person.lastname.eq(lastname)); } if (budget != null && budget != 0) { booleanBuilder.and(QPerson.person.budget.goe(budget)); } if (dobLimit != null && dobLimit != 0) { booleanBuilder.and( QPerson.person.dob.before(Instant.ofEpochSecond(dobLimit))); } return personRepository.findAll(booleanBuilder.getValue(), PageRequest.of(page, size, Sort.by(Sort.Direction.ASC, "id"))); }
Example #13
Source File: AccountingService.java From radman with MIT License | 5 votes |
private Predicate buildAccountingSearchPredicate(@NonNull AccountingFilter filter) { BooleanBuilder booleanBuilder = new BooleanBuilder(); if (!(StringUtils.isEmpty(filter.getSearchText()))) { booleanBuilder.or(QRadAcct.radAcct.acctSessionId.contains(filter.getSearchText())); booleanBuilder.or(QRadAcct.radAcct.acctUniqueId.contains(filter.getSearchText())); booleanBuilder.or(QRadAcct.radAcct.username.contains(filter.getSearchText())); booleanBuilder.or(QRadAcct.radAcct.realm.contains(filter.getSearchText())); booleanBuilder.or(QRadAcct.radAcct.nasIpAddress.contains(filter.getSearchText())); booleanBuilder.or(QRadAcct.radAcct.nasPortId.contains(filter.getSearchText())); booleanBuilder.or(QRadAcct.radAcct.nasPortType.contains(filter.getSearchText())); booleanBuilder.or(QRadAcct.radAcct.acctInterval.stringValue().contains(filter.getSearchText())); booleanBuilder.or(QRadAcct.radAcct.acctSessionTime.stringValue().contains(filter.getSearchText())); booleanBuilder.or(QRadAcct.radAcct.acctAuthentic.contains(filter.getSearchText())); booleanBuilder.or(QRadAcct.radAcct.connectInfoStart.contains(filter.getSearchText())); booleanBuilder.or(QRadAcct.radAcct.connectInfoStop.contains(filter.getSearchText())); booleanBuilder.or(QRadAcct.radAcct.acctInputOctets.stringValue().contains(filter.getSearchText())); booleanBuilder.or(QRadAcct.radAcct.acctOutputOctets.stringValue().contains(filter.getSearchText())); booleanBuilder.or(QRadAcct.radAcct.calledStationId.contains(filter.getSearchText())); booleanBuilder.or(QRadAcct.radAcct.callingStationId.contains(filter.getSearchText())); booleanBuilder.or(QRadAcct.radAcct.acctTerminateCause.contains(filter.getSearchText())); booleanBuilder.or(QRadAcct.radAcct.serviceType.contains(filter.getSearchText())); booleanBuilder.or(QRadAcct.radAcct.framedProtocol.contains(filter.getSearchText())); booleanBuilder.or(QRadAcct.radAcct.framedIpAddress.contains(filter.getSearchText())); } if (filter.isSearchOnlyActiveSessions()) { booleanBuilder.and(QRadAcct.radAcct.acctStartTime.isNotNull()); booleanBuilder.and(QRadAcct.radAcct.acctStopTime.isNull()); } return booleanBuilder.getValue(); }
Example #14
Source File: SystemUserService.java From radman with MIT License | 5 votes |
private Predicate buildSystemUserSearchPredicate(@Nullable String searchText) { BooleanBuilder booleanBuilder = new BooleanBuilder(); if (!StringUtils.isEmpty(searchText)) { booleanBuilder.or(QSystemUser.systemUser.username.contains(searchText)); booleanBuilder.or(QSystemUser.systemUser.role.stringValue().contains(searchText)); } return booleanBuilder; }
Example #15
Source File: RadiusUserService.java From radman with MIT License | 5 votes |
private Predicate buildRadiusUserToGroupSearchPredicate(Filter filter) { BooleanBuilder booleanBuilder = new BooleanBuilder(); if (!StringUtils.isEmpty(filter.getSearchText())) { booleanBuilder.or(QRadUserGroup.radUserGroup.username.contains(filter.getSearchText())); booleanBuilder.or(QRadUserGroup.radUserGroup.groupName.contains(filter.getSearchText())); } return booleanBuilder; }
Example #16
Source File: RadiusUserService.java From radman with MIT License | 5 votes |
private Predicate buildRadiusGroupSearchPredicate(RadiusGroupFilter filter) { BooleanBuilder booleanBuilder = new BooleanBuilder(); if (!StringUtils.isEmpty(filter.getSearchText())) { if (filter.isSearchByGroupName()) { booleanBuilder.or(QRadiusGroup.radiusGroup.name.contains(filter.getSearchText())); } if (filter.isSearchByDescription()) { booleanBuilder.or(QRadiusGroup.radiusGroup.description.contains(filter.getSearchText())); } } return booleanBuilder; }
Example #17
Source File: RadiusUserService.java From radman with MIT License | 5 votes |
private Predicate buildRadiusUserSearchPredicate(RadiusUserFilter filter) { BooleanBuilder booleanBuilder = new BooleanBuilder(); if (!StringUtils.isEmpty(filter.getSearchText())) { if (filter.isSearchByName()) { booleanBuilder.or(QRadiusUser.radiusUser.username.contains(filter.getSearchText())); } if (filter.isSearchByDescription()) { booleanBuilder.or(QRadiusUser.radiusUser.description.contains(filter.getSearchText())); } } return booleanBuilder; }
Example #18
Source File: AttributeService.java From radman with MIT License | 5 votes |
private Predicate buildAuthorizationAttributeSearchPredicate(AttributeFilter filter) { BooleanBuilder booleanBuilder = new BooleanBuilder(); if (!StringUtils.isEmpty(filter.getSearchText())) { if (filter.isSearchByName()) { booleanBuilder.or(QRadReplyAttribute.radReplyAttribute.name.contains(filter.getSearchText())); } if (filter.isSearchByDescription()) { booleanBuilder.or(QRadReplyAttribute.radReplyAttribute.description.contains(filter.getSearchText())); } } return booleanBuilder; }
Example #19
Source File: AttributeService.java From radman with MIT License | 5 votes |
private Predicate buildAuthenticationAttributeSearchPredicate(AttributeFilter filter) { BooleanBuilder booleanBuilder = new BooleanBuilder(); if (!StringUtils.isEmpty(filter.getSearchText())) { if (filter.isSearchByName()) { booleanBuilder.or(QRadCheckAttribute.radCheckAttribute.name.contains(filter.getSearchText())); } if (filter.isSearchByDescription()) { booleanBuilder.or(QRadCheckAttribute.radCheckAttribute.description.contains(filter.getSearchText())); } } return booleanBuilder; }
Example #20
Source File: NasService.java From radman with MIT License | 5 votes |
private Predicate buildNasGroupSearchPredicate(@Nullable String searchText) { BooleanBuilder booleanBuilder = new BooleanBuilder(); if (!StringUtils.isEmpty(searchText)) { booleanBuilder.or(QRadHuntGroup.radHuntGroup.groupName.contains(searchText)); booleanBuilder.or(QRadHuntGroup.radHuntGroup.nasIpAddress.contains(searchText)); booleanBuilder.or(QRadHuntGroup.radHuntGroup.nasPortId.contains(searchText)); } return booleanBuilder; }
Example #21
Source File: QueryController.java From tutorials with MIT License | 4 votes |
@GetMapping(value = "/users", produces = MediaType.APPLICATION_JSON_VALUE) public Iterable<User> queryOverUser(@QuerydslPredicate(root = User.class) Predicate predicate) { final BooleanBuilder builder = new BooleanBuilder(); return personRepository.findAll(builder.and(predicate)); }
Example #22
Source File: QueryController.java From tutorials with MIT License | 4 votes |
@GetMapping(value = "/addresses", produces = MediaType.APPLICATION_JSON_VALUE) public Iterable<Address> queryOverAddress(@QuerydslPredicate(root = Address.class) Predicate predicate) { final BooleanBuilder builder = new BooleanBuilder(); return addressRepository.findAll(builder.and(predicate)); }