Skip to content

Commit 5ebfdb6

Browse files
committed
Polishing.
Add dynamic projection benchmark.
1 parent 403e1b4 commit 5ebfdb6

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

pom.xml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,9 @@
5656
<profiles>
5757
<profile>
5858
<id>jmh</id>
59-
<dependencies>
60-
<dependency>
61-
<groupId>com.github.mp911de.microbenchmark-runner</groupId>
62-
<artifactId>microbenchmark-runner-junit5</artifactId>
63-
<version>0.4.0.RELEASE</version>
64-
<scope>test</scope>
65-
</dependency>
66-
</dependencies>
6759
<repositories>
6860
<repository>
69-
<id>jitpack.io</id>
61+
<id>jitpack</id>
7062
<url>https://jitpack.io</url>
7163
</repository>
7264
</repositories>

spring-data-jpa/src/jmh/java/org/springframework/data/jpa/benchmark/RepositoryQueryMethodBenchmarks.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
import org.springframework.data.domain.Sort;
4444
import org.springframework.data.jpa.benchmark.model.Person;
45+
import org.springframework.data.jpa.benchmark.model.PersonDto;
4546
import org.springframework.data.jpa.benchmark.model.Profile;
4647
import org.springframework.data.jpa.benchmark.repository.PersonRepository;
4748
import org.springframework.data.jpa.repository.support.JpaRepositoryFactory;
@@ -195,6 +196,12 @@ public List<Person> stringBasedQueryDynamicSort(BenchmarkParameters parameters)
195196
Sort.by(COLUMN_PERSON_FIRSTNAME));
196197
}
197198

199+
@Benchmark
200+
public List<PersonDto> stringBasedQueryDynamicSortAndProjection(BenchmarkParameters parameters) {
201+
return parameters.repositoryProxy.findAllWithAnnotatedQueryByFirstname(PERSON_FIRSTNAME,
202+
Sort.by(COLUMN_PERSON_FIRSTNAME), PersonDto.class);
203+
}
204+
198205
@Benchmark
199206
public List<Person> stringBasedNativeQuery(BenchmarkParameters parameters) {
200207
return parameters.repositoryProxy.findAllWithNativeQueryByFirstname(PERSON_FIRSTNAME);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright 2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.jpa.benchmark.model;
17+
18+
/**
19+
* @author Mark Paluch
20+
*/
21+
public record PersonDto(String firstname, String lastname) {
22+
}

spring-data-jpa/src/jmh/java/org/springframework/data/jpa/benchmark/repository/PersonRepository.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public interface PersonRepository extends ListCrudRepository<Person, Integer> {
3838
@Query("SELECT p FROM org.springframework.data.jpa.benchmark.model.Person p WHERE p.firstname = ?1")
3939
List<Person> findAllWithAnnotatedQueryByFirstname(String firstname, Sort sort);
4040

41+
@Query("SELECT p FROM org.springframework.data.jpa.benchmark.model.Person p WHERE p.firstname = ?1")
42+
<T> List<T> findAllWithAnnotatedQueryByFirstname(String firstname, Sort sort, Class<T> projection);
43+
4144
@Query(value = "SELECT * FROM person WHERE firstname = ?1", nativeQuery = true)
4245
List<Person> findAllWithNativeQueryByFirstname(String firstname);
4346

0 commit comments

Comments
 (0)