1
1
/*
2
- * Copyright 2008-2015 the original author or authors.
2
+ * Copyright 2008-2016 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
36
36
* @author Oliver Gierke
37
37
* @author Thomas Darimont
38
38
* @author Christoph Strobl
39
+ * @author Mark Paluch
39
40
*/
40
41
public class PartTree implements Iterable <OrPart > {
41
42
@@ -52,9 +53,10 @@ public class PartTree implements Iterable<OrPart> {
52
53
private static final String KEYWORD_TEMPLATE = "(%s)(?=(\\ p{Lu}|\\ P{InBASIC_LATIN}))" ;
53
54
private static final String QUERY_PATTERN = "find|read|get|query|stream" ;
54
55
private static final String COUNT_PATTERN = "count" ;
56
+ private static final String EXISTS_PATTERN = "exists" ;
55
57
private static final String DELETE_PATTERN = "delete|remove" ;
56
58
private static final Pattern PREFIX_TEMPLATE = Pattern .compile ( //
57
- "^(" + QUERY_PATTERN + "|" + COUNT_PATTERN + "|" + DELETE_PATTERN + ")((\\ p{Lu}.*?))??By" );
59
+ "^(" + QUERY_PATTERN + "|" + COUNT_PATTERN + "|" + EXISTS_PATTERN + "|" + DELETE_PATTERN + ")((\\ p{Lu}.*?))??By" );
58
60
59
61
/**
60
62
* The subject, for example "findDistinctUserByNameOrderByAge" would have the subject "DistinctUser".
@@ -125,6 +127,16 @@ public Boolean isCountProjection() {
125
127
return subject .isCountProjection ();
126
128
}
127
129
130
+ /**
131
+ * Returns whether an exists projection shall be applied.
132
+ *
133
+ * @return
134
+ * @since 1.13
135
+ */
136
+ public Boolean isExistsProjection () {
137
+ return subject .isExistsProjection ();
138
+ }
139
+
128
140
/**
129
141
* return true if the created {@link PartTree} is meant to be used for delete operation.
130
142
*
@@ -262,20 +274,23 @@ private static class Subject {
262
274
263
275
private static final String DISTINCT = "Distinct" ;
264
276
private static final Pattern COUNT_BY_TEMPLATE = Pattern .compile ("^count(\\ p{Lu}.*?)??By" );
277
+ private static final Pattern EXISTS_BY_TEMPLATE = Pattern .compile ("^(" + EXISTS_PATTERN + ")(\\ p{Lu}.*?)??By" );
265
278
private static final Pattern DELETE_BY_TEMPLATE = Pattern .compile ("^(" + DELETE_PATTERN + ")(\\ p{Lu}.*?)??By" );
266
279
private static final String LIMITING_QUERY_PATTERN = "(First|Top)(\\ d*)?" ;
267
280
private static final Pattern LIMITED_QUERY_TEMPLATE = Pattern .compile ("^(" + QUERY_PATTERN + ")(" + DISTINCT + ")?"
268
281
+ LIMITING_QUERY_PATTERN + "(\\ p{Lu}.*?)??By" );
269
282
270
283
private final boolean distinct ;
271
284
private final boolean count ;
285
+ private final boolean exists ;
272
286
private final boolean delete ;
273
287
private final Integer maxResults ;
274
288
275
289
public Subject (String subject ) {
276
290
277
291
this .distinct = subject == null ? false : subject .contains (DISTINCT );
278
292
this .count = matches (subject , COUNT_BY_TEMPLATE );
293
+ this .exists = matches (subject , EXISTS_BY_TEMPLATE );
279
294
this .delete = matches (subject , DELETE_BY_TEMPLATE );
280
295
this .maxResults = returnMaxResultsIfFirstKSubjectOrNull (subject );
281
296
}
@@ -314,6 +329,16 @@ public boolean isCountProjection() {
314
329
return count ;
315
330
}
316
331
332
+ /**
333
+ * Returns {@literal true} if {@link Subject} matches {@link #EXISTS_BY_TEMPLATE}.
334
+ *
335
+ * @return
336
+ * @since 1.13
337
+ */
338
+ public boolean isExistsProjection () {
339
+ return exists ;
340
+ }
341
+
317
342
public boolean isDistinct () {
318
343
return distinct ;
319
344
}
0 commit comments