Skip to content

Commit b8319a0

Browse files
Add performance module.
Add new module using JMH to benchmark certain aspects of query parsing & rendering. See: #3309
1 parent d60efe6 commit b8319a0

File tree

9 files changed

+543
-0
lines changed

9 files changed

+543
-0
lines changed

pom.xml

+6
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@
5858

5959

6060
<profiles>
61+
<profile>
62+
<id>benchmark</id>
63+
<modules>
64+
<module>spring-data-jpa-performance</module>
65+
</modules>
66+
</profile>
6167
<profile>
6268
<id>hibernate-62</id>
6369
<properties>

spring-data-jpa-performance/pom.xml

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>org.springframework.data</groupId>
8+
<artifactId>spring-data-jpa-parent</artifactId>
9+
<version>3.4.x-LABS-QUERY-SNAPSHOT</version>
10+
</parent>
11+
12+
<name>Spring Data JPA - Performance</name>
13+
<artifactId>spring-data-jpa-performance</artifactId>
14+
15+
<properties>
16+
<jmh.version>1.37</jmh.version>
17+
</properties>
18+
19+
<dependencies>
20+
21+
<dependency>
22+
<groupId>${groupId}</groupId>
23+
<artifactId>spring-data-jpa</artifactId>
24+
<version>${version}</version>
25+
</dependency>
26+
27+
<dependency>
28+
<groupId>org.openjdk.jmh</groupId>
29+
<artifactId>jmh-generator-annprocess</artifactId>
30+
<version>${jmh.version}</version>
31+
<scope>provided</scope>
32+
</dependency>
33+
34+
<dependency>
35+
<groupId>jakarta.annotation</groupId>
36+
<artifactId>jakarta.annotation-api</artifactId>
37+
<version>${jakarta-annotation-api}</version>
38+
</dependency>
39+
40+
<dependency>
41+
<groupId>jakarta.persistence</groupId>
42+
<artifactId>jakarta.persistence-api</artifactId>
43+
<version>${jakarta-persistence-api}</version>
44+
<scope>compile</scope>
45+
</dependency>
46+
47+
<dependency>
48+
<groupId>${hibernate.groupId}.orm</groupId>
49+
<artifactId>hibernate-core</artifactId>
50+
<version>${hibernate}</version>
51+
<exclusions>
52+
<exclusion>
53+
<groupId>net.bytebuddy</groupId>
54+
<artifactId>byte-buddy</artifactId>
55+
</exclusion>
56+
</exclusions>
57+
<scope>compile</scope>
58+
</dependency>
59+
60+
<dependency>
61+
<groupId>${hibernate.groupId}.orm</groupId>
62+
<artifactId>hibernate-jpamodelgen</artifactId>
63+
<version>${hibernate}</version>
64+
<scope>provided</scope>
65+
</dependency>
66+
67+
<dependency>
68+
<groupId>jakarta.xml.bind</groupId>
69+
<artifactId>jakarta.xml.bind-api</artifactId>
70+
<version>${jaxb}</version>
71+
<scope>provided</scope>
72+
</dependency>
73+
74+
<dependency>
75+
<groupId>com.github.mp911de.microbenchmark-runner</groupId>
76+
<artifactId>microbenchmark-runner-junit5</artifactId>
77+
<version>0.4.0.RELEASE</version>
78+
<scope>test</scope>
79+
</dependency>
80+
81+
<dependency>
82+
<groupId>com.h2database</groupId>
83+
<artifactId>h2</artifactId>
84+
<version>${h2}</version>
85+
<scope>test</scope>
86+
</dependency>
87+
88+
</dependencies>
89+
90+
<build>
91+
<plugins>
92+
<plugin>
93+
<groupId>org.apache.maven.plugins</groupId>
94+
<artifactId>maven-jar-plugin</artifactId>
95+
<configuration>
96+
<archive>
97+
<manifestEntries>
98+
<Automatic-Module-Name>org.springframework.data.jpa.performance.tests</Automatic-Module-Name>
99+
</manifestEntries>
100+
</archive>
101+
</configuration>
102+
</plugin>
103+
</plugins>
104+
</build>
105+
106+
<repositories>
107+
<repository>
108+
<id>jitpack.io</id>
109+
<url>https://jitpack.io</url>
110+
</repository>
111+
</repositories>
112+
113+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2024 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.model;
17+
18+
/**
19+
* @author Christoph Strobl
20+
*/
21+
public interface IPersonProjection {
22+
23+
String getFirstname();
24+
String getLastname();
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
* Copyright 2024 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.model;
17+
18+
import java.util.Set;
19+
20+
import jakarta.persistence.Column;
21+
import jakarta.persistence.Entity;
22+
import jakarta.persistence.GeneratedValue;
23+
import jakarta.persistence.GenerationType;
24+
import jakarta.persistence.Id;
25+
import jakarta.persistence.ManyToMany;
26+
import jakarta.persistence.Table;
27+
28+
/**
29+
* @author Christoph Strobl
30+
*/
31+
@Entity
32+
@Table(name = "person")
33+
public class Person {
34+
35+
@Id
36+
@GeneratedValue(strategy = GenerationType.AUTO) //
37+
private Integer id;
38+
39+
private String firstname;
40+
private String lastname;
41+
42+
private int age;
43+
private boolean decased;
44+
45+
@Column(nullable = false, unique = true) //
46+
private String emailAddress;
47+
48+
@ManyToMany //
49+
private Set<Profile> profiles;
50+
51+
public Person() {}
52+
53+
public Person(String firstname, String lastname) {
54+
this(firstname, lastname, "%s.%[email protected]");
55+
}
56+
57+
public Person(String firstname, String lastname, String emailAddress) {
58+
59+
this.firstname = firstname;
60+
this.lastname = lastname;
61+
this.emailAddress = emailAddress;
62+
}
63+
64+
public Integer getId() {
65+
return id;
66+
}
67+
68+
public void setId(Integer id) {
69+
this.id = id;
70+
}
71+
72+
public String getEmailAddress() {
73+
return emailAddress;
74+
}
75+
76+
public void setEmailAddress(String emailAddress) {
77+
this.emailAddress = emailAddress;
78+
}
79+
80+
public String getFirstname() {
81+
return firstname;
82+
}
83+
84+
public void setFirstname(String firstname) {
85+
this.firstname = firstname;
86+
}
87+
88+
public String getLastname() {
89+
return lastname;
90+
}
91+
92+
public void setLastname(String lastname) {
93+
this.lastname = lastname;
94+
}
95+
96+
public int getAge() {
97+
return age;
98+
}
99+
100+
public void setAge(int age) {
101+
this.age = age;
102+
}
103+
104+
public boolean isDecased() {
105+
return decased;
106+
}
107+
108+
public void setDecased(boolean decased) {
109+
this.decased = decased;
110+
}
111+
112+
public Set<Profile> getProfiles() {
113+
return profiles;
114+
}
115+
116+
public void setProfiles(Set<Profile> profiles) {
117+
this.profiles = profiles;
118+
}
119+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2024 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.model;
17+
18+
import jakarta.persistence.Entity;
19+
import jakarta.persistence.GeneratedValue;
20+
import jakarta.persistence.Id;
21+
22+
/**
23+
* @author Christoph Strobl
24+
*/
25+
@Entity
26+
public class Profile {
27+
28+
@Id
29+
@GeneratedValue private Integer id;
30+
private String name;
31+
32+
public Profile() {}
33+
34+
public Profile(String name) {
35+
this.name = name;
36+
}
37+
38+
public Integer getId() {
39+
return id;
40+
}
41+
42+
public void setId(Integer id) {
43+
this.id = id;
44+
}
45+
46+
public String getName() {
47+
return name;
48+
}
49+
50+
public void setName(String name) {
51+
this.name = name;
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2024 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.repository;
17+
18+
import java.util.List;
19+
20+
import org.springframework.data.jpa.model.IPersonProjection;
21+
import org.springframework.data.jpa.model.Person;
22+
import org.springframework.data.repository.ListCrudRepository;
23+
24+
/**
25+
* @author Christoph Strobl
26+
*/
27+
public interface PersonRepository extends ListCrudRepository<Person, Integer> {
28+
29+
List<Person> findAllByFirstname(String firstname);
30+
31+
List<IPersonProjection> findAllAndProjectToInterfaceByFirstname(String firstname);
32+
33+
@Query("SELECT p FROM org.springframework.data.jpa.model.Person p WHERE p.firstname = ?1")
34+
List<Person> findAllWithAnnotatedQueryByFirstname(String firstname);
35+
36+
@Query(value = "SELECT * FROM person WHERE firstname = ?1", nativeQuery = true)
37+
List<Person> findAllWithNativeQueryByFirstname(String firstname);
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence https://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
3+
<persistence-unit name="benchmark">
4+
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
5+
<class>org.springframework.data.jpa.domain.AbstractPersistable</class>
6+
<class>org.springframework.data.jpa.domain.AbstractAuditable</class>
7+
<class>org.springframework.data.jpa.model.Person</class>
8+
<class>org.springframework.data.jpa.model.Profile</class>
9+
<exclude-unlisted-classes>true</exclude-unlisted-classes>
10+
</persistence-unit>
11+
</persistence>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
4+
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
5+
<encoder>
6+
<pattern>%d %5p %40.40c:%4L - %m%n</pattern>
7+
</encoder>
8+
</appender>
9+
10+
<logger name="org.springframework.data" level="error"/>
11+
12+
<!-- <logger name="org.hibernate.SQL" level="debug" />-->
13+
14+
<root level="error">
15+
<appender-ref ref="console"/>
16+
</root>
17+
18+
</configuration>

0 commit comments

Comments
 (0)