org.springframework.data.domain.Example.getProbe()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(12.2k)|赞(0)|评价(0)|浏览(140)

本文整理了Java中org.springframework.data.domain.Example.getProbe()方法的一些代码示例,展示了Example.getProbe()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Example.getProbe()方法的具体详情如下:
包路径:org.springframework.data.domain.Example
类名称:Example
方法名:getProbe

Example.getProbe介绍

[英]Get the example used.
[中]使用示例。

代码示例

代码示例来源:origin: spring-projects/spring-data-jpa

/**
 * Extract the {@link Predicate} representing the {@link Example}.
 *
 * @param root must not be {@literal null}.
 * @param cb must not be {@literal null}.
 * @param example must not be {@literal null}.
 * @return never {@literal null}.
 */
public static <T> Predicate getPredicate(Root<T> root, CriteriaBuilder cb, Example<T> example) {
  Assert.notNull(root, "Root must not be null!");
  Assert.notNull(cb, "CriteriaBuilder must not be null!");
  Assert.notNull(example, "Example must not be null!");
  ExampleMatcher matcher = example.getMatcher();
  List<Predicate> predicates = getPredicates("", cb, root, root.getModel(), example.getProbe(),
      example.getProbeType(), new ExampleMatcherAccessor(matcher), new PathNode("root", null, example.getProbe()));
  if (predicates.isEmpty()) {
    return cb.isTrue(cb.literal(true));
  }
  if (predicates.size() == 1) {
    return predicates.iterator().next();
  }
  Predicate[] array = predicates.toArray(new Predicate[0]);
  return matcher.isAllMatching() ? cb.and(array) : cb.or(array);
}

代码示例来源:origin: apache/servicemix-bundles

/**
   * Get the actual type for the probe used. This is usually the given class, but the original class in case of a
   * CGLIB-generated subclass.
   *
   * @return
   * @see ProxyUtils#getUserClass(Class)
   */
  @SuppressWarnings("unchecked")
  default Class<T> getProbeType() {
    return (Class<T>) ProxyUtils.getUserClass(getProbe().getClass());
  }
}

代码示例来源:origin: spring-projects/spring-data-redis

/**
 * Retrieve a mapped {@link RedisOperationChain} to query secondary indexes given {@link Example}.
 *
 * @param example must not be {@literal null}.
 * @return the mapped {@link RedisOperationChain}.
 */
public RedisOperationChain getMappedExample(Example<?> example) {
  RedisOperationChain chain = new RedisOperationChain();
  ExampleMatcherAccessor matcherAccessor = new ExampleMatcherAccessor(example.getMatcher());
  applyPropertySpecs("", example.getProbe(), mappingContext.getRequiredPersistentEntity(example.getProbeType()),
      matcherAccessor, example.getMatcher().getMatchMode(), chain);
  return chain;
}

代码示例来源:origin: com.mmnaseri.utils/spring-data-mock

/**
 * This method will create an invocation that had it occurred on a query method would provide sufficient
 * data for a parsed query method expression to be evaluated
 * @param descriptor    the query descriptor
 * @param example       the example that is used for evaluation
 * @return the fake method invocation corresponding to the example probe
 */
private Invocation createInvocation(QueryDescriptor descriptor, Example example) {
  final List<Object> values = new ArrayList<>();
  //since according to http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#query-by-example
  //the matcher only supports AND condition, so, we expect to see only one branch
  final List<List<Parameter>> branches = descriptor.getBranches();
  final List<Parameter> parameters = branches.get(0);
  for (Parameter parameter : parameters) {
    final String propertyPath = parameter.getPath();
    final Object propertyValue = PropertyUtils.getPropertyValue(example.getProbe(), propertyPath);
    final ExampleMatcher.PropertySpecifier specifier = example.getMatcher().getPropertySpecifiers().getForPath(propertyPath);
    values.add(specifier == null ? propertyValue : specifier.getPropertyValueTransformer().convert(propertyValue));
  }
  return new ImmutableInvocation(null, values.toArray());
}

代码示例来源:origin: spring-projects/spring-data-mongodb

/**
 * Returns the given {@link Example} as {@link Document} holding matching values extracted from
 * {@link Example#getProbe()}.
 *
 * @param example must not be {@literal null}.
 * @param entity must not be {@literal null}.
 * @return
 */
