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

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

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

Example.getMatcher介绍

[英]Get the ExampleMatcher used.
[中]使用ExampleMatcher。

代码示例

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

private boolean isTypeRestricting(Example example) {
  if (example.getMatcher() instanceof UntypedExampleMatcher) {
    return false;
  }
  if (example.getMatcher().getIgnoredPaths().isEmpty()) {
    return true;
  }
  for (String path : example.getMatcher().getIgnoredPaths()) {
    if (this.converter.getTypeMapper().isTypeKey(path)) {
      return false;
    }
  }
  return true;
}

代码示例来源: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: 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: 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: org.springframework.data/spring-data-mongodb

private boolean isTypeRestricting(Example example) {
  if (example.getMatcher() instanceof UntypedExampleMatcher) {
    return false;
  }
  if (example.getMatcher().getIgnoredPaths().isEmpty()) {
    return true;
  }
  for (String path : example.getMatcher().getIgnoredPaths()) {
    if (this.converter.getTypeMapper().isTypeKey(path)) {
      return false;
    }
  }
  return true;
}

代码示例来源: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: 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: com.arangodb/arangodb-spring-data

final String fullJavaPath,
Object value) {
final String delimiter = example.getMatcher().isAllMatching() ? " AND " : " OR ";
if (predicateBuilder.length() > 0) {
  predicateBuilder.append(delimiter);
final ExampleMatcher.PropertySpecifier specifier = example.getMatcher().getPropertySpecifiers()
    .getForPath(fullPath);
if (specifier != null && value != null) {
  clause = String.format("e.%s == null", fullPath);
} else if (String.class.isAssignableFrom(value.getClass())) {
  final boolean ignoreCase = specifier == null ? example.getMatcher().isIgnoreCaseEnabled()
      : (specifier.getIgnoreCase() == null ? false : specifier.getIgnoreCase());
  final ExampleMatcher.StringMatcher stringMatcher = (specifier == null
      || specifier.getStringMatcher() == ExampleMatcher.StringMatcher.DEFAULT)
          ? example.getMatcher().getDefaultStringMatcher()
          : specifier.getStringMatcher();
  final String string = (String) value;

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

switch (example.getMatcher().getDefaultStringMatcher()) {
  case EXACT:
    likeType = LikeType.EQUAL_TO;
    example.getMatcher().isIgnoreCaseEnabled(),
    likeType);

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

switch (example.getMatcher().getDefaultStringMatcher()) {
  case EXACT:
    likeType = LikeType.EQUAL_TO;
    example.getMatcher().isIgnoreCaseEnabled(),
    likeType);

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

private <T> void validateExample(Example<T> example) {
    Assert.notNull(example, "A non-null example is expected");

    ExampleMatcher matcher = example.getMatcher();
    if (!matcher.isAllMatching()) {
      throw new DatastoreDataException("Unsupported MatchMode. Only MatchMode.ALL is supported");
    }
    if (matcher.isIgnoreCaseEnabled()) {
      throw new DatastoreDataException("Ignore case matching is not supported");
    }
    if (!(matcher.getDefaultStringMatcher() == ExampleMatcher.StringMatcher.EXACT
        || matcher.getDefaultStringMatcher() == ExampleMatcher.StringMatcher.DEFAULT)) {
      throw new DatastoreDataException("Unsupported StringMatcher. Only EXACT and DEFAULT are supported");
    }

    Optional<String> path =
        example.getMatcher().getIgnoredPaths().stream().filter((s) -> s.contains(".")).findFirst();
    if (path.isPresent()) {
      throw new DatastoreDataException("Ignored paths deeper than 1 are not supported");
    }
    if (matcher.getPropertySpecifiers().hasValues()) {
      throw new DatastoreDataException("Property matchers are not supported");
    }
  }
}

代码示例来源: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: 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: 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: com.arangodb/arangodb-spring-data

private void traversePropertyTree(
  final Example<T> example,
  final StringBuilder predicateBuilder,
  final Map<String, Object> bindVars,
  final String path,
  final String javaPath,
  final ArangoPersistentEntity<?> entity,
  final Object object) {
  final PersistentPropertyAccessor<?> accessor = entity.getPropertyAccessor(object);
  entity.doWithProperties((final ArangoPersistentProperty property) -> {
    if (property.getFrom().isPresent() || property.getTo().isPresent() || property.getRelations().isPresent()) {
      return;
    }
    final String fullPath = path + (path.length() == 0 ? "" : ".") + property.getFieldName();
    final String fullJavaPath = javaPath + (javaPath.length() == 0 ? "" : ".") + property.getName();
    final Object value = accessor.getProperty(property);
    if (property.isEntity() && value != null) {
      final ArangoPersistentEntity<?> persistentEntity = context.getPersistentEntity(property.getType());
      traversePropertyTree(example, predicateBuilder, bindVars, fullPath, fullJavaPath, persistentEntity,
        value);
    } else if (!example.getMatcher().isIgnoredPath(fullJavaPath) && (value != null
        || example.getMatcher().getNullHandler().equals(ExampleMatcher.NullHandler.INCLUDE))) {
      addPredicate(example, predicateBuilder, bindVars, fullPath, fullJavaPath, value);
    }
  });
}

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

private void traversePropertyTree(
  final Example<T> example,
  final StringBuilder predicateBuilder,
  final Map<String, Object> bindVars,
  final String path,
  final String javaPath,
  final ArangoPersistentEntity<?> entity,
  final Object object) {
  final PersistentPropertyAccessor<?> accessor = entity.getPropertyAccessor(object);
  entity.doWithProperties((final ArangoPersistentProperty property) -> {
    if (property.getFrom().isPresent() || property.getTo().isPresent() || property.getRelations().isPresent()) {
      return;
    }
    final String fullPath = path + (path.length() == 0 ? "" : ".") + property.getFieldName();
    final String fullJavaPath = javaPath + (javaPath.length() == 0 ? "" : ".") + property.getName();
    final Object value = accessor.getProperty(property);
    if (property.isEntity() && value != null) {
      final ArangoPersistentEntity<?> persistentEntity = context.getPersistentEntity(property.getType());
      traversePropertyTree(example, predicateBuilder, bindVars, fullPath, fullJavaPath, persistentEntity,
        value);
    } else if (!example.getMatcher().isIgnoredPath(fullJavaPath) && (value != null
        || example.getMatcher().getNullHandler().equals(ExampleMatcher.NullHandler.INCLUDE))) {
      addPredicate(example, predicateBuilder, bindVars, fullPath, fullJavaPath, value);
    }
  });
}

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

builder.setKind(persistentEntity.kindName());
ExampleMatcherAccessor matcherAccessor = new ExampleMatcherAccessor(example.getMatcher());
matcherAccessor.getPropertySpecifiers();
LinkedList<StructuredQuery.Filter> filters = new LinkedList<>();
persistentEntity.doWithColumnBackedProperties((persistentProperty) -> {
  if (!example.getMatcher().isIgnoredPath(persistentProperty.getName())) {
    String fieldName = persistentProperty.getFieldName();
    Value<?> value = probeEntity.getValue(fieldName);
    if (value instanceof NullValue
        && example.getMatcher().getNullHandler() != ExampleMatcher.NullHandler.INCLUDE) {

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

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<>();
int index = 0;

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

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<>();
int index = 0;

相关文章

微信公众号

最新文章

更多