Skip to content

Commit 14125f3

Browse files
committed
DATAJPA-1267 - Polishing.
Tweak error messages. Make method static where possible. Typos. Original pull request: #250.
1 parent 0128004 commit 14125f3

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/main/java/org/springframework/data/jpa/repository/query/StringQuery.java

+6-8
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ private String parseParameterBindingsOfQueryIntoBindingsAndReturnCleanedQuery(St
233233
List<ParameterBinding> bindings, Metadata queryMeta) {
234234

235235
int greatestParameterIndex = tryFindGreatestParameterIndexIn(query);
236-
237236
boolean parametersShouldBeAccessedByIndex = greatestParameterIndex != -1;
238237

239238
/*
@@ -267,7 +266,7 @@ private String parseParameterBindingsOfQueryIntoBindingsAndReturnCleanedQuery(St
267266
String expression = spelExtractor.getParameter(parameterName == null ? parameterIndexString : parameterName);
268267
String replacement = null;
269268

270-
Assert.isTrue(parameterIndexString != null || parameterName != null, "We need either a name or an index.");
269+
Assert.isTrue(parameterIndexString != null || parameterName != null, () -> String.format("We need either a name or an index! Offending query string: %s", query));
271270

272271
expressionParameterIndex++;
273272
if ("".equals(parameterIndexString)) {
@@ -279,7 +278,7 @@ private String parseParameterBindingsOfQueryIntoBindingsAndReturnCleanedQuery(St
279278
}
280279

281280
if (usesJpaStyleParameters && queryMeta.usesJdbcStyleParameters) {
282-
throw new IllegalArgumentException("Mixing of ? parameters and other forms like ?1 is not supported");
281+
throw new IllegalArgumentException("Mixing of ? parameters and other forms like ?1 is not supported!");
283282
}
284283

285284
switch (ParameterBindingType.of(typeSource)) {
@@ -325,7 +324,7 @@ private String parseParameterBindingsOfQueryIntoBindingsAndReturnCleanedQuery(St
325324
return resultingQuery;
326325
}
327326

328-
private SpelExtractor createSpelExtractor(String queryWithSpel, boolean parametersShouldBeAccessedByIndex,
327+
private static SpelExtractor createSpelExtractor(String queryWithSpel, boolean parametersShouldBeAccessedByIndex,
329328
int greatestParameterIndex) {
330329

331330
/*
@@ -345,7 +344,7 @@ private SpelExtractor createSpelExtractor(String queryWithSpel, boolean paramete
345344
return SpelQueryContext.of(indexToParameterName, parameterNameToReplacement).parse(queryWithSpel);
346345
}
347346

348-
private String replaceFirst(String text, String substring, String replacement) {
347+
private static String replaceFirst(String text, String substring, String replacement) {
349348

350349
int index = text.indexOf(substring);
351350
if (index < 0) {
@@ -356,15 +355,15 @@ private String replaceFirst(String text, String substring, String replacement) {
356355
}
357356

358357
@Nullable
359-
private Integer getParameterIndex(@Nullable String parameterIndexString) {
358+
private static Integer getParameterIndex(@Nullable String parameterIndexString) {
360359

361360
if (parameterIndexString == null || parameterIndexString.isEmpty()) {
362361
return null;
363362
}
364363
return Integer.valueOf(parameterIndexString);
365364
}
366365

367-
private int tryFindGreatestParameterIndexIn(String query) {
366+
private static int tryFindGreatestParameterIndexIn(String query) {
368367

369368
Matcher parameterIndexMatcher = PARAMETER_BINDING_BY_INDEX.matcher(query);
370369

@@ -440,7 +439,6 @@ static ParameterBindingType of(String typeSource) {
440439
throw new IllegalArgumentException(String.format("Unsupported parameter binding type %s!", typeSource));
441440
}
442441
}
443-
444442
}
445443

446444
/**

src/test/java/org/springframework/data/jpa/repository/query/ParameterBindingParserUnitTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
public class ParameterBindingParserUnitTests {
2828

2929
@Test // DATAJPA-1200
30-
public void idenficationOfParameters() {
30+
public void identificationOfParameters() {
3131

3232
SoftAssertions softly = new SoftAssertions();
3333

@@ -63,7 +63,7 @@ public void idenficationOfParameters() {
6363
softly.assertAll();
6464
}
6565

66-
public void checkHasParameter(SoftAssertions softly, String query, boolean containsParameter, String label) {
66+
private void checkHasParameter(SoftAssertions softly, String query, boolean containsParameter, String label) {
6767

6868
StringQuery stringQuery = new StringQuery(query);
6969

0 commit comments

Comments
 (0)