@@ -18,18 +18,48 @@ public class InterceptorParamBuilder<P extends BasicJpa, J extends BasicJson, E>
18
18
private String orderByClause = "" ;
19
19
private String query = "" ;
20
20
21
+ /**
22
+ * This helps you to add something to the select-clause, like 'distinct' or a
23
+ * limit.<br>
24
+ * The standard table always gets the alias 'o'.
25
+ *
26
+ * @param selectClause the clause (Example:
27
+ * {@code 'DISTINCT ' + ThisJpa.class.getSimpleName + ' AS o'})
28
+ * @return itself in order to provide a fluent interface.
29
+ */
21
30
public InterceptorParamBuilder <P , J , E > select (final String selectClause ) {
22
- this .selectClause = selectClause ;
31
+ this .selectClause = selectClause .trim ().toLowerCase ().startsWith ("select" )
32
+ ? selectClause .trim ().substring (6 ).trim ()
33
+ : selectClause .trim ();
23
34
return this ;
24
35
}
25
36
37
+ /**
38
+ * Here you can specify a special join-clause that will be added to your query
39
+ * later on.<br>
40
+ * The aliases you give here may be used in all other parts of the query.
41
+ *
42
+ * @param joinClause the clause (Example:
43
+ * {@code ' JOIN ' + MyClass.getSimpleName() + ' AS f ON o.fId=f.id'})
44
+ * @return itself in order to provide a fluent interface.
45
+ */
26
46
public InterceptorParamBuilder <P , J , E > join (final String joinClause ) {
27
- this .joinClause = joinClause . startsWith ( " " ) ? joinClause : " " + joinClause ;
47
+ this .joinClause = " " + joinClause . trim () ;
28
48
return this ;
29
49
}
30
50
51
+ /**
52
+ * Here you can specify a special order-by-clause that will be appended to your
53
+ * SQL-query later on.
54
+ * <p>
55
+ * May or may not start with 'order by', your choice.
56
+ *
57
+ * @param orderByClause the clause (Example: {@code 'o.name DESC'}
58
+ * @return itself in order to provide a fluent interface.
59
+ */
31
60
public InterceptorParamBuilder <P , J , E > orderBy (final String orderByClause ) {
32
- this .orderByClause = orderByClause .startsWith (" " ) ? orderByClause : " " + orderByClause ;
61
+ this .orderByClause = orderByClause .trim ().toLowerCase ().startsWith ("order by" ) ? " " + orderByClause .trim ()
62
+ : " ORDER BY " + orderByClause .trim ();
33
63
return this ;
34
64
}
35
65
@@ -52,7 +82,7 @@ public InterceptorParamBuilder<P, J, E> orderBy(final String orderByClause) {
52
82
* preceded by a '~'.<br>
53
83
* {@code Example: 'dbEnumField = :jsonField[~MyEnumClass]'}<br>
54
84
* <p>
55
- * - Term operators are: >, <, >=, <=, = or ==, <> or != and LIKE (which
85
+ * - Term operators are: {@code >, <, >=, <=, = or ==, <> or != and LIKE} (which
56
86
* automatically adds the wildcards like %yourvalue% before going to the
57
87
* database).<br>
58
88
* - Every term may be optional when you precede the DB-field-name with a
@@ -69,6 +99,12 @@ public InterceptorParamBuilder<P, J, E> query(final String query) {
69
99
return this ;
70
100
}
71
101
102
+ /**
103
+ * Builds this Interceptor and returns you to the fluent interface of the
104
+ * underlying {@link GenericHandlerGroupBuilder}.
105
+ *
106
+ * @return the {@link GenericHandlerGroupBuilder} you came from.
107
+ */
72
108
public GenericHandlerGroupBuilder <P , J , E > build () {
73
109
InterceptorData r = InterceptorData .builder ()
74
110
.selectClause (selectClause )
0 commit comments