Fix NullPointer when deriving a count query for non-SELECT statements.
Closes #2812
This commit is contained in:
committed by
Greg L. Turnquist
parent
7a9e55f8cf
commit
ff9e081fc0
@@ -105,7 +105,7 @@ interface DeclaredQuery {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return whether the query is a native query of not.
|
* Return whether the query is a native query of not.
|
||||||
*
|
*
|
||||||
* @return <code>true</code> if native query otherwise <code>false</code>
|
* @return <code>true</code> if native query otherwise <code>false</code>
|
||||||
*/
|
*/
|
||||||
default boolean isNativeQuery() {
|
default boolean isNativeQuery() {
|
||||||
|
|||||||
@@ -617,7 +617,7 @@ public abstract class QueryUtils {
|
|||||||
|
|
||||||
String replacement = useVariable ? SIMPLE_COUNT_VALUE : complexCountValue;
|
String replacement = useVariable ? SIMPLE_COUNT_VALUE : complexCountValue;
|
||||||
|
|
||||||
if (nativeQuery && (variable.contains(",") || "*".equals(variable))) {
|
if (variable != null && (nativeQuery && (variable.contains(",") || "*".equals(variable)))) {
|
||||||
replacement = "1";
|
replacement = "1";
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|||||||
@@ -70,6 +70,15 @@ class DefaultQueryUtilsUnitTests {
|
|||||||
"select count(distinct u) from User u where u.foo = ?");
|
"select count(distinct u) from User u where u.foo = ?");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test // GH-2812
|
||||||
|
void createsCountQueryForDeleteQuery() {
|
||||||
|
|
||||||
|
String result = createCountQueryFor("delete from some_table where id in :ids", null, true);
|
||||||
|
|
||||||
|
// ح(•̀ж•́)ง †
|
||||||
|
assertThat(result).isEqualTo("deleteselect count(where) from some_table where id in :ids");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createsCountQueryForConstructorQueries() {
|
void createsCountQueryForConstructorQueries() {
|
||||||
|
|
||||||
|
|||||||
@@ -176,6 +176,15 @@ class QueryEnhancerUnitTests {
|
|||||||
endsIgnoringCase(query, "ORDER BY p.firstname, p.lastname asc");
|
endsIgnoringCase(query, "ORDER BY p.firstname, p.lastname asc");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test // GH-2812
|
||||||
|
void createCountQueryFromDeleteQuery() {
|
||||||
|
|
||||||
|
StringQuery query = new StringQuery("delete from some_table where id in :ids", true);
|
||||||
|
|
||||||
|
assertThat(getEnhancer(query).createCountQueryFor("p.lastname"))
|
||||||
|
.isEqualToIgnoringCase("delete from some_table where id in :ids");
|
||||||
|
}
|
||||||
|
|
||||||
@Test // DATAJPA-456
|
@Test // DATAJPA-456
|
||||||
void createCountQueryFromTheGivenCountProjection() {
|
void createCountQueryFromTheGivenCountProjection() {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user