diff --git a/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java b/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java index 6623a9eda7..dc5282d063 100644 --- a/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java +++ b/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java @@ -29,6 +29,7 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.function.Predicate; +import java.util.regex.Pattern; import java.util.stream.Collectors; import org.apache.commons.logging.Log; @@ -93,6 +94,7 @@ * @author Mark Paluch * @author Mikael Klamra * @author Christoph Strobl + * @author Kamil KrzywaƄski */ public abstract class AbstractMappingContext, P extends PersistentProperty

> implements MappingContext, ApplicationEventPublisherAware, ApplicationContextAware, BeanFactoryAware, @@ -819,8 +821,8 @@ public boolean matches(Property property) { */ static class PropertyMatch { - private final @Nullable String namePattern; - private final @Nullable String typeName; + private final @Nullable Pattern namePatternRegex; + private final @Nullable String typeName; /** * Creates a new {@link PropertyMatch} for the given name pattern and type name. At least one of the parameters @@ -833,8 +835,8 @@ public PropertyMatch(@Nullable String namePattern, @Nullable String typeName) { Assert.isTrue(!((namePattern == null) && (typeName == null)), "Either name pattern or type name must be given"); - this.namePattern = namePattern; - this.typeName = typeName; + this.namePatternRegex = namePattern == null ? null : Pattern.compile(namePattern); + this.typeName = typeName; } /** @@ -869,9 +871,9 @@ public boolean matches(String name, Class type) { Assert.notNull(name, "Name must not be null"); Assert.notNull(type, "Type must not be null"); - if ((namePattern != null) && !name.matches(namePattern)) { - return false; - } + if (namePatternRegex != null && !namePatternRegex.matcher(name).matches()) { + return false; + } if ((typeName != null) && !type.getName().equals(typeName)) { return false;