当前位置: 首页>>代码示例>>Java>>正文


Java Predicate类代码示例

本文整理汇总了Java中com.querydsl.core.types.Predicate的典型用法代码示例。如果您正苦于以下问题:Java Predicate类的具体用法?Java Predicate怎么用?Java Predicate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Predicate类属于com.querydsl.core.types包,在下文中一共展示了Predicate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: pesquisar

import com.querydsl.core.types.Predicate; //导入依赖的package包/类
/**
 * Retorna os Veiculos de acordo com o filtro.
 * 
 * @param placa
 *            Número da Placa do Veiculo. Busca com like à direita.
 * @return todos os Veiculos do Usuário paginado de 10 em 10.
 */
@RequestMapping(value = "/pesquisar", method = RequestMethod.GET)
@ApiOperation(value = "Pesquisa de Veículo")
public ResponseEntity<Page<Veiculo>> pesquisar(
		@RequestParam(name = "placa", required = true) String placa, 
		@PageableDefault(sort = { "placa" }, direction = Direction.ASC) Pageable pageable) {
	
	// Não permite caracteres especiais na busca
	Validate.isTrue(StringUtils.isAlphanumeric(placa));
	
	Predicate predicate = QVeiculo.veiculo.placa.like(placa.toUpperCase() + '%');

	Page<Veiculo> page = veiculoRepository.findAll(predicate, pageable);
	
	page.forEach(v -> v.getProprietario().getId()); // TODO buscar uma
													// forma de arrumar
													// no
													// QueryDslPredicateExecutor
	return new ResponseEntity<>(page, HttpStatus.OK);
}
 
开发者ID:gustajz,项目名称:parking-api,代码行数:27,代码来源:VeiculoController.java

示例2: buildTextQuery

import com.querydsl.core.types.Predicate; //导入依赖的package包/类
private Predicate buildTextQuery(TextQuery txt, StringPath txtfield) {

        if (txt.isEmpty()) {
            return null;
        }

        BooleanBuilder predicate = new BooleanBuilder();

        if (txt.getContains() != null) {
            predicate.and(txtfield.contains(txt.getContains()));
        }

        if (txt.getStartWith() != null) {
            predicate.and(txtfield.startsWith(txt.getStartWith()));
        }

        if (txt.getEndWith() != null) {
            predicate.and(txtfield.endsWith(txt.getEndWith()));
        }

        if (txt.getEquals() != null) {
            predicate.and(txtfield.endsWith(txt.getEquals()));
        }

        return predicate;
    }
 
开发者ID:raptorbox,项目名称:raptor,代码行数:27,代码来源:DataQueryBuilder.java

示例3: searchDevices

import com.querydsl.core.types.Predicate; //导入依赖的package包/类
@RequestMapping(method = RequestMethod.POST, value = "/search")
@ApiOperation(value = "Search for device instances", notes = "", response = Device.class, nickname = "searchDevices")
@PreAuthorize("@raptorSecurity.can(principal, 'device', 'read')")
public ResponseEntity<?> searchDevices(
        @AuthenticationPrincipal User currentUser,
        @RequestParam MultiValueMap<String, String> parameters, 
        @RequestBody DeviceQuery query
) {

    if (query.isEmpty()) {
        return JsonErrorResponse.badRequest();
    }

    if (!currentUser.isAdmin()) {
        query.userId(currentUser.getId());
    }

    DeviceQueryBuilder qb = new DeviceQueryBuilder(query);
    Predicate predicate = qb.getPredicate();
    Pageable paging = qb.getPaging();

    Page<Device> pagedList = deviceService.search(predicate, paging);

    return ResponseEntity.ok(pagedList);
}
 
开发者ID:raptorbox,项目名称:raptor,代码行数:26,代码来源:InventoryController.java

示例4: noHolidayExistsSubSelect