public Document getMappedExample(Example<?> example, MongoPersistentEntity<?> entity) {
  Assert.notNull(example, "Example must not be null!");
  Assert.notNull(entity, "MongoPersistentEntity must not be null!");
  Document reference = (Document) converter.convertToMongoType(example.getProbe());
  if (entity.getIdProperty() != null && ClassUtils.isAssignable(entity.getType(), example.getProbeType())) {
    Object identifier = entity.getIdentifierAccessor(example.getProbe()).getIdentifier();
    if (identifier == null) {
      reference.remove(entity.getIdProperty().getFieldName());
    }
  }
  ExampleMatcherAccessor matcherAccessor = new ExampleMatcherAccessor(example.getMatcher());
  applyPropertySpecs("", reference, example.getProbeType(), matcherAccessor);
  Document flattened = ObjectUtils.nullSafeEquals(NullHandler.INCLUDE, matcherAccessor.getNullHandler()) ? reference
      : new Document(SerializationUtils.flattenMap(reference));
  Document result = example.getMatcher().isAllMatching() ? flattened : orConcatenate(flattened);
  return updateTypeRestrictions(result, example);
}

代码示例来源:origin: mmnaseri/spring-data-mock

/**
 * This method will create an invocation that had it occurred on a query method would provide sufficient
 * data for a parsed query method expression to be evaluated
 * @param descriptor    the query descriptor
 * @param example       the example that is used for evaluation
 * @return the fake method invocation corresponding to the example probe
 */
private Invocation createInvocation(QueryDescriptor descriptor, Example example) {
  final List<Object> values = new ArrayList<>();
  //since according to http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#query-by-example
  //the matcher only supports AND condition, so, we expect to see only one branch
  final List<List<Parameter>> branches = descriptor.getBranches();
  final List<Parameter> parameters = branches.get(0);
  for (Parameter parameter : parameters) {
    final String propertyPath = parameter.getPath();
    final Object propertyValue = PropertyUtils.getPropertyValue(example.getProbe(), propertyPath);
    final ExampleMatcher.PropertySpecifier specifier = example.getMatcher().getPropertySpecifiers().getForPath(propertyPath);
    values.add(specifier == null ? propertyValue : specifier.getPropertyValueTransformer().convert(propertyValue));
  }
  return new ImmutableInvocation(null, values.toArray());
}

代码示例来源:origin: org.springframework.data/spring-data-mongodb

/**
 * Returns the given {@link Example} as {@link Document} holding matching values extracted from
 * {@link Example#getProbe()}.
 *
 * @param example must not be {@literal null}.
 * @param entity must not be {@literal null}.
 * @return
 */
public Document getMappedExample(Example<?> example, MongoPersistentEntity<?> entity) {
  Assert.notNull(example, "Example must not be null!");
  Assert.notNull(entity, "MongoPersistentEntity must not be null!");
  Document reference = (Document) converter.convertToMongoType(example.getProbe());
  if (entity.getIdProperty() != null && ClassUtils.isAssignable(entity.getType(), example.getProbeType())) {
    Object identifier = entity.getIdentifierAccessor(example.getProbe()).getIdentifier();
    if (identifier == null) {
      reference.remove(entity.getIdProperty().getFieldName());
    }
  }
  ExampleMatcherAccessor matcherAccessor = new ExampleMatcherAccessor(example.getMatcher());
  applyPropertySpecs("", reference, example.getProbeType(), matcherAccessor);
  Document flattened = ObjectUtils.nullSafeEquals(NullHandler.INCLUDE, matcherAccessor.getNullHandler()) ? reference
      : new Document(SerializationUtils.flattenMap(reference));
  Document result = example.getMatcher().isAllMatching() ? flattened : orConcatenate(flattened);
  return updateTypeRestrictions(result, example);
}

代码示例来源:origin: com.mmnaseri.utils/spring-data-mock

