Skip to content

Commit 8c69055

Browse files
committed
Move Benchmarks from performance module into spring-data-jpa.
Closes #3655
1 parent 490d34a commit 8c69055

File tree

13 files changed

+84
-198
lines changed

13 files changed

+84
-198
lines changed

pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,6 @@
5858

5959

6060
<profiles>
61-
<profile>
62-
<id>benchmark</id>
63-
<modules>
64-
<module>spring-data-jpa-performance</module>
65-
</modules>
66-
</profile>
6761
<profile>
6862
<id>hibernate-62</id>
6963
<properties>

spring-data-jpa-performance/pom.xml

Lines changed: 0 additions & 129 deletions
This file was deleted.

spring-data-jpa-performance/src/main/resources/META-INF/persistence.xml

Lines changed: 0 additions & 11 deletions
This file was deleted.

spring-data-jpa-performance/src/main/resources/logback.xml

Lines changed: 0 additions & 18 deletions
This file was deleted.

spring-data-jpa/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,16 @@
351351
<artifactId>hibernate-jpamodelgen</artifactId>
352352
<version>${hibernate}</version>
353353
</path>
354+
<path>
355+
<groupId>org.hibernate.orm</groupId>
356+
<artifactId>hibernate-core</artifactId>
357+
<version>${hibernate}</version>
358+
</path>
359+
<path>
360+
<groupId>org.openjdk.jmh</groupId>
361+
<artifactId>jmh-generator-annprocess</artifactId>
362+
<version>${jmh}</version>
363+
</path>
354364
<path>
355365
<groupId>jakarta.persistence</groupId>
356366
<artifactId>jakarta.persistence-api</artifactId>
Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,22 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.data.jpa.repository;
16+
package org.springframework.data.jpa.benchmark;
1717

1818
import jakarta.persistence.EntityManager;
1919
import jakarta.persistence.EntityManagerFactory;
20-
import jakarta.persistence.Persistence;
2120
import jakarta.persistence.Query;
2221
import jakarta.persistence.TypedQuery;
2322
import jakarta.persistence.criteria.CriteriaBuilder;
2423
import jakarta.persistence.criteria.CriteriaQuery;
2524
import jakarta.persistence.criteria.Root;
26-
import jmh.mbr.junit5.Microbenchmark;
2725

28-
import java.util.HashMap;
2926
import java.util.List;
30-
import java.util.Map;
27+
import java.util.Properties;
3128
import java.util.Set;
3229

30+
import org.hibernate.jpa.HibernatePersistenceProvider;
31+
import org.junit.platform.commons.annotation.Testable;
3332
import org.openjdk.jmh.annotations.Benchmark;
3433
import org.openjdk.jmh.annotations.Fork;
3534
import org.openjdk.jmh.annotations.Level;
@@ -42,21 +41,24 @@
4241
import org.openjdk.jmh.annotations.Warmup;
4342

4443
import org.springframework.data.domain.Sort;
45-
import org.springframework.data.jpa.model.IPersonProjection;
46-
import org.springframework.data.jpa.model.Person;
47-
import org.springframework.data.jpa.model.Profile;
44+
import org.springframework.data.jpa.benchmark.model.IPersonProjection;
45+
import org.springframework.data.jpa.benchmark.model.Person;
46+
import org.springframework.data.jpa.benchmark.model.Profile;
47+
import org.springframework.data.jpa.benchmark.repository.PersonRepository;
4848
import org.springframework.data.jpa.repository.support.JpaRepositoryFactory;
49+
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
50+
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
4951
import org.springframework.util.ObjectUtils;
5052

