31
31
public final class QueryCreationException extends RepositoryCreationException {
32
32
33
33
private static final @ Serial long serialVersionUID = -1238456123580L ;
34
- private static final String MESSAGE_TEMPLATE = "Could not create query for method %s ; Could not find property %s on domain class %s " ;
34
+ private static final String MESSAGE_TEMPLATE = "Could not create query for method [%s] ; Could not find property '%s' on domain class '%s' " ;
35
35
36
36
private final Method method ;
37
37
38
38
/**
39
39
* Creates a new {@link QueryCreationException}.
40
+ *
41
+ * @param message the detail message.
42
+ * @param method the query method causing the exception.
40
43
*/
41
44
private QueryCreationException (String message , QueryMethod method ) {
42
45
@@ -46,8 +49,23 @@ private QueryCreationException(String message, QueryMethod method) {
46
49
47
50
/**
48
51
* Creates a new {@link QueryCreationException}.
52
+ *
53
+ * @param message the detail message.
54
+ * @param cause the root cause from the data access API in use.
55
+ * @param method the query method causing the exception.
56
+ * @since 4.0
49
57
*/
50
- private QueryCreationException (String message , Throwable cause , Class <?> repositoryInterface , Method method ) {
58
+ private QueryCreationException (String message , @ Nullable Throwable cause , QueryMethod method ) {
59
+
60
+ super (message , cause , method .getMetadata ().getRepositoryInterface ());
61
+ this .method = method .getMethod ();
62
+ }
63
+
64
+ /**
65
+ * Creates a new {@link QueryCreationException}.
66
+ */
67
+ private QueryCreationException (@ Nullable String message , @ Nullable Throwable cause , Class <?> repositoryInterface ,
68
+ Method method ) {
51
69
52
70
super (message , cause , repositoryInterface );
53
71
this .method = method ;
@@ -56,9 +74,9 @@ private QueryCreationException(String message, Throwable cause, Class<?> reposit
56
74
/**
57
75
* Rejects the given domain class property.
58
76
*
59
- * @param method
60
- * @param propertyName
61
- * @return
77
+ * @param method the {@link QueryMethod} to create the exception for.
78
+ * @param propertyName the property name that could not be found.
79
+ * @return the {@link QueryCreationException}.
62
80
*/
63
81
public static QueryCreationException invalidProperty (QueryMethod method , String propertyName ) {
64
82
@@ -69,48 +87,67 @@ public static QueryCreationException invalidProperty(QueryMethod method, String
69
87
/**
70
88
* Creates a new {@link QueryCreationException}.
71
89
*
72
- * @param method
73
- * @param message
74
- * @return
90
+ * @param method the {@link QueryMethod} to create the exception for.
91
+ * @param message the message to use.
92
+ * @return the {@link QueryCreationException}.
75
93
*/
76
94
public static QueryCreationException create (QueryMethod method , String message ) {
77
-
78
- return new QueryCreationException (String .format ("Could not create query for %s; Reason: %s" , method , message ),
79
- method );
95
+ return new QueryCreationException (createMessage (message , method .getMethod ()), method );
80
96
}
81
97
82
98
/**
83
99
* Creates a new {@link QueryCreationException} for the given {@link QueryMethod} and {@link Throwable} as cause.
84
100
*
85
- * @param method
86
- * @param cause
87
- * @return
101
+ * @param method the query method causing the exception.
102
+ * @param cause the root cause from the data access API in use.
103
+ * @return the {@link QueryCreationException}.
88
104
*/
89
105
@ SuppressWarnings ("NullAway" )
90
106
public static QueryCreationException create (QueryMethod method , Throwable cause ) {
91
- return new QueryCreationException (cause .getMessage (), cause , method .getMetadata ().getRepositoryInterface (),
92
- method .getMethod ());
107
+ return new QueryCreationException (cause .getMessage (), cause , method );
108
+ }
109
+
110
+ /**
111
+ * Creates a new {@link QueryCreationException} for the given {@link QueryMethod}, {@code message} and
112
+ * {@link Throwable} as cause.
113
+ *
114
+ * @param method the query method causing the exception.
115
+ * @param message the detail message.
116
+ * @param cause the root cause from the data access API in use.
117
+ * @return the {@link QueryCreationException}.
118
+ * @since 4.0
119
+ */
120
+ @ SuppressWarnings ("NullAway" )
121
+ public static QueryCreationException create (QueryMethod method , String message , Throwable cause ) {
122
+ return create (message , cause , method .getMetadata ().getRepositoryInterface (), method .getMethod ());
93
123
}
94
124
95
125
/**
96
126
* Creates a new {@link QueryCreationException} for the given {@link QueryMethod} and {@link Throwable} as cause.
97
127
*
98
- * @param method
99
- * @param cause
100
- * @return
128
+ * @param message the detail message.
129
+ * @param cause the root cause from the data access API in use.
130
+ * @param repositoryInterface the repository interface.
131
+ * @param method the query method causing the exception.
132
+ * @return the {@link QueryCreationException}.
101
133
* @since 2.5
102
134
*/
103
- public static QueryCreationException create (@ Nullable String message , Throwable cause , Class <?> repositoryInterface ,
104
- Method method ) {
105
- return new QueryCreationException (String . format ( "Could not create query for %s; Reason: %s" , method , message ),
135
+ public static QueryCreationException create (@ Nullable String message , @ Nullable Throwable cause ,
136
+ Class <?> repositoryInterface , Method method ) {
137
+ return new QueryCreationException (createMessage ( message , method ),
106
138
cause , repositoryInterface , method );
107
139
}
108
140
141
+ private static String createMessage (@ Nullable String message , Method method ) {
142
+ return String .format ("Could not create query for [%s]; Reason: %s" , method , message );
143
+ }
144
+
109
145
/**
110
- * @return
146
+ * @return the method causing the exception.
111
147
* @since 2.5
112
148
*/
113
149
public Method getMethod () {
114
150
return method ;
115
151
}
152
+
116
153
}
0 commit comments