Browse Source

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.
pull/231/head
Jens Schauder 9 years ago committed by Oliver Gierke
parent
commit
1fc25727cf
  1. 1
      .gitignore
  2. 6
      pom.xml
  3. 4
      src/main/java/org/springframework/data/domain/ExampleMatcher.java
  4. 137
      src/main/java/org/springframework/data/repository/core/support/ExampleMatcherAccessor.java
  5. 167
      src/main/java/org/springframework/data/support/ExampleMatcherAccessor.java
  6. 41
      src/test/java/org/springframework/data/DependencyTests.java
  7. 1
      src/test/java/org/springframework/data/repository/core/support/ExampleSpecificationAccessorUnitTests.java

1
.gitignore vendored

@ -12,3 +12,4 @@ src/ant/.ant-targets-upload-dist.xml @@ -12,3 +12,4 @@ src/ant/.ant-targets-upload-dist.xml
*.ipr
*.iws
/.idea/
*.graphml

6
pom.xml

@ -261,6 +261,12 @@ @@ -261,6 +261,12 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>de.schauderhaft.degraph</groupId>
<artifactId>degraph-check</artifactId>
<version>0.1.4</version>
</dependency>
</dependencies>
<build>

4
src/main/java/org/springframework/data/domain/ExampleMatcher.java

@ -46,6 +46,7 @@ import org.springframework.util.Assert; @@ -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 { @@ -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.

137
src/main/java/org/springframework/data/repository/core/support/ExampleMatcherAccessor.java

@ -15,11 +15,7 @@ @@ -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; @@ -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);
}
}

167
src/main/java/org/springframework/data/support/ExampleMatcherAccessor.java

@ -0,0 +1,167 @@ @@ -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();
}
}

41
src/test/java/org/springframework/data/DependencyTests.java

@ -0,0 +1,41 @@ @@ -0,0 +1,41 @@
/*
* Copyright 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;
import static de.schauderhaft.degraph.check.JCheck.*;
import static org.junit.Assert.*;
import org.junit.Test;
/**
* @author Jens Schauder
*/
public class DependencyTests {
@Test
public void noInternalPackageCycles() {
assertThat(
classpath() //
.noJars() //
.including("org.springframework.data.**") //
.filterClasspath("*target/classes") //
.printOnFailure("degraph.graphml"), //
violationFree() //
);
}
}

1
src/test/java/org/springframework/data/repository/core/support/ExampleSpecificationAccessorUnitTests.java

@ -26,6 +26,7 @@ import org.springframework.data.domain.ExampleMatcher.NoOpPropertyValueTransform @@ -26,6 +26,7 @@ import org.springframework.data.domain.ExampleMatcher.NoOpPropertyValueTransform
import org.springframework.data.domain.ExampleMatcher.NullHandler;
import org.springframework.data.domain.ExampleMatcher.PropertyValueTransformer;
import org.springframework.data.domain.ExampleMatcher.StringMatcher;
import org.springframework.data.support.ExampleMatcherAccessor;
/**
* Unit tests for {@link ExampleMatcherAccessor}.

Loading…
Cancel
Save