5153
/**
5254
* @author Christoph Strobl
5355
*/
54-
@Microbenchmark
56+
@Testable
5557
@Fork(1)
5658
@Warmup(time = 2, iterations = 3)
5759
@Measurement(time = 2)
5860
@Timeout(time = 2)
59-
public class RepositoryFinderTests {
61+
public class RepositoryFinderBenchmarks {
6062

6163
private static final String PERSON_FIRSTNAME = "first";
6264
private static final String COLUMN_PERSON_FIRSTNAME = "firstname";
@@ -103,12 +105,23 @@ public void doTearDown() {
103105

104106
private void createEntityManager() {
105107

106-
Map<String, String> properties = new HashMap<>();
108+
LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
109+
factoryBean.setPersistenceUnitName("benchmark");
110+
factoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
111+
factoryBean.setPersistenceProviderClass(HibernatePersistenceProvider.class);
112+
factoryBean.setPersistenceXmlLocation("classpath*:META-INF/persistence-jmh.xml");
113+
factoryBean.setMappingResources("classpath*:META-INF/orm-jmh.xml");
114+
115+
Properties properties = new Properties();
107116
properties.put("jakarta.persistence.jdbc.url", "jdbc:h2:mem:test");
108117
properties.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
109118
properties.put("hibernate.hbm2ddl.auto", "update");
110-
EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("benchmark", properties);
119+
properties.put("hibernate.xml_mapping_enabled", "false");
120+
121+
factoryBean.setJpaProperties(properties);
122+
factoryBean.afterPropertiesSet();
111123

124+
EntityManagerFactory entityManagerFactory = factoryBean.getObject();
112125
entityManager = entityManagerFactory.createEntityManager();
113126
}
114127

@@ -139,7 +152,7 @@ public List<Person> baselineEntityManagerCriteriaQuery(BenchmarkParameters param
139152
public List<Person> baselineEntityManagerHQLQuery(BenchmarkParameters parameters) {
140153

141154
Query query = parameters.entityManager
142-
.createQuery("SELECT p FROM org.springframework.data.jpa.model.Person p WHERE p.firstname = ?1");
155+
.createQuery("SELECT p FROM org.springframework.data.jpa.benchmark.model.Person p WHERE p.firstname = ?1");
143156
query.setParameter(1, PERSON_FIRSTNAME);
144157

145158
return query.getResultList();
@@ -148,7 +161,8 @@ public List<Person> baselineEntityManagerHQLQuery(BenchmarkParameters parameters
148161
@Benchmark
149162
public Long baselineEntityManagerCount(BenchmarkParameters parameters) {
150163

151-
Query query = parameters.entityManager.createQuery("SELECT COUNT(*) FROM org.springframework.data.jpa.model.Person p WHERE p.firstname = ?1");
164+
Query query = parameters.entityManager.createQuery(
165+
"SELECT COUNT(*) FROM org.springframework.data.jpa.benchmark.model.Person p WHERE p.firstname = ?1");
152166
query.setParameter(1, PERSON_FIRSTNAME);
153167

154168
return (Long) query.getSingleResult();
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.data.jpa.model;
16+
package org.springframework.data.jpa.benchmark.model;
1717

1818
/**
1919
* @author Christoph Strobl

spring-data-jpa-performance/src/main/java/org/springframework/data/jpa/model/Person.java renamed to spring-data-jpa/src/jmh/java/org/springframework/data/jpa/benchmark/model/Person.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.data.jpa.model;
17-
18-
import java.util.Set;
16+
package org.springframework.data.jpa.benchmark.model;
1917

2018
import jakarta.persistence.Column;
2119
import jakarta.persistence.Entity;
@@ -25,6 +23,8 @@
2523
import jakarta.persistence.ManyToMany;
2624
import jakarta.persistence.Table;
2725

26+
import java.util.Set;
27+
2828
/**
2929
* @author Christoph Strobl
3030
*/

spring-data-jpa-performance/src/main/java/org/springframework/data/jpa/model/Profile.java renamed to spring-data-jpa/src/jmh/java/org/springframework/data/jpa/benchmark/model/Profile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.data.jpa.model;
16+
package org.springframework.data.jpa.benchmark.model;
1717

1818
import jakarta.persistence.Entity;
1919
import jakarta.persistence.GeneratedValue;
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.data.jpa.repository;
16+
package org.springframework.data.jpa.benchmark.repository;
1717

1818
import java.util.List;
1919

2020
import org.springframework.data.domain.Sort;
21-
import org.springframework.data.jpa.model.IPersonProjection;
22-
import org.springframework.data.jpa.model.Person;
21+
import org.springframework.data.jpa.benchmark.model.IPersonProjection;
22+
import org.springframework.data.jpa.benchmark.model.Person;
23+
import org.springframework.data.jpa.repository.Query;
2324
import org.springframework.data.repository.ListCrudRepository;
2425

2526
/**
@@ -31,17 +32,17 @@ public interface PersonRepository extends ListCrudRepository<Person, Integer> {
3132

3233
List<IPersonProjection> findAllAndProjectToInterfaceByFirstname(String firstname);
3334

34-
@Query("SELECT p FROM org.springframework.data.jpa.model.Person p WHERE p.firstname = ?1")
35+
@Query("SELECT p FROM org.springframework.data.jpa.benchmark.model.Person p WHERE p.firstname = ?1")
3536
List<Person> findAllWithAnnotatedQueryByFirstname(String firstname);
3637

37-
@Query("SELECT p FROM org.springframework.data.jpa.model.Person p WHERE p.firstname = ?1")
38+
@Query("SELECT p FROM org.springframework.data.jpa.benchmark.model.Person p WHERE p.firstname = ?1")
3839
List<Person> findAllWithAnnotatedQueryByFirstname(String firstname, Sort sort);
3940

4041
@Query(value = "SELECT * FROM person WHERE firstname = ?1", nativeQuery = true)
4142
List<Person> findAllWithNativeQueryByFirstname(String firstname);
4243

4344
Long countByFirstname(String firstname);
4445

45-
@Query("SELECT COUNT(*) FROM org.springframework.data.jpa.model.Person p WHERE p.firstname = ?1")
46+
@Query("SELECT COUNT(*) FROM org.springframework.data.jpa.benchmark.model.Person p WHERE p.firstname = ?1")
4647
Long countWithAnnotatedQueryByFirstname(String firstname);
4748
}

0 commit comments

Comments
 (0)