import com.querydsl.core.types.Predicate; //导入依赖的package包/类
private static Predicate noHolidayExistsSubSelect(final Expression<Long> userId,
    final DatePath<Date> date) {
  QPublicHoliday qPublicHoliday = new QPublicHoliday("exp_work_nh_ph");
  QUserHolidayScheme qUserHolidayScheme = new QUserHolidayScheme("exp_work_nh_uhsch");
  QDateRange qDateRange = new QDateRange("exp_work_nh_data_range");

  return new SQLQuery<>().select(qPublicHoliday.publicHolidayId).from(qPublicHoliday)
      .innerJoin(qUserHolidayScheme)
      .on(qUserHolidayScheme.holidaySchemeId.eq(qPublicHoliday.holidaySchemeId))
      .innerJoin(qDateRange).on(qDateRange.dateRangeId.eq(qUserHolidayScheme.dateRangeId))
      .where(qUserHolidayScheme.userId.eq(userId)
          .and(qDateRange.startDate.loe(date))
          .and(qDateRange.endDateExcluded.gt(date))
          .and(qPublicHoliday.date.eq(date)))
      .notExists();
}
 
开发者ID:everit-org,项目名称:jira-hr-admin,代码行数:17,代码来源:QueryUtil.java

示例5: hasOverlapping

import com.querydsl.core.types.Predicate; //导入依赖的package包/类
private boolean hasOverlapping(final Long userId, final Date startDate,
    final Date endDateExcluded, final Long userHolidayAmountIdToExclude) {
  Long count = querydslSupport.execute((connection, configuration) -> {
    QDateRange qDateRange = QDateRange.dateRange;
    QUserHolidayAmount qUserHolidayAmount = QUserHolidayAmount.userHolidayAmount;
    SQLQuery<Long> query = new SQLQuery<>(connection, configuration)
        .select(qDateRange.dateRangeId)
        .from(qDateRange)
        .innerJoin(qUserHolidayAmount)
        .on(qDateRange.dateRangeId.eq(qUserHolidayAmount.dateRangeId));

    List<Predicate> predicates = new ArrayList<>();
    predicates.add(qUserHolidayAmount.userId.eq(userId));

    if (userHolidayAmountIdToExclude != null) {
      predicates.add(qUserHolidayAmount.userHolidayAmountId.ne(userHolidayAmountIdToExclude));
    }

    predicates.add(rangeOverlaps(qDateRange, startDate, endDateExcluded));

    query.where(predicates.toArray(new Predicate[predicates.size()]));
    return query.fetchCount();
  });
  return count > 0;
}
 
开发者ID:everit-org,项目名称:jira-hr-admin,代码行数:26,代码来源:UserHolidayAmountServlet.java

示例6: index

import com.querydsl.core.types.Predicate; //导入依赖的package包/类
@RequestMapping(value = "/", method = RequestMethod.GET)
String index(Model model, //
		@QuerydslPredicate(root = User.class) Predicate predicate, //
		@PageableDefault(sort = { "lastname", "firstname" }) Pageable pageable, //
		@RequestParam MultiValueMap<String, String> parameters) {

	ServletUriComponentsBuilder builder = ServletUriComponentsBuilder.fromCurrentRequest();
	builder.replaceQueryParam("page", new Object[0]);

	model.addAttribute("baseUri", builder.build().toUri());
	model.addAttribute("users", repository.findAll(predicate, pageable));

	return "index";
}
 
开发者ID:Just-Fun,项目名称:spring-data-examples,代码行数:15,代码来源:UserController.java

示例7: findDishes

import com.querydsl.core.types.Predicate; //导入依赖的package包/类
@RequestMapping(value = "search", method = RequestMethod.GET)
  public ModelAndView findDishes(@QuerydslPredicate(root = Dish.class) Predicate predicate, @PageableDefault(sort = {"date"}, direction = Sort.Direction.DESC) Pageable pageable, ModelAndView modelAndView) {
Sort realSort = pageable.getSort().and(new Sort(Sort.Direction.ASC, "id"));
PageRequest pageRequest = new PageRequest(pageable.getPageNumber(), pageable.getPageSize(), realSort);
Page<Dish> page = dishRepo.findAll(predicate, pageRequest);
List<DishWebDTO> dishes = page.getContent().stream().map(dishDtoFactory::create).collect(Collectors.toList());
modelAndView.addObject("page", page);
modelAndView.addObject("dishes", dishes);
modelAndView.addObject("labels", getLabelsFromDishes());
modelAndView.addObject("categories", getCategoriesFromDishes());
modelAndView.addObject("mensas", mensaRepo.findAllByOrderByName());
      modelAndView.setViewName("search");
      return modelAndView;
  }
 
