Skip to content

Commit 430aa6d

Browse files
committed
spring-projects#282 - Bring new code in line with Spring Data code formatting settings
1 parent 616fa0c commit 430aa6d

File tree

11 files changed

+1317
-1344
lines changed

11 files changed

+1317
-1344
lines changed

Diff for: src/main/java/org/springframework/data/r2dbc/repository/query/ConditionFactory.java

+249-250
Large diffs are not rendered by default.

Diff for: src/main/java/org/springframework/data/r2dbc/repository/query/LikeEscaper.java

+31-31
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
*/
1616
package org.springframework.data.r2dbc.repository.query;
1717

18-
import org.springframework.lang.Nullable;
19-
2018
import java.util.Arrays;
2119
import java.util.List;
2220

21+
import org.springframework.lang.Nullable;
22+
2323
/**
2424
* Helper class encapsulating an escape character for LIKE queries and the actually usage of it in escaping
2525
* {@link String}s.
@@ -30,37 +30,37 @@
3030
* @author Roman Chigvintsev
3131
*/
3232
public class LikeEscaper {
33-
public static final LikeEscaper DEFAULT = LikeEscaper.of('\\');
33+
public static final LikeEscaper DEFAULT = LikeEscaper.of('\\');
3434

35-
private final char escapeCharacter;
36-
private final List<String> toReplace;
35+
private final char escapeCharacter;
36+
private final List<String> toReplace;
3737

38-
private LikeEscaper(char escapeCharacter) {
39-
this.escapeCharacter = escapeCharacter;
40-
this.toReplace = Arrays.asList(String.valueOf(escapeCharacter), "_", "%");
41-
}
38+
private LikeEscaper(char escapeCharacter) {
39+
this.escapeCharacter = escapeCharacter;
40+
this.toReplace = Arrays.asList(String.valueOf(escapeCharacter), "_", "%");
41+
}
4242

43-
/**
44-
* Creates new instance of this class with the given escape character.
45-
*
46-
* @param escapeCharacter escape character
47-
* @return new instance of {@link LikeEscaper}
48-
*/
49-
public static LikeEscaper of(char escapeCharacter) {
50-
return new LikeEscaper(escapeCharacter);
51-
}
43+
/**
44+
* Creates new instance of this class with the given escape character.
45+
*
46+
* @param escapeCharacter escape character
47+
* @return new instance of {@link LikeEscaper}
48+
*/
49+
public static LikeEscaper of(char escapeCharacter) {
50+
return new LikeEscaper(escapeCharacter);
51+
}
5252

53-
/**
54-
* Escapes all special like characters ({@code _}, {@code %}) using the configured escape character.
55-
*
56-
* @param value value to be escaped
57-
* @return escaped value
58-
*/
59-
@Nullable
60-
public String escape(@Nullable String value) {
61-
if (value == null) {
62-
return null;
63-
}
64-
return toReplace.stream().reduce(value, (it, character) -> it.replace(character, escapeCharacter + character));
65-
}
53+
/**
54+
* Escapes all special like characters ({@code _}, {@code %}) using the configured escape character.
55+
*
56+
* @param value value to be escaped
57+
* @return escaped value
58+
*/
59+
@Nullable
60+
public String escape(@Nullable String value) {
61+
if (value == null) {
62+
return null;
63+
}
64+
return toReplace.stream().reduce(value, (it, character) -> it.replace(character, escapeCharacter + character));
65+
}
6666
}

Diff for: src/main/java/org/springframework/data/r2dbc/repository/query/ParameterMetadata.java

