Skip to content

Commit 1fc2572

Browse files
schauderodrotbohm
authored andcommitted
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: spring-projects#230. Related ticket: DATAMONGO-1721.
1 parent f44255b commit 1fc2572

File tree

7 files changed

+227
-130
lines changed

7 files changed

+227
-130
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ src/ant/.ant-targets-upload-dist.xml
1212
*.ipr
1313
*.iws
1414
/.idea/
15+
*.graphml

pom.xml

+6
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,12 @@
261261
<optional>true</optional>
262262
</dependency>
263263

264+
<dependency>
265+
<groupId>de.schauderhaft.degraph</groupId>
266+
<artifactId>degraph-check</artifactId>
267+
<version>0.1.4</version>
268+
</dependency>
269+
264270
</dependencies>
265271

266272
<build>

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
* @author Christoph Strobl
4747
* @author Mark Paluch
4848
* @author Oliver Gierke
49+
* @author Jens Schauder
4950
* @param <T>
5051
* @since 1.12
5152
*/
@@ -635,8 +636,9 @@ public static GenericPropertyMatcher regex() {
635636
* Match modes for treatment of {@link String} values.
636637
*
637638
* @author Christoph Strobl
639+
* @author Jens Schauder
638640
*/
639-
public static enum StringMatcher {
641+
public enum StringMatcher {
640642

641643
/**
642644
* Store specific default.

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

+8-129
Original file line numberDiff line numberDiff line change
@@ -15,151 +15,30 @@
1515
*/
1616
package org.springframework.data.repository.core.support;
1717

18-
import java.util.Collection;
19-
2018
import org.springframework.data.domain.ExampleMatcher;
21-
import org.springframework.data.domain.ExampleMatcher.PropertySpecifier;
22-
import org.springframework.util.Assert;
2319

2420
/**
2521
* Accessor for the {@link ExampleMatcher} to use in modules that support query by example (QBE) querying.
2622
*
2723
* @author Mark Paluch
2824
* @author Oliver Gierke
2925
* @author Christoph Strobl
26+
* @author Jens Schauder
27+
*
3028
* @since 1.12
29+
*
30+
* @deprecated use {@link org.springframework.data.support.ExampleMatcherAccessor} instead.
3131
*/
32-
public class ExampleMatcherAccessor {
32+
@Deprecated
33+
public class ExampleMatcherAccessor extends org.springframework.data.support.ExampleMatcherAccessor {
3334

34-
private final ExampleMatcher matcher;
3535

3636
/**
3737
* Creates a new {@link ExampleMatcherAccessor} for the given {@link ExampleMatcher}.
38-
*
38+
*
3939
* @param matcher must not be {@literal null}.
4040
*/
4141
public ExampleMatcherAccessor(ExampleMatcher matcher) {
42-
43-
Assert.notNull(matcher, "ExampleMatcher must not be null!");
44-
45-
this.matcher = matcher;
46-
}
47-
48-
/**
49-
* Returns the {@link PropertySpecifier}s of the underlying {@link ExampleMatcher}.
50-
*
51-
* @return unmodifiable {@link Collection} of {@link ExampleMatcher.PropertySpecifier}s.
52-
*/
53-
public Collection<ExampleMatcher.PropertySpecifier> getPropertySpecifiers() {
54-
return matcher.getPropertySpecifiers().getSpecifiers();
55-
}
56-
57-
/**
58-
* Returns whether the underlying {@link ExampleMatcher} contains a {@link PropertySpecifier} for the given path.
59-
*
60-
* @param path the dot-path identifying a property.
61-
* @return {@literal true} in case {@link ExampleMatcher.PropertySpecifier} defined for given path.
62-
*/
63-
public boolean hasPropertySpecifier(String path) {
64-
return matcher.getPropertySpecifiers().hasSpecifierForPath(path);
65-
}
66-
67-
/**
68-
* Get the {@link ExampleMatcher.PropertySpecifier} for given path. <br />
69-
* Please check if {@link #hasPropertySpecifier(String)} to avoid running into {@literal null} values.
70-
*
71-
* @param path Dot-Path to property.
72-
* @return {@literal null} when no {@link ExampleMatcher.PropertySpecifier} defined for path.
73-
*/
74-
public ExampleMatcher.PropertySpecifier getPropertySpecifier(String path) {
75-
return matcher.getPropertySpecifiers().getForPath(path);
76-
}
77-
78-
/**
79-
* @return true if at least one {@link ExampleMatcher.PropertySpecifier} defined.
80-
*/
81-
public boolean hasPropertySpecifiers() {
82-
return matcher.getPropertySpecifiers().hasValues();
83-
}
84-
85-
/**
86-
* Get the {@link ExampleMatcher.StringMatcher} for a given path or return the default one if none defined.
87-
*
88-
* @param path
89-
* @return never {@literal null}.
90-
*/
91-
public ExampleMatcher.StringMatcher getStringMatcherForPath(String path) {
92-
93-
if (!hasPropertySpecifier(path)) {
94-
return matcher.getDefaultStringMatcher();
95-
}
96-
97-
ExampleMatcher.PropertySpecifier specifier = getPropertySpecifier(path);
98-
return specifier.getStringMatcher() != null ? specifier.getStringMatcher() : matcher.getDefaultStringMatcher();
99-
}
100-
101-
/**
102-
* Get defined null handling.
103-
*
104-
* @return never {@literal null}
105-
*/
106-
public ExampleMatcher.NullHandler getNullHandler() {
107-
return matcher.getNullHandler();
108-
}
109-
110-
/**
111-
* Get defined {@link ExampleMatcher.StringMatcher}.
112-
*
113-
* @return never {@literal null}.
114-
*/
115-
public ExampleMatcher.StringMatcher getDefaultStringMatcher() {
116-
return matcher.getDefaultStringMatcher();
117-
}
118-
119-
/**
120-
* @return {@literal true} if {@link String} should be matched with ignore case option.
121-
*/
122-
public boolean isIgnoreCaseEnabled() {
123-
return matcher.isIgnoreCaseEnabled();
124-
}
125-
126-
/**
127-
* @param path
128-
* @return return {@literal true} if path was set to be ignored.
129-
*/
130-
public boolean isIgnoredPath(String path) {
131-
return matcher.isIgnoredPath(path);
132-
}
133-
134-
/**
135-
* Get the ignore case flag for a given path or return the default one if none defined.
136-
*
137-
* @param path
138-
* @return never {@literal null}.
139-
*/
140-
public boolean isIgnoreCaseForPath(String path) {
141-
142-
if (!hasPropertySpecifier(path)) {
143-
return matcher.isIgnoreCaseEnabled();
144-
}
145-
146-
ExampleMatcher.PropertySpecifier specifier = getPropertySpecifier(path);
147-
return specifier.getIgnoreCase() != null ? specifier.getIgnoreCase() : matcher.isIgnoreCaseEnabled();
148-
}
149-
150-
/**
151-
* Get the ignore case flag for a given path or return {@link ExampleMatcher.NoOpPropertyValueTransformer} if none
152-
* defined.
153-
*
154-
* @param path
155-
* @return never {@literal null}.
156-
*/
157-
public ExampleMatcher.PropertyValueTransformer getValueTransformerForPath(String path) {
158-
159-
if (!hasPropertySpecifier(path)) {
160-
return ExampleMatcher.NoOpPropertyValueTransformer.INSTANCE;
161-
}
162-
163-
return getPropertySpecifier(path).getPropertyValueTransformer();
42+
super(matcher);
16443
}
16544
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
/*
2+
* Copyright 2016-2017 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.support;
17+
18+
import java.util.Collection;
19+
20+
import org.springframework.data.domain.ExampleMatcher;
21+
import org.springframework.data.domain.ExampleMatcher.PropertySpecifier;
22+
import org.springframework.data.util.StringMatcher;
23+
import org.springframework.util.Assert;
24+
25+
/**
26+
* Accessor for the {@link ExampleMatcher} to use in modules that support query by example (QBE) querying.
27+
*
28+
* @author Mark Paluch
29+
* @author Oliver Gierke
30+
* @author Christoph Strobl
31+
* @author Jens Schauder
32+
* @since 1.12
33+
*/
34+
public class ExampleMatcherAccessor {
35+
36+
private final ExampleMatcher matcher;
37+
38+
/**
39+
* Creates a new {@link ExampleMatcherAccessor} for the given {@link ExampleMatcher}.
40+
*
41+
* @param matcher must not be {@literal null}.
42+
*/
43+
public ExampleMatcherAccessor(ExampleMatcher matcher) {
44+
45+
Assert.notNull(matcher, "ExampleMatcher must not be null!");
46+
47+
this.matcher = matcher;
48+
}
49+
50+
/**
51+
* Returns the {@link PropertySpecifier}s of the underlying {@link ExampleMatcher}.
52+
*
53+
* @return unmodifiable {@link Collection} of {@link ExampleMatcher.PropertySpecifier}s.
54+
*/
55+
public Collection<ExampleMatcher.PropertySpecifier> getPropertySpecifiers() {
56+
return matcher.getPropertySpecifiers().getSpecifiers();
57+
}
58+
59+
/**
60+
* Returns whether the underlying {@link ExampleMatcher} contains a {@link PropertySpecifier} for the given path.
61+
*
62+
* @param path the dot-path identifying a property.
63+
* @return {@literal true} in case {@link ExampleMatcher.PropertySpecifier} defined for given path.
64+
*/
65+
public boolean hasPropertySpecifier(String path) {
66+
return matcher.getPropertySpecifiers().hasSpecifierForPath(path);
67+
}
68+
69+
/**
70+
* Get the {@link ExampleMatcher.PropertySpecifier} for given path. <br />
71+
* Please check if {@link #hasPropertySpecifier(String)} to avoid running into {@literal null} values.
72+
*
73+
* @param path Dot-Path to property.
74+
* @return {@literal null} when no {@link ExampleMatcher.PropertySpecifier} defined for path.
75+
*/
76+
public ExampleMatcher.PropertySpecifier getPropertySpecifier(String path) {
77+
return matcher.getPropertySpecifiers().getForPath(path);
78+
}
79+
80+
/**
81+
* @return true if at least one {@link ExampleMatcher.PropertySpecifier} defined.
82+
*/
83+
public boolean hasPropertySpecifiers() {
84+
return matcher.getPropertySpecifiers().hasValues();
85+
}
86+
87+
/**
88+
* Get the {@link ExampleMatcher.StringMatcher} for a given path or return the default one if none defined.
89+
*
90+
* @param path
91+
* @return never {@literal null}.
92+
*/
93+
public ExampleMatcher.StringMatcher getStringMatcherForPath(String path) {
94+
95+
if (!hasPropertySpecifier(path)) {
96+
return matcher.getDefaultStringMatcher();
97+
}
98+
99+
ExampleMatcher.PropertySpecifier specifier = getPropertySpecifier(path);
100+
return specifier.getStringMatcher() != null ? specifier.getStringMatcher() : matcher.getDefaultStringMatcher();
101+
}
102+
103+
/**
104+
* Get defined null handling.
105+
*
106+
* @return never {@literal null}
107+
*/
108+
public ExampleMatcher.NullHandler getNullHandler() {
109+
return matcher.getNullHandler();
110+
}
111+
112+
/**
113+
* Get defined {@link ExampleMatcher.StringMatcher}.
114+
*
115+
* @return never {@literal null}.
116+
*/
117+
public ExampleMatcher.StringMatcher getDefaultStringMatcher() {
118+
return matcher.getDefaultStringMatcher();
119+
}
120+
121+
/**
122+
* @return {@literal true} if {@link String} should be matched with ignore case option.
123+
*/
124+
public boolean isIgnoreCaseEnabled() {
125+
return matcher.isIgnoreCaseEnabled();
126+
}
127+
128+
/**
129+
* @param path
130+
* @return return {@literal true} if path was set to be ignored.
131+
*/
132+
public boolean isIgnoredPath(String path) {
133+
return matcher.isIgnoredPath(path);
134+
}
135+
136+
/**
137+
* Get the ignore case flag for a given path or return the default one if none defined.
138+
*
139+
* @param path
140+
* @return never {@literal null}.
141+
*/
142+
public boolean isIgnoreCaseForPath(String path) {
143+
144+
if (!hasPropertySpecifier(path)) {
145+
return matcher.isIgnoreCaseEnabled();
146+
}
147+
148+
ExampleMatcher.PropertySpecifier specifier = getPropertySpecifier(path);
149+
return specifier.getIgnoreCase() != null ? specifier.getIgnoreCase() : matcher.isIgnoreCaseEnabled();
150+
}
151+
152+
/**
153+
* Get the ignore case flag for a given path or return {@link ExampleMatcher.NoOpPropertyValueTransformer} if none
154+
* defined.
155+
*
156+
* @param path
157+
* @return never {@literal null}.
158+
*/
159+
public ExampleMatcher.PropertyValueTransformer getValueTransformerForPath(String path) {
160+
161+
if (!hasPropertySpecifier(path)) {
162+
return ExampleMatcher.NoOpPropertyValueTransformer.INSTANCE;
163+
}
164+
165+
return getPropertySpecifier(path).getPropertyValueTransformer();
166+
}
167+
}

0 commit comments

Comments
 (0)