开发者ID:xabgesagtx,项目名称:mensa-api,代码行数:15,代码来源:MensaWebController.java

示例8: createTypePredicate

import com.querydsl.core.types.Predicate; //导入依赖的package包/类
/**
 * Find the common type that should be used to compare the given two
 * expressions.
 *
 * @param other The type of the other that we should enforce on the json
 * type.
 * @return the extra predicate to enforce the type with.
 */
private Predicate createTypePredicate(CompareType other) {
    switch (other) {
        case NUMBER:
            return Expressions.stringTemplate("jsonb_typeof({0})", jsonExpression).eq("number");
        case BOOLEAN:
            return Expressions.stringTemplate("jsonb_typeof({0})", jsonExpression).eq("boolean");
        default:
            return null;
    }
}
 
开发者ID:FraunhoferIOSB,项目名称:SensorThingsServer,代码行数:19,代码来源:JsonExpressionFactory.java

示例9: buildPredicate

import com.querydsl.core.types.Predicate; //导入依赖的package包/类
public Optional<Predicate> buildPredicate(final QAnnouncementSubscriber subscriber) {
    final Map<Organisation, Set<OccupationType>> childOccupationMapping = activeOccupations.stream()
            .flatMap(occupation -> occupation.getOrganisation().getAllParentsAndSelf().stream()
                    .map(parent -> new BasicOccupationItem(parent, occupation.getOccupationType())))
            .collect(groupingBy(BasicOccupationItem::getOrganisation,
                    mapping(BasicOccupationItem::getOccupationType, toSet())));

    final List<Predicate> predicateList = childOccupationMapping.entrySet().stream()
            .filter(entry -> organisationFilter == null || organisationFilter.contains(entry.getKey()))
            .map(entry -> {
                final Organisation organisation = entry.getKey();
                final Set<OccupationType> childOccupationTypes = entry.getValue();

                if (childOccupationTypes.contains(OccupationType.TOIMINNANOHJAAJA)) {
                    // Coordinator should see any message sent by parent organisations or self
                    return subscriber.organisation.eq(organisation);

                } else if (childOccupationTypes.contains(OccupationType.SEURAN_YHDYSHENKILO)) {
                    // Club contact person should see all club communication
                    return subscriber.organisation.eq(organisation)
                            .and(subscriber.occupationType.in(OccupationType.clubValues()));

                } else {
                    Preconditions.checkArgument(!childOccupationTypes.isEmpty(), "should not be empty");
                    return subscriber.organisation.eq(organisation)
                            .and(subscriber.occupationType.in(childOccupationTypes));
                }
            })
            .collect(Collectors.toList());

    return predicateList.isEmpty() ? Optional.empty() : Optional.ofNullable(ExpressionUtils.anyOf(predicateList));
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:33,代码来源:PersonOccupationGraph.java

示例10: subscriberExists

import com.querydsl.core.types.Predicate; //导入依赖的package包/类
private static Predicate subscriberExists(final QAnnouncement announcement,
                                          final QAnnouncementSubscriber subscriber,
                                          final Predicate predicate) {
    return JPAExpressions.selectFrom(subscriber)
            .where(subscriber.announcement.eq(announcement), predicate)
            .exists();
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:8,代码来源:ListAnnouncementFilter.java

示例11: listByClubAndYear

import com.querydsl.core.types.Predicate; //导入依赖的package包/类
@Transactional(readOnly = true)
public List<HuntingClubAreaDTO> listByClubAndYear(final long clubId,
                                                  final Integer year,
                                                  final boolean activeOnly) {
    final HuntingClub club = requireEntityService.requireHuntingClub(clubId, EntityPermission.READ);

    final Predicate[] predicates = createPredicate(club, year, activeOnly);

    return huntingClubAreaDTOTransformer.apply(new JPAQuery<>(entityManager).from(QHuntingClubArea.huntingClubArea)
            .where(predicates)
            .select(QHuntingClubArea.huntingClubArea)
            .fetch());
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:14,代码来源:HuntingClubAreaCrudFeature.java

示例12: given_brand_eg_when_findpage_then_brand_should_be_loaded

import com.querydsl.core.types.Predicate; //导入依赖的package包/类
@Transactional
@Test
public void given_brand_eg_when_findpage_then_brand_should_be_loaded() {
  Page<Product> productPage =
      productRepository.findAll(
          (Predicate) null, new PageRequest(0, 10), EntityGraphUtils.fromName(Product.BRAND_EG));
  assertThat(productPage.getContent()).isNotEmpty();
  for (Product product : productPage.getContent()) {
    assertThat(Hibernate.isInitialized(product.getBrand())).isTrue();
  }
}
 
开发者ID:Cosium,项目名称:spring-data-jpa-entity-graph,代码行数:12,代码来源:EntityGraphQuerydslPredicateExecutorTest.java

示例13: buildTextQuery

import com.querydsl.core.types.Predicate; //导入依赖的package包/类
private Predicate buildTextQuery(TextQuery txt, StringPath txtfield) {

        if (txt.isEmpty()) {
            return null;
        }

        BooleanBuilder predicate = new BooleanBuilder();

        if (txt.getContains() != null) {
            predicate.and(txtfield.contains(txt.getContains()));
        }

        if (txt.getStartWith() != null) {
            predicate.and(txtfield.startsWith(txt.getStartWith()));
        }

        if (txt.getEndWith() != null) {
            predicate.and(txtfield.endsWith(txt.getEndWith()));
        }

        if (txt.getEquals() != null) {
            predicate.and(txtfield.endsWith(txt.getEquals()));
        }

        if (!txt.getIn().isEmpty()) {
            predicate.and(txtfield.in(txt.getIn()));
        }

        return predicate;
    }
 
开发者ID:raptorbox,项目名称:raptor,代码行数:31,代码来源:TreeQueryBuilder.java

示例14: getPredicate

import com.querydsl.core.types.Predicate; //导入依赖的package包/类
public Predicate getPredicate() {
        throw new RuntimeException("querydsl geoquery is missing?");
//        QRecordSet record = new QRecordSet("record");
//
//        BooleanBuilder predicate = new BooleanBuilder();
//
//        if (query.getUserId() != null) {
//            predicate.and(record.userId.eq(query.getUserId()));
//        }
//        
//        if (!query.getTimestamp().isEmpty()) {
//            
//            // between
//            if(query.getTimestamp().getBetween().length > 0) {
//                Date t0 = Date.from(Instant.ofEpochMilli(query.getTimestamp().getBetween()[0].longValue()));
//                Date t1 = Date.from(Instant.ofEpochMilli(query.getTimestamp().getBetween()[1].longValue()));
//                predicate.and(record.timestamp.between(t0, t1));
//            }
//            
//        }
//        
//        if (!query.getLocation().isEmpty()) {
//            GeoQuery.Distance d = query.getLocation().getDistance();
//            if (d.center != null) {
//                predicate.and(MongodbExpressions.near(record.location, 0, 0));
//                NearQuery nearQuery = NearQuery
//                        .near(d.center)
//                        .maxDistance(new Distance(d.radius, Metrics.KILOMETERS));
//            }
//        }
//        
//        
//        return predicate;
    }
 
开发者ID:raptorbox,项目名称:raptor,代码行数:35,代码来源:DataQueryBuilder.java

示例15: getPredicate

import com.querydsl.core.types.Predicate; //导入依赖的package包/类
public Predicate getPredicate() {

        QApp app = new QApp("app");

        BooleanBuilder predicate = new BooleanBuilder();

        if (query.getUserId() != null) {
            predicate.and(app.userId.eq(query.getUserId()));
        }

        // id
        Predicate pid = buildTextQuery(query.id, app.id);
        if (pid != null) {
            predicate.and(pid);
        }

        // name
        Predicate pname = buildTextQuery(query.name, app.name);
        if (pname != null) {
            predicate.and(pname);
        }

        // description
        Predicate pdesc = buildTextQuery(query.description, app.description);
        if (pdesc != null) {
            predicate.and(pdesc);
        }

        //users (id)
        Predicate users = buildAppUserListQuery(query.users, app.users);
        if (users != null) {
            predicate.and(users);
        }

        return predicate;
    }
 
开发者ID:raptorbox,项目名称:raptor,代码行数:37,代码来源:AppQueryBuilder.java


注:本文中的com.querydsl.core.types.Predicate类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。