Skip to content

Commit 490eef0

Browse files
committed
Address review findings.
1 parent e88a895 commit 490eef0

11 files changed

+105
-65
lines changed

Diff for: spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/DeleteSpecification.java

+19-9
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131

3232
/**
3333
* Specification in the sense of Domain Driven Design to handle Criteria Deletes.
34+
* <p>
35+
* Specifications can be composed into higher order functions from other specifications using
36+
* {@link #and(DeleteSpecification)}, {@link #or(DeleteSpecification)} or factory methods such as
37+
* {@link #allOf(Iterable)}. Composition considers whether one or more specifications contribute to the overall
38+
* predicate by returning a {@link Predicate} or {@literal null}. Specifications returning {@literal null} are
39+
* considered to not contribute to the overall predicate and their result is not considered in the final predicate.
3440
*
3541
* @author Mark Paluch
3642
* @since 4.0
@@ -44,7 +50,7 @@ public interface DeleteSpecification<T> extends Serializable {
4450
* @param <T> the type of the {@link Root} the resulting {@literal DeleteSpecification} operates on.
4551
* @return guaranteed to be not {@literal null}.
4652
*/
47-
static <T> DeleteSpecification<T> all() {
53+
static <T> DeleteSpecification<T> unrestricted() {
4854
return (root, query, builder) -> null;
4955
}
5056

@@ -150,13 +156,14 @@ static <T> DeleteSpecification<T> not(DeleteSpecification<T> spec) {
150156

151157
return (root, delete, builder) -> {
152158

153-
Predicate not = spec.toPredicate(root, delete, builder);
154-
return not != null ? builder.not(not) : null;
159+
Predicate predicate = spec.toPredicate(root, delete, builder);
160+
return predicate != null ? builder.not(predicate) : null;
155161
};
156162
}
157163

158164
/**
159-
* Applies an AND operation to all the given {@link DeleteSpecification}s.
165+
* Applies an AND operation to all the given {@link DeleteSpecification}s. If {@code specifications} is empty, the
166+
* resulting {@link DeleteSpecification} will be unrestricted applying to all objects.
160167
*
161168
* @param specifications the {@link DeleteSpecification}s to compose.
162169
* @return the conjunction of the specifications.
@@ -169,7 +176,8 @@ static <T> DeleteSpecification<T> allOf(DeleteSpecification<T>... specifications
169176
}
170177

171178
/**
172-
* Applies an AND operation to all the given {@link DeleteSpecification}s.
179+
* Applies an AND operation to all the given {@link DeleteSpecification}s. If {@code specifications} is empty, the
180+
* resulting {@link DeleteSpecification} will be unrestricted applying to all objects.
173181
*
174182
* @param specifications the {@link DeleteSpecification}s to compose.
175183
* @return the conjunction of the specifications.
@@ -179,11 +187,12 @@ static <T> DeleteSpecification<T> allOf(DeleteSpecification<T>... specifications
179187
static <T> DeleteSpecification<T> allOf(Iterable<DeleteSpecification<T>> specifications) {
180188

181189
return StreamSupport.stream(specifications.spliterator(), false) //
182-
.reduce(DeleteSpecification.all(), DeleteSpecification::and);
190+
.reduce(DeleteSpecification.unrestricted(), DeleteSpecification::and);
183191
}
184192

185193
/**
186-
* Applies an OR operation to all the given {@link DeleteSpecification}s.
194+
* Applies an OR operation to all the given {@link DeleteSpecification}s. If {@code specifications} is empty, the
195+
* resulting {@link DeleteSpecification} will be unrestricted applying to all objects.
187196
*
188197
* @param specifications the {@link DeleteSpecification}s to compose.
189198
* @return the disjunction of the specifications.
@@ -196,7 +205,8 @@ static <T> DeleteSpecification<T> anyOf(DeleteSpecification<T>... specifications
196205
}
197206

198207
/**
199-
* Applies an OR operation to all the given {@link DeleteSpecification}s.
208+
* Applies an OR operation to all the given {@link DeleteSpecification}s. If {@code specifications} is empty, the
209+
* resulting {@link DeleteSpecification} will be unrestricted applying to all objects.
200210
*
201211
* @param specifications the {@link DeleteSpecification}s to compose.
202212
* @return the disjunction of the specifications.
@@ -206,7 +216,7 @@ static <T> DeleteSpecification<T> anyOf(DeleteSpecification<T>... specifications
206216
static <T> DeleteSpecification<T> anyOf(Iterable<DeleteSpecification<T>> specifications) {
207217

208218
return StreamSupport.stream(specifications.spliterator(), false) //
209-
.reduce(DeleteSpecification.all(), DeleteSpecification::or);
219+
.reduce(DeleteSpecification.unrestricted(), DeleteSpecification::or);
210220
}
211221

212222
/**

Diff for: spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/PredicateSpecification.java

+19-9
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030

3131
/**
3232
* Specification in the sense of Domain Driven Design.
33+
* <p>
34+
* Specifications can be composed into higher order functions from other specifications using
35+
* {@link #and(PredicateSpecification)}, {@link #or(PredicateSpecification)} or factory methods such as
36+
* {@link #allOf(Iterable)}. Composition considers whether one or more specifications contribute to the overall
37+
* predicate by returning a {@link Predicate} or {@literal null}. Specifications returning {@literal null} are
38+
* considered to not contribute to the overall predicate and their result is not considered in the final predicate.
3339
*
3440
* @author Mark Paluch
3541
* @since 4.0
@@ -42,7 +48,7 @@ public interface PredicateSpecification<T> extends Serializable {
4248
* @param <T> the type of the {@link Root} the resulting {@literal PredicateSpecification} operates on.
4349
* @return guaranteed to be not {@literal null}.
4450
*/
45-
static <T> PredicateSpecification<T> all() {
51+
static <T> PredicateSpecification<T> unrestricted() {
4652
return (root, builder) -> null;
4753
}
4854

@@ -104,13 +110,14 @@ static <T> PredicateSpecification<T> not(PredicateSpecification<T> spec) {
104110

105111
return (root, builder) -> {
106112

107-
Predicate not = spec.toPredicate(root, builder);
108-
return not != null ? builder.not(not) : null;
113+
Predicate predicate = spec.toPredicate(root, builder);
114+
return predicate != null ? builder.not(predicate) : null;
109115
};
110116
}
111117

112118
/**
113-
* Applies an AND operation to all the given {@link PredicateSpecification}s.
119+
* Applies an AND operation to all the given {@link PredicateSpecification}s. If {@code specifications} is empty, the
120+
* resulting {@link PredicateSpecification} will be unrestricted applying to all objects.
114121
*
115122
* @param specifications the {@link PredicateSpecification}s to compose.
116123
* @return the conjunction of the specifications.
@@ -123,7 +130,8 @@ static <T> PredicateSpecification<T> allOf(PredicateSpecification<T>... specific
123130
}
124131

125132
/**
126-
* Applies an AND operation to all the given {@link PredicateSpecification}s.
133+
* Applies an AND operation to all the given {@link PredicateSpecification}s. If {@code specifications} is empty, the
134+
* resulting {@link PredicateSpecification} will be unrestricted applying to all objects.
127135
*
128136
* @param specifications the {@link PredicateSpecification}s to compose.
129137
* @return the conjunction of the specifications.
@@ -133,11 +141,12 @@ static <T> PredicateSpecification<T> allOf(PredicateSpecification<T>... specific
133141
static <T> PredicateSpecification<T> allOf(Iterable<PredicateSpecification<T>> specifications) {
134142

135143
return StreamSupport.stream(specifications.spliterator(), false) //
136-
.reduce(PredicateSpecification.all(), PredicateSpecification::and);
144+
.reduce(PredicateSpecification.unrestricted(), PredicateSpecification::and);
137145
}
138146

139147
/**
140-
* Applies an OR operation to all the given {@link PredicateSpecification}s.
148+
* Applies an OR operation to all the given {@link PredicateSpecification}s. If {@code specifications} is empty, the
149+
* resulting {@link PredicateSpecification} will be unrestricted applying to all objects.
141150
*
142151
* @param specifications the {@link PredicateSpecification}s to compose.
143152
* @return the disjunction of the specifications.
@@ -150,7 +159,8 @@ static <T> PredicateSpecification<T> anyOf(PredicateSpecification<T>... specific
150159
}
151160

152161
/**
153-
* Applies an OR operation to all the given {@link PredicateSpecification}s.
162+
* Applies an OR operation to all the given {@link PredicateSpecification}s. If {@code specifications} is empty, the
163+
* resulting {@link PredicateSpecification} will be unrestricted applying to all objects.
154164
*
155165
* @param specifications the {@link PredicateSpecification}s to compose.
156166
* @return the disjunction of the specifications.
@@ -160,7 +170,7 @@ static <T> PredicateSpecification<T> anyOf(PredicateSpecification<T>... specific
160170
static <T> PredicateSpecification<T> anyOf(Iterable<PredicateSpecification<T>> specifications) {
161171

162172
return StreamSupport.stream(specifications.spliterator(), false) //
163-
.reduce(PredicateSpecification.all(), PredicateSpecification::or);
173+
.reduce(PredicateSpecification.unrestricted(), PredicateSpecification::or);
164174
}
165175

166176
/**

Diff for: spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/Specification.java

+19-9
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232

3333
/**
3434
* Specification in the sense of Domain Driven Design.
35+
* <p>
36+
* Specifications can be composed into higher order functions from other specifications using
37+
* {@link #and(Specification)}, {@link #or(Specification)} or factory methods such as {@link #allOf(Iterable)}.
38+
* Composition considers whether one or more specifications contribute to the overall predicate by returning a
39+
* {@link Predicate} or {@literal null}. Specifications returning {@literal null} are considered to not contribute to
40+
* the overall predicate and their result is not considered in the final predicate.
3541
*
3642
* @author Oliver Gierke
3743
* @author Thomas Darimont
@@ -51,7 +57,7 @@ public interface Specification<T> extends Serializable {
5157
* @param <T> the type of the {@link Root} the resulting {@literal Specification} operates on.
5258
* @return guaranteed to be not {@literal null}.
5359
*/
54-
static <T> Specification<T> all() {
60+
static <T> Specification<T> unrestricted() {
5561
return (root, query, builder) -> null;
5662
}
5763

@@ -148,13 +154,14 @@ static <T> Specification<T> not(Specification<T> spec) {
148154

149155
return (root, query, builder) -> {
150156

151-
Predicate not = spec.toPredicate(root, query, builder);
152-
return not != null ? builder.not(not) : null;
157+
Predicate predicate = spec.toPredicate(root, query, builder);
158+
return predicate != null ? builder.not(predicate) : null;
153159
};
154160
}
155161

156162
/**
157-
* Applies an AND operation to all the given {@link Specification}s.
163+
* Applies an AND operation to all the given {@link Specification}s. If {@code specifications} is empty, the resulting
164+
* {@link Specification} will be unrestricted applying to all objects.
158165
*
159166
* @param specifications the {@link Specification}s to compose.
160167
* @return the conjunction of the specifications.
@@ -168,7 +175,8 @@ static <T> Specification<T> allOf(Specification<T>... specifications) {
168175
}
169176

170177
/**
171-
* Applies an AND operation to all the given {@link Specification}s.
178+
* Applies an AND operation to all the given {@link Specification}s. If {@code specifications} is empty, the resulting
179+
* {@link Specification} will be unrestricted applying to all objects.
172180
*
173181
* @param specifications the {@link Specification}s to compose.
174182
* @return the conjunction of the specifications.
@@ -179,11 +187,12 @@ static <T> Specification<T> allOf(Specification<T>... specifications) {
179187
static <T> Specification<T> allOf(Iterable<Specification<T>> specifications) {
180188

181189
return StreamSupport.stream(specifications.spliterator(), false) //
182-
.reduce(Specification.all(), Specification::and);
190+
.reduce(Specification.unrestricted(), Specification::and);
183191
}
184192

185193
/**
186-
* Applies an OR operation to all the given {@link Specification}s.
194+
* Applies an OR operation to all the given {@link Specification}s. If {@code specifications} is empty, the resulting
195+
* {@link Specification} will be unrestricted applying to all objects.
187196
*
188197
* @param specifications the {@link Specification}s to compose.
189198
* @return the disjunction of the specifications
@@ -197,7 +206,8 @@ static <T> Specification<T> anyOf(Specification<T>... specifications) {
197206
}
198207

199208
/**
200-
* Applies an OR operation to all the given {@link Specification}s.
209+
* Applies an OR operation to all the given {@link Specification}s. If {@code specifications} is empty, the resulting
210+
* {@link Specification} will be unrestricted applying to all objects.
201211
*
202212
* @param specifications the {@link Specification}s to compose.
203213
* @return the disjunction of the specifications
@@ -208,7 +218,7 @@ static <T> Specification<T> anyOf(Specification<T>... specifications) {
208218
static <T> Specification<T> anyOf(Iterable<Specification<T>> specifications) {
209219

210220
return StreamSupport.stream(specifications.spliterator(), false) //
211-
.reduce(Specification.all(), Specification::or);
221+
.reduce(Specification.unrestricted(), Specification::or);
212222
}
213223

214224
/**

Diff for: spring-data-jpa/src/main/java/org/springframework/data/jpa/domain/UpdateSpecification.java

+23-13
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131

3232
/**
3333
* Specification in the sense of Domain Driven Design to handle Criteria Updates.
34+
* <p>
35+
* Specifications can be composed into higher order functions from other specifications using
36+
* {@link #and(UpdateSpecification)}, {@link #or(UpdateSpecification)} or factory methods such as
37+
* {@link #allOf(Iterable)}. Composition considers whether one or more specifications contribute to the overall
38+
* predicate by returning a {@link Predicate} or {@literal null}. Specifications returning {@literal null} are
39+
* considered to not contribute to the overall predicate and their result is not considered in the final predicate.
3440
*
3541
* @author Mark Paluch
3642
* @since 4.0
@@ -39,27 +45,27 @@
3945
public interface UpdateSpecification<T> extends Serializable {
4046

4147
/**
42-
* Simple static factory method to create a specification deleting all objects.
48+
* Simple static factory method to create a specification updating all objects.
4349
*
4450
* @param <T> the type of the {@link Root} the resulting {@literal UpdateSpecification} operates on.
4551
* @return guaranteed to be not {@literal null}.
4652
*/
47-
static <T> UpdateSpecification<T> all() {
53+
static <T> UpdateSpecification<T> unrestricted() {
4854
return (root, query, builder) -> null;
4955
}
5056

5157
/**
52-
* Simple static factory method to add some syntactic sugar around a {@literal UpdateSpecification}. For example:
58+
* Simple static factory method to add some syntactic sugar around a {@literal UpdateOperation}. For example:
5359
*
5460
* <pre class="code">
55-
* UpdateSpecification&lt;User&gt; updateLastname = UpdateSpecification
61+
* UpdateSpecification&lt;User&gt; updateLastname = UpdateOperation
5662
* .&lt;User&gt; update((root, update, criteriaBuilder) -> update.set("lastname", "Heisenberg"))
5763
* .where(userHasFirstname("Walter").and(userHasLastname("White")));
5864
*
5965
* repository.update(updateLastname);
6066
* </pre>
6167
*
62-
* @param <T> the type of the {@link Root} the resulting {@literal UpdateSpecification} operates on.
68+
* @param <T> the type of the {@link Root} the resulting {@literal UpdateOperation} operates on.
6369
* @param spec must not be {@literal null}.
6470
* @return guaranteed to be not {@literal null}.
6571
*/
@@ -172,13 +178,14 @@ static <T> UpdateSpecification<T> not(UpdateSpecification<T> spec) {
172178

173179
return (root, update, builder) -> {
174180

175-
Predicate not = spec.toPredicate(root, update, builder);
176-
return not != null ? builder.not(not) : null;
181+
Predicate predicate = spec.toPredicate(root, update, builder);
182+
return predicate != null ? builder.not(predicate) : null;
177183
};
178184
}
179185

180186
/**
181-
* Applies an AND operation to all the given {@link UpdateSpecification}s.
187+
* Applies an AND operation to all the given {@link UpdateSpecification}s. If {@code specifications} is empty, the
188+
* resulting {@link UpdateSpecification} will be unrestricted applying to all objects.
182189
*
183190
* @param specifications the {@link UpdateSpecification}s to compose.
184191
* @return the conjunction of the specifications.
@@ -191,7 +198,8 @@ static <T> UpdateSpecification<T> allOf(UpdateSpecification<T>... specifications
191198
}
192199

193200
/**
194-
* Applies an AND operation to all the given {@link UpdateSpecification}s.
201+
* Applies an AND operation to all the given {@link UpdateSpecification}s. If {@code specifications} is empty, the
202+
* resulting {@link UpdateSpecification} will be unrestricted applying to all objects.
195203
*
196204
* @param specifications the {@link UpdateSpecification}s to compose.
197205
* @return the conjunction of the specifications.
@@ -201,11 +209,12 @@ static <T> UpdateSpecification<T> allOf(UpdateSpecification<T>... specifications
201209
static <T> UpdateSpecification<T> allOf(Iterable<UpdateSpecification<T>> specifications) {
202210

203211
return StreamSupport.stream(specifications.spliterator(), false) //
204-
.reduce(UpdateSpecification.all(), UpdateSpecification::and);
212+
.reduce(UpdateSpecification.unrestricted(), UpdateSpecification::and);
205213
}
206214

207215
/**
208-
* Applies an OR operation to all the given {@link UpdateSpecification}s.
216+
* Applies an OR operation to all the given {@link UpdateSpecification}s. If {@code specifications} is empty, the
217+
* resulting {@link UpdateSpecification} will be unrestricted applying to all objects.
209218
*
210219
* @param specifications the {@link UpdateSpecification}s to compose.
211220
* @return the disjunction of the specifications.
@@ -218,7 +227,8 @@ static <T> UpdateSpecification<T> anyOf(UpdateSpecification<T>... specifications
218227
}
219228

220229
/**
221-
* Applies an OR operation to all the given {@link UpdateSpecification}s.
230+
* Applies an OR operation to all the given {@link UpdateSpecification}s. If {@code specifications} is empty, the
231+
* resulting {@link UpdateSpecification} will be unrestricted applying to all objects.
222232
*
223233
* @param specifications the {@link UpdateSpecification}s to compose.
224234
* @return the disjunction of the specifications.
@@ -228,7 +238,7 @@ static <T> UpdateSpecification<T> anyOf(UpdateSpecification<T>... specifications
228238
static <T> UpdateSpecification<T> anyOf(Iterable<UpdateSpecification<T>> specifications) {
229239

230240
return StreamSupport.stream(specifications.spliterator(), false) //
231-
.reduce(UpdateSpecification.all(), UpdateSpecification::or);
241+
.reduce(UpdateSpecification.unrestricted(), UpdateSpecification::or);
232242
}
233243

234244
/**

0 commit comments

Comments
 (0)