Correcting sort object reference in FetchableFluentQueryByExample.sortBy and FetchableFluentQueryByPredicate.sortBy

Closes #2438
Original pull request #2439
This commit is contained in:
jonyschak
2022-02-13 01:31:57 -06:00
committed by Jens Schauder
parent f23d03c96a
commit 4ed32e8369
4 changed files with 89 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2021 the original author or authors.
* Copyright 2021-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,6 +45,7 @@ import org.springframework.util.Assert;
* @author Greg Turnquist
* @author Mark Paluch
* @author Jens Schauder
* @author J.R. Onyschak
* @since 2.6
*/
class FetchableFluentQueryByExample<S, R> extends FluentQuerySupport<S, R> implements FetchableFluentQuery<R> {
@@ -86,8 +87,8 @@ class FetchableFluentQueryByExample<S, R> extends FluentQuerySupport<S, R> imple
Assert.notNull(sort, "Sort must not be null!");
return new FetchableFluentQueryByExample<>(example, entityType, resultType, sort.and(sort), properties, finder,
countOperation, existsOperation, entityManager, escapeCharacter);
return new FetchableFluentQueryByExample<>(example, entityType, resultType, this.sort.and(sort), properties,
finder, countOperation, existsOperation, entityManager, escapeCharacter);
}
/*

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2021 the original author or authors.
* Copyright 2021-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -46,6 +46,7 @@ import com.querydsl.jpa.impl.AbstractJPAQuery;
* @author Greg Turnquist
* @author Mark Paluch
* @author Jens Schauder
* @author J.R. Onyschak
* @since 2.6
*/
class FetchableFluentQueryByPredicate<S, R> extends FluentQuerySupport<S, R> implements FetchableFluentQuery<R> {
@@ -89,8 +90,8 @@ class FetchableFluentQueryByPredicate<S, R> extends FluentQuerySupport<S, R> imp
Assert.notNull(sort, "Sort must not be null!");
return new FetchableFluentQueryByPredicate<>(predicate, entityType, resultType, sort.and(sort), properties, finder,
pagedFinder, countOperation, existsOperation, entityManager);
return new FetchableFluentQueryByPredicate<>(predicate, entityType, resultType, this.sort.and(sort), properties,
finder, pagedFinder, countOperation, existsOperation, entityManager);
}
/*

View File

@@ -0,0 +1,41 @@
/*
* Copyright 2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.jpa.repository.support;
import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Order;
/**
* Unit tests for {@link FetchableFluentQueryByExample}.
*
* @author J.R. Onyschak
*/
class FetchableFluentQueryByExampleUnitTests {
@Test // GH-2438
@SuppressWarnings({ "rawtypes", "unchecked" })
void multipleSortBy() {
Sort s1 = Sort.by(Order.by("s1"));
Sort s2 = Sort.by(Order.by("s2"));
FetchableFluentQueryByExample f = new FetchableFluentQueryByExample(Example.of(""), null, null, null, null, null);
f = (FetchableFluentQueryByExample) f.sortBy(s1).sortBy(s2);
assertThat(f.sort).isEqualTo(s1.and(s2));
}
}

View File

@@ -0,0 +1,40 @@
/*
* Copyright 2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.jpa.repository.support;
import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Order;
/**
* Unit tests for {@link FetchableFluentQueryByPredicate}.
*
* @author J.R. Onyschak
*/
class FetchableFluentQueryByPredicateUnitTests {
@Test // GH-2438
@SuppressWarnings({ "rawtypes", "unchecked" })
void multipleSortBy() {
Sort s1 = Sort.by(Order.by("s1"));
Sort s2 = Sort.by(Order.by("s2"));
FetchableFluentQueryByPredicate f = new FetchableFluentQueryByPredicate(null, null, null, null, null, null, null);
f = (FetchableFluentQueryByPredicate) f.sortBy(s1).sortBy(s2);
assertThat(f.sort).isEqualTo(s1.and(s2));
}
}