@Override
public QueryDescriptor extract(RepositoryMetadata repositoryMetadata, RepositoryFactoryConfiguration configuration, Example example) {
  final OperatorContext operatorContext = configuration.getDescriptionExtractor().getOperatorContext();
  final Map<String, Object> values = extractValues(example.getProbe());
  final ExampleMatcher matcher = example.getMatcher();
  final List<Parameter> parameters = new ArrayList<>();

代码示例来源:origin: arangodb/spring-data

public String convertExampleToPredicate(final Example<T> example, final Map<String, Object> bindVars) {
  final StringBuilder predicateBuilder = new StringBuilder();
  final ArangoPersistentEntity<?> persistentEntity = context.getPersistentEntity(example.getProbeType());
  Assert.isTrue(example.getProbe() != null, "Probe in Example cannot be null");
  traversePropertyTree(example, predicateBuilder, bindVars, "", "", persistentEntity, example.getProbe());
  return predicateBuilder.toString();
}

代码示例来源:origin: mmnaseri/spring-data-mock

@Override
public QueryDescriptor extract(RepositoryMetadata repositoryMetadata, RepositoryFactoryConfiguration configuration, Example example) {
  final OperatorContext operatorContext = configuration.getDescriptionExtractor().getOperatorContext();
  final Map<String, Object> values = extractValues(example.getProbe());
  final ExampleMatcher matcher = example.getMatcher();
  final List<Parameter> parameters = new ArrayList<>();

代码示例来源:origin: com.arangodb/arangodb-spring-data

public String convertExampleToPredicate(final Example<T> example, final Map<String, Object> bindVars) {
  final StringBuilder predicateBuilder = new StringBuilder();
  final ArangoPersistentEntity<?> persistentEntity = context.getPersistentEntity(example.getProbeType());
  Assert.isTrue(example.getProbe() != null, "Probe in Example cannot be null");
  traversePropertyTree(example, predicateBuilder, bindVars, "", "", persistentEntity, example.getProbe());
  return predicateBuilder.toString();
}

代码示例来源:origin: hexagonframework/spring-data-ebean

break;
return ebeanServer.getExpressionFactory().exampleLike(example.getProbe(),
    example.getMatcher().isIgnoreCaseEnabled(),
    likeType);

代码示例来源:origin: org.springframework.data/spring-data-jpa

/**
 * Extract the {@link Predicate} representing the {@link Example}.
 *
 * @param root must not be {@literal null}.
 * @param cb must not be {@literal null}.
 * @param example must not be {@literal null}.
 * @return never {@literal null}.
 */
public static <T> Predicate getPredicate(Root<T> root, CriteriaBuilder cb, Example<T> example) {
  Assert.notNull(root, "Root must not be null!");
  Assert.notNull(cb, "CriteriaBuilder must not be null!");
  Assert.notNull(example, "Example must not be null!");
  ExampleMatcher matcher = example.getMatcher();
  List<Predicate> predicates = getPredicates("", cb, root, root.getModel(), example.getProbe(),
      example.getProbeType(), new ExampleMatcherAccessor(matcher), new PathNode("root", null, example.getProbe()));
  if (predicates.isEmpty()) {
    return cb.isTrue(cb.literal(true));
  }
  if (predicates.size() == 1) {
    return predicates.iterator().next();
  }
  Predicate[] array = predicates.toArray(new Predicate[0]);
  return matcher.isAllMatching() ? cb.and(array) : cb.or(array);
}

代码示例来源:origin: io.github.hexagonframework.data/spring-data-ebean

break;
return ebeanServer.getExpressionFactory().exampleLike(example.getProbe(),
    example.getMatcher().isIgnoreCaseEnabled(),
    likeType);

代码示例来源:origin: org.springframework.data/spring-data-redis

/**
 * Retrieve a mapped {@link RedisOperationChain} to query secondary indexes given {@link Example}.
 *
 * @param example must not be {@literal null}.
 * @return the mapped {@link RedisOperationChain}.
 */
public RedisOperationChain getMappedExample(Example<?> example) {
  RedisOperationChain chain = new RedisOperationChain();
  ExampleMatcherAccessor matcherAccessor = new ExampleMatcherAccessor(example.getMatcher());
  applyPropertySpecs("", example.getProbe(), mappingContext.getRequiredPersistentEntity(example.getProbeType()),
      matcherAccessor, example.getMatcher().getMatchMode(), chain);
  return chain;
}

代码示例来源:origin: apache/servicemix-bundles

/**
 * Retrieve a mapped {@link RedisOperationChain} to query secondary indexes given {@link Example}.
 *
 * @param example must not be {@literal null}.
 * @return the mapped {@link RedisOperationChain}.
 */
public RedisOperationChain getMappedExample(Example<?> example) {
  RedisOperationChain chain = new RedisOperationChain();
  ExampleMatcherAccessor matcherAccessor = new ExampleMatcherAccessor(example.getMatcher());
  applyPropertySpecs("", example.getProbe(), mappingContext.getRequiredPersistentEntity(example.getProbeType()),
      matcherAccessor, example.getMatcher().getMatchMode(), chain);
  return chain;
}

代码示例来源:origin: spring-cloud/spring-cloud-gcp

private <T> StructuredQuery exampleToQuery(Example<T> example, DatastoreQueryOptions queryOptions, boolean keyQuery) {
  validateExample(example);
  T probe = example.getProbe();
  FullEntity.Builder<IncompleteKey> probeEntityBuilder = Entity.newBuilder();
  this.datastoreEntityConverter.write(probe, probeEntityBuilder);

相关文章

微信公众号

最新文章

更多