Skip to content

Commit 813b740

Browse files
We should have at least one integration test demonstrating this feature.
1 parent 7f30a9f commit 813b740

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/support/JdbcQueryMethod.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ public JdbcQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFac
6161

6262
@Nullable
6363
String getAnnotatedQuery() {
64-
String annotatedValue = getNamedQueryvalue();
65-
return StringUtils.hasText(annotatedValue) ? annotatedValue : getNamedQueryName();
64+
String annotatedValue = getQueryValue();
65+
return StringUtils.hasText(annotatedValue) ? annotatedValue : getValueNamedQuery();
6666
}
6767

6868
/**
@@ -71,7 +71,7 @@ String getAnnotatedQuery() {
7171
* @return May be {@code null}.
7272
*/
7373
@Nullable
74-
public String getNamedQueryvalue() {
74+
public String getQueryValue() {
7575
return getMergedAnnotationAttribute("value");
7676
}
7777
/**
@@ -80,11 +80,11 @@ public String getNamedQueryvalue() {
8080
* @return May be {@code null}.
8181
*/
8282
@Nullable
83-
public String getNamedQueryName() {
83+
public String getValueNamedQuery() {
8484
String annotatedName = getMergedAnnotationAttribute("name");
8585
return (StringUtils.hasText(annotatedName) && this.namedQueries.hasQuery(annotatedName))
8686
? this.namedQueries.getQuery(annotatedName)
87-
: super.getNamedQueryName();
87+
: null;
8888
}
8989

9090
/*

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/support/JdbcQueryMethodUnitTests.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ public void returnsSpecifiedRowMapperClass() throws NoSuchMethodException {
7676
assertThat(queryMethod.getRowMapperClass()).isEqualTo(CustomRowMapper.class);
7777
}
7878

79+
80+
81+
82+
83+
84+
85+
86+
7987
@Test // DATAJDBC-234
8088
public void returnsSqlStatementName() throws NoSuchMethodException {
8189

@@ -112,20 +120,20 @@ public void returnsSqlStatementNameAndValue() throws NoSuchMethodException {
112120
}
113121

114122
@Test // DATAJDBC-234
115-
public void returnsSpecifiedRowMapperClassName() throws NoSuchMethodException {
116-
123+
public void returnsNullNoSqlQuery() throws NoSuchMethodException {
124+
117125
RepositoryMetadata metadata = mock(RepositoryMetadata.class);
118126
Properties properties = new Properties();
119127
properties.setProperty(DUMMY_SELECT_NAME, DUMMY_SELECT_VALUE);
120128
NamedQueries nameQueries = new PropertiesBasedNamedQueries(properties);
121-
129+
122130
doReturn(String.class).when(metadata).getReturnedDomainClass(any(Method.class));
123-
131+
124132
JdbcQueryMethod queryMethod = new JdbcQueryMethod(
125-
JdbcQueryMethodUnitTests.class.getDeclaredMethod("queryMethodName"), metadata,
133+
JdbcQueryMethodUnitTests.class.getDeclaredMethod("queryWhitoutQueryAnnotation"), metadata,
126134
mock(ProjectionFactory.class), nameQueries);
127-
128-
assertThat(queryMethod.getRowMapperClass()).isEqualTo(CustomRowMapper.class);
135+
136+
assertThat(queryMethod.getAnnotatedQuery()).isEqualTo(null);
129137
}
130138

131139
@Query(value = DUMMY_SELECT_VALUE, rowMapperClass = CustomRowMapper.class)
@@ -139,6 +147,9 @@ private void queryMethodName() {
139147
@Query(value = DUMMY_SELECT_NAME_VALUE, name = DUMMY_SELECT_NAME, rowMapperClass = CustomRowMapper.class)
140148
private void queryMethodNameAndValue() {
141149
}
150+
151+
private void queryWhitoutQueryAnnotation() {
152+
}
142153

143154
private class CustomRowMapper implements RowMapper<Object> {
144155

0 commit comments

Comments
 (0)