DATACMNS-1097 - Move classes to better matching packages.
Introduced new ExampleMatcherAccessor in data.support in favor of the now deprecated one in data.repository.core to avoid a dependency into the repositories subsystem to work with examples in general. Added Degraph based test in order to avoid future cyclic package dependency violations. Original pull request: #230. Related ticket: DATAMONGO-1721.
This commit is contained in:
committed by
Oliver Gierke
parent
f44255b9a8
commit
1fc25727cf
@@ -46,6 +46,7 @@ import org.springframework.util.Assert;
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
* @author Oliver Gierke
|
||||
* @author Jens Schauder
|
||||
* @param <T>
|
||||
* @since 1.12
|
||||
*/
|
||||
@@ -635,8 +636,9 @@ public class ExampleMatcher {
|
||||
* Match modes for treatment of {@link String} values.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
public static enum StringMatcher {
|
||||
public enum StringMatcher {
|
||||
|
||||
/**
|
||||
* Store specific default.
|
||||
|
||||
@@ -15,11 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.repository.core.support;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.data.domain.ExampleMatcher;
|
||||
import org.springframework.data.domain.ExampleMatcher.PropertySpecifier;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Accessor for the {@link ExampleMatcher} to use in modules that support query by example (QBE) querying.
|
||||
@@ -27,139 +23,22 @@ import org.springframework.util.Assert;
|
||||
* @author Mark Paluch
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
* @author Jens Schauder
|
||||
*
|
||||
* @since 1.12
|
||||
*
|
||||
* @deprecated use {@link org.springframework.data.support.ExampleMatcherAccessor} instead.
|
||||
*/
|
||||
public class ExampleMatcherAccessor {
|
||||
@Deprecated
|
||||
public class ExampleMatcherAccessor extends org.springframework.data.support.ExampleMatcherAccessor {
|
||||
|
||||
private final ExampleMatcher matcher;
|
||||
|
||||
/**
|
||||
* Creates a new {@link ExampleMatcherAccessor} for the given {@link ExampleMatcher}.
|
||||
*
|
||||
*
|
||||
* @param matcher must not be {@literal null}.
|
||||
*/
|
||||
public ExampleMatcherAccessor(ExampleMatcher matcher) {
|
||||
|
||||
Assert.notNull(matcher, "ExampleMatcher must not be null!");
|
||||
|
||||
this.matcher = matcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link PropertySpecifier}s of the underlying {@link ExampleMatcher}.
|
||||
*
|
||||
* @return unmodifiable {@link Collection} of {@link ExampleMatcher.PropertySpecifier}s.
|
||||
*/
|
||||
public Collection<ExampleMatcher.PropertySpecifier> getPropertySpecifiers() {
|
||||
return matcher.getPropertySpecifiers().getSpecifiers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the underlying {@link ExampleMatcher} contains a {@link PropertySpecifier} for the given path.
|
||||
*
|
||||
* @param path the dot-path identifying a property.
|
||||
* @return {@literal true} in case {@link ExampleMatcher.PropertySpecifier} defined for given path.
|
||||
*/
|
||||
public boolean hasPropertySpecifier(String path) {
|
||||
return matcher.getPropertySpecifiers().hasSpecifierForPath(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link ExampleMatcher.PropertySpecifier} for given path. <br />
|
||||
* Please check if {@link #hasPropertySpecifier(String)} to avoid running into {@literal null} values.
|
||||
*
|
||||
* @param path Dot-Path to property.
|
||||
* @return {@literal null} when no {@link ExampleMatcher.PropertySpecifier} defined for path.
|
||||
*/
|
||||
public ExampleMatcher.PropertySpecifier getPropertySpecifier(String path) {
|
||||
return matcher.getPropertySpecifiers().getForPath(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if at least one {@link ExampleMatcher.PropertySpecifier} defined.
|
||||
*/
|
||||
public boolean hasPropertySpecifiers() {
|
||||
return matcher.getPropertySpecifiers().hasValues();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link ExampleMatcher.StringMatcher} for a given path or return the default one if none defined.
|
||||
*
|
||||
* @param path
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public ExampleMatcher.StringMatcher getStringMatcherForPath(String path) {
|
||||
|
||||
if (!hasPropertySpecifier(path)) {
|
||||
return matcher.getDefaultStringMatcher();
|
||||
}
|
||||
|
||||
ExampleMatcher.PropertySpecifier specifier = getPropertySpecifier(path);
|
||||
return specifier.getStringMatcher() != null ? specifier.getStringMatcher() : matcher.getDefaultStringMatcher();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get defined null handling.
|
||||
*
|
||||
* @return never {@literal null}
|
||||
*/
|
||||
public ExampleMatcher.NullHandler getNullHandler() {
|
||||
return matcher.getNullHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get defined {@link ExampleMatcher.StringMatcher}.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public ExampleMatcher.StringMatcher getDefaultStringMatcher() {
|
||||
return matcher.getDefaultStringMatcher();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@literal true} if {@link String} should be matched with ignore case option.
|
||||
*/
|
||||
public boolean isIgnoreCaseEnabled() {
|
||||
return matcher.isIgnoreCaseEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param path
|
||||
* @return return {@literal true} if path was set to be ignored.
|
||||
*/
|
||||
public boolean isIgnoredPath(String path) {
|
||||
return matcher.isIgnoredPath(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ignore case flag for a given path or return the default one if none defined.
|
||||
*
|
||||
* @param path
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public boolean isIgnoreCaseForPath(String path) {
|
||||
|
||||
if (!hasPropertySpecifier(path)) {
|
||||
return matcher.isIgnoreCaseEnabled();
|
||||
}
|
||||
|
||||
ExampleMatcher.PropertySpecifier specifier = getPropertySpecifier(path);
|
||||
return specifier.getIgnoreCase() != null ? specifier.getIgnoreCase() : matcher.isIgnoreCaseEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ignore case flag for a given path or return {@link ExampleMatcher.NoOpPropertyValueTransformer} if none
|
||||
* defined.
|
||||
*
|
||||
* @param path
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public ExampleMatcher.PropertyValueTransformer getValueTransformerForPath(String path) {
|
||||
|
||||
if (!hasPropertySpecifier(path)) {
|
||||
return ExampleMatcher.NoOpPropertyValueTransformer.INSTANCE;
|
||||
}
|
||||
|
||||
return getPropertySpecifier(path).getPropertyValueTransformer();
|
||||
super(matcher);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* Copyright 2016-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.support;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.data.domain.ExampleMatcher;
|
||||
import org.springframework.data.domain.ExampleMatcher.PropertySpecifier;
|
||||
import org.springframework.data.util.StringMatcher;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Accessor for the {@link ExampleMatcher} to use in modules that support query by example (QBE) querying.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
* @author Jens Schauder
|
||||
* @since 1.12
|
||||
*/
|
||||
public class ExampleMatcherAccessor {
|
||||
|
||||
private final ExampleMatcher matcher;
|
||||
|
||||
/**
|
||||
* Creates a new {@link ExampleMatcherAccessor} for the given {@link ExampleMatcher}.
|
||||
*
|
||||
* @param matcher must not be {@literal null}.
|
||||
*/
|
||||
public ExampleMatcherAccessor(ExampleMatcher matcher) {
|
||||
|
||||
Assert.notNull(matcher, "ExampleMatcher must not be null!");
|
||||
|
||||
this.matcher = matcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link PropertySpecifier}s of the underlying {@link ExampleMatcher}.
|
||||
*
|
||||
* @return unmodifiable {@link Collection} of {@link ExampleMatcher.PropertySpecifier}s.
|
||||
*/
|
||||
public Collection<ExampleMatcher.PropertySpecifier> getPropertySpecifiers() {
|
||||
return matcher.getPropertySpecifiers().getSpecifiers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the underlying {@link ExampleMatcher} contains a {@link PropertySpecifier} for the given path.
|
||||
*
|
||||
* @param path the dot-path identifying a property.
|
||||
* @return {@literal true} in case {@link ExampleMatcher.PropertySpecifier} defined for given path.
|
||||
*/
|
||||
public boolean hasPropertySpecifier(String path) {
|
||||
return matcher.getPropertySpecifiers().hasSpecifierForPath(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link ExampleMatcher.PropertySpecifier} for given path. <br />
|
||||
* Please check if {@link #hasPropertySpecifier(String)} to avoid running into {@literal null} values.
|
||||
*
|
||||
* @param path Dot-Path to property.
|
||||
* @return {@literal null} when no {@link ExampleMatcher.PropertySpecifier} defined for path.
|
||||
*/
|
||||
public ExampleMatcher.PropertySpecifier getPropertySpecifier(String path) {
|
||||
return matcher.getPropertySpecifiers().getForPath(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if at least one {@link ExampleMatcher.PropertySpecifier} defined.
|
||||
*/
|
||||
public boolean hasPropertySpecifiers() {
|
||||
return matcher.getPropertySpecifiers().hasValues();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link ExampleMatcher.StringMatcher} for a given path or return the default one if none defined.
|
||||
*
|
||||
* @param path
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public ExampleMatcher.StringMatcher getStringMatcherForPath(String path) {
|
||||
|
||||
if (!hasPropertySpecifier(path)) {
|
||||
return matcher.getDefaultStringMatcher();
|
||||
}
|
||||
|
||||
ExampleMatcher.PropertySpecifier specifier = getPropertySpecifier(path);
|
||||
return specifier.getStringMatcher() != null ? specifier.getStringMatcher() : matcher.getDefaultStringMatcher();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get defined null handling.
|
||||
*
|
||||
* @return never {@literal null}
|
||||
*/
|
||||
public ExampleMatcher.NullHandler getNullHandler() {
|
||||
return matcher.getNullHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get defined {@link ExampleMatcher.StringMatcher}.
|
||||
*
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public ExampleMatcher.StringMatcher getDefaultStringMatcher() {
|
||||
return matcher.getDefaultStringMatcher();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@literal true} if {@link String} should be matched with ignore case option.
|
||||
*/
|
||||
public boolean isIgnoreCaseEnabled() {
|
||||
return matcher.isIgnoreCaseEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param path
|
||||
* @return return {@literal true} if path was set to be ignored.
|
||||
*/
|
||||
public boolean isIgnoredPath(String path) {
|
||||
return matcher.isIgnoredPath(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ignore case flag for a given path or return the default one if none defined.
|
||||
*
|
||||
* @param path
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public boolean isIgnoreCaseForPath(String path) {
|
||||
|
||||
if (!hasPropertySpecifier(path)) {
|
||||
return matcher.isIgnoreCaseEnabled();
|
||||
}
|
||||
|
||||
ExampleMatcher.PropertySpecifier specifier = getPropertySpecifier(path);
|
||||
return specifier.getIgnoreCase() != null ? specifier.getIgnoreCase() : matcher.isIgnoreCaseEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ignore case flag for a given path or return {@link ExampleMatcher.NoOpPropertyValueTransformer} if none
|
||||
* defined.
|
||||
*
|
||||
* @param path
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
public ExampleMatcher.PropertyValueTransformer getValueTransformerForPath(String path) {
|
||||
|
||||
if (!hasPropertySpecifier(path)) {
|
||||
return ExampleMatcher.NoOpPropertyValueTransformer.INSTANCE;
|
||||
}
|
||||
|
||||
return getPropertySpecifier(path).getPropertyValueTransformer();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user