+44-47
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import lombok.AllArgsConstructor;
1919
import lombok.Builder;
2020
import lombok.NonNull;
21+
2122
import org.springframework.data.repository.query.parser.Part;
2223
import org.springframework.lang.Nullable;
2324
import org.springframework.util.Assert;
@@ -28,55 +29,51 @@
2829
@Builder
2930
@AllArgsConstructor
3031
class ParameterMetadata {
31-
@Nullable
32-
private final String name;
33-
@NonNull
34-
private final Class<?> type;
35-
@NonNull
36-
private final Part.Type partType;
37-
private final boolean isNullParameter;
38-
@NonNull
39-
private final LikeEscaper likeEscaper;
32+
@Nullable private final String name;
33+
@NonNull private final Class<?> type;
34+
@NonNull private final Part.Type partType;
35+
private final boolean isNullParameter;
36+
@NonNull private final LikeEscaper likeEscaper;
4037

41-
/**
42-
* Prepares parameter value before it's actually bound to the query.
43-
*
44-
* @param value must not be {@literal null}
45-
* @return prepared query parameter value
46-
*/
47-
public Object prepare(Object value) {
48-
Assert.notNull(value, "Value must not be null!");
49-
if (String.class.equals(type)) {
50-
switch (partType) {
51-
case STARTING_WITH:
52-
return String.format("%s%%", likeEscaper.escape(value.toString()));
53-
case ENDING_WITH:
54-
return String.format("%%%s", likeEscaper.escape(value.toString()));
55-
case CONTAINING:
56-
case NOT_CONTAINING:
57-
return String.format("%%%s%%", likeEscaper.escape(value.toString()));
58-
default:
59-
return value;
60-
}
61-
}
62-
return value;
63-
}
38+
/**
39+
* Prepares parameter value before it's actually bound to the query.
40+
*
41+
* @param value must not be {@literal null}
42+
* @return prepared query parameter value
43+
*/
44+
public Object prepare(Object value) {
45+
Assert.notNull(value, "Value must not be null!");
46+
if (String.class.equals(type)) {
47+
switch (partType) {
48+
case STARTING_WITH:
49+
return String.format("%s%%", likeEscaper.escape(value.toString()));
50+
case ENDING_WITH:
51+
return String.format("%%%s", likeEscaper.escape(value.toString()));
52+
case CONTAINING:
53+
case NOT_CONTAINING:
54+
return String.format("%%%s%%", likeEscaper.escape(value.toString()));
55+
default:
56+
return value;
57+
}
58+
}
59+
return value;
60+
}
6461

65-
@Nullable
66-
public String getName() {
67-
return name;
68-
}
62+
@Nullable
63+
public String getName() {
64+
return name;
65+
}
6966

70-
public Class<?> getType() {
71-
return type;
72-
}
67+
public Class<?> getType() {
68+
return type;
69+
}
7370

74-
/**
75-
* Determines whether parameter value should be translated to {@literal IS NULL} condition.
76-
*
77-
* @return {@literal true} if parameter value should be translated to {@literal IS NULL} condition
78-
*/
79-
public boolean isIsNullParameter() {
80-
return isNullParameter;
81-
}
71+
/**
72+
* Determines whether parameter value should be translated to {@literal IS NULL} condition.
73+
*
74+
* @return {@literal true} if parameter value should be translated to {@literal IS NULL} condition
75+
*/
76+
public boolean isIsNullParameter() {
77+
return isNullParameter;
78+
}
8279
}

Diff for: src/main/java/org/springframework/data/r2dbc/repository/query/ParameterMetadataProvider.java

+70-75
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@
1515
*/
1616
package org.springframework.data.r2dbc.repository.query;
1717

18+
import java.util.ArrayList;
19+
import java.util.Iterator;
20+
import java.util.List;
21+
1822
import org.springframework.data.relational.repository.query.RelationalParameterAccessor;
1923
import org.springframework.data.repository.query.Parameter;
2024
import org.springframework.data.repository.query.Parameters;
2125
import org.springframework.data.repository.query.parser.Part;
2226
import org.springframework.lang.Nullable;
2327
import org.springframework.util.Assert;
2428

25-
import java.util.ArrayList;
26-
import java.util.Iterator;
27-
import java.util.List;
28-
2929
/**
3030
* Helper class to allow easy creation of {@link ParameterMetadata}s.
3131
* <p>
@@ -35,85 +35,80 @@
3535
* @author Roman Chigvintsev
3636
*/
3737
class ParameterMetadataProvider {
38-
private static final Object VALUE_PLACEHOLDER = new Object();
38+
private static final Object VALUE_PLACEHOLDER = new Object();
3939

40-
private final Iterator<? extends Parameter> bindableParameterIterator;
41-
@Nullable
42-
private final Iterator<Object> bindableParameterValueIterator;
43-
private final List<ParameterMetadata> parameterMetadata = new ArrayList<>();
44-
private final LikeEscaper likeEscaper;
40+
private final Iterator<? extends Parameter> bindableParameterIterator;
41+
@Nullable private final Iterator<Object> bindableParameterValueIterator;
42+
private final List<ParameterMetadata> parameterMetadata = new ArrayList<>();
43+
private final LikeEscaper likeEscaper;
4544

46-
/**
47-
* Creates new instance of this class with the given {@link RelationalParameterAccessor} and {@link LikeEscaper}.
48-
*
49-
* @param accessor relational parameter accessor (must not be {@literal null}).
50-
* @param likeEscaper escaper for LIKE operator parameters (must not be {@literal null})
51-
*/
52-
ParameterMetadataProvider(RelationalParameterAccessor accessor, LikeEscaper likeEscaper) {
53-
this(accessor.getBindableParameters(), accessor.iterator(), likeEscaper);
54-
}
45+
/**
46+
* Creates new instance of this class with the given {@link RelationalParameterAccessor} and {@link LikeEscaper}.
47+
*
48+
* @param accessor relational parameter accessor (must not be {@literal null}).
49+
* @param likeEscaper escaper for LIKE operator parameters (must not be {@literal null})
50+
*/
51+
ParameterMetadataProvider(RelationalParameterAccessor accessor, LikeEscaper likeEscaper) {
52+
this(accessor.getBindableParameters(), accessor.iterator(), likeEscaper);
53+
}
5554

56-
/**
57-
* Creates new instance of this class with the given {@link Parameters} and {@link LikeEscaper}.
58-
*
59-
* @param parameters method parameters (must not be {@literal null})
60-
* @param likeEscaper escaper for LIKE operator parameters (must not be {@literal null})
61-
*/
62-
ParameterMetadataProvider(Parameters<?, ?> parameters, LikeEscaper likeEscaper) {
63-
this(parameters, null, likeEscaper);
64-
}
55+
/**
56+
* Creates new instance of this class with the given {@link Parameters} and {@link LikeEscaper}.
57+
*
58+
* @param parameters method parameters (must not be {@literal null})
59+
* @param likeEscaper escaper for LIKE operator parameters (must not be {@literal null})
60+
*/
61+
ParameterMetadataProvider(Parameters<?, ?> parameters, LikeEscaper likeEscaper) {
62+
this(parameters, null, likeEscaper);
63+
}
6564

66-
/**
67-
* Creates new instance of this class with the given {@link Parameters}, {@link Iterator} over all bindable
65+
/**
66+
* Creates new instance of this class with the given {@link Parameters}, {@link Iterator} over all bindable
6867
* parameter values and {@link LikeEscaper}.
69-
*
70-
* @param bindableParameterValueIterator iterator over bindable parameter values
71-
* @param parameters method parameters (must not be {@literal null})
72-
* @param likeEscaper escaper for LIKE operator parameters (must not be {@literal null})
73-
*/
74-
private ParameterMetadataProvider(Parameters<?, ?> parameters,
75-
@Nullable Iterator<Object> bindableParameterValueIterator,
76-
LikeEscaper likeEscaper) {
77-
Assert.notNull(parameters, "Parameters must not be null!");
78-
Assert.notNull(likeEscaper, "Like escaper must not be null!");
68+
*
69+
* @param bindableParameterValueIterator iterator over bindable parameter values
70+
* @param parameters method parameters (must not be {@literal null})
71+
* @param likeEscaper escaper for LIKE operator parameters (must not be {@literal null})
72+
*/
73+
private ParameterMetadataProvider(Parameters<?, ?> parameters,
74+
@Nullable Iterator<Object> bindableParameterValueIterator, LikeEscaper likeEscaper) {
75+
Assert.notNull(parameters, "Parameters must not be null!");
76+
Assert.notNull(likeEscaper, "Like escaper must not be null!");
7977

80-
this.bindableParameterIterator = parameters.getBindableParameters().iterator();
81-
this.bindableParameterValueIterator = bindableParameterValueIterator;
82-
this.likeEscaper = likeEscaper;
83-
}
78+
this.bindableParameterIterator = parameters.getBindableParameters().iterator();
79+
this.bindableParameterValueIterator = bindableParameterValueIterator;
80+
this.likeEscaper = likeEscaper;
81+
}
8482

85-
/**
86-
* Creates new instance of {@link ParameterMetadata} for the given {@link Part} and next {@link Parameter}.
87-
*/
88-
public ParameterMetadata next(Part part) {
89-
Assert.isTrue(bindableParameterIterator.hasNext(),
90-
() -> String.format("No parameter available for part %s.", part));
91-
Parameter parameter = bindableParameterIterator.next();
92-
ParameterMetadata metadata = ParameterMetadata.builder()
93-
.type(parameter.getType())
94-
.partType(part.getType())
95-
.name(getParameterName(parameter, part.getProperty().getSegment()))
96-
.isNullParameter(getParameterValue() == null && Part.Type.SIMPLE_PROPERTY.equals(part.getType()))
97-
.likeEscaper(likeEscaper)
98-
.build();
99-
parameterMetadata.add(metadata);
100-
return metadata;
101-
}
83+
/**
84+
* Creates new instance of {@link ParameterMetadata} for the given {@link Part} and next {@link Parameter}.
85+
*/
86+
public ParameterMetadata next(Part part) {
87+
Assert.isTrue(bindableParameterIterator.hasNext(),
88+
() -> String.format("No parameter available for part %s.", part));
89+
Parameter parameter = bindableParameterIterator.next();
90+
ParameterMetadata metadata = ParameterMetadata.builder().type(parameter.getType()).partType(part.getType())
91+
.name(getParameterName(parameter, part.getProperty().getSegment()))
92+
.isNullParameter(getParameterValue() == null && Part.Type.SIMPLE_PROPERTY.equals(part.getType()))
93+
.likeEscaper(likeEscaper).build();
94+
parameterMetadata.add(metadata);
95+
return metadata;
96+
}
10297

103-
public ParameterMetadata getParameterMetadata(int index) {
104-
return parameterMetadata.get(index);
105-
}
98+
public ParameterMetadata getParameterMetadata(int index) {
99+
return parameterMetadata.get(index);
100+
}
106101

107-
@Nullable
108-
private String getParameterName(Parameter parameter, String defaultName) {
109-
if (parameter.isExplicitlyNamed()) {
110-
return parameter.getName().orElseThrow(() -> new IllegalArgumentException("Parameter needs to be named"));
111-
}
112-
return defaultName;
113-
}
102+
@Nullable
103+
private String getParameterName(Parameter parameter, String defaultName) {
104+
if (parameter.isExplicitlyNamed()) {
105+
return parameter.getName().orElseThrow(() -> new IllegalArgumentException("Parameter needs to be named"));
106+
}
107+
return defaultName;
108+
}
114109

115-
@Nullable
116-
private Object getParameterValue() {
117-
return bindableParameterValueIterator == null ? VALUE_PLACEHOLDER : bindableParameterValueIterator.next();
118-
}
110+
@Nullable
111+
private Object getParameterValue() {
112+
return bindableParameterValueIterator == null ? VALUE_PLACEHOLDER : bindableParameterValueIterator.next();
113+
}
119114
}

0 commit comments

Comments
 (0)