Skip to content

Commit 1bc3f89

Browse files
committed
[BAEL-9370] Introduced module with spring-data-jpa repositories:
- one not using AOT at all - one using AOT - one using AOT AND AOT repositories Will compare the performance of each solution
1 parent cdcc7a2 commit 1bc3f89

File tree

58 files changed

+1852
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1852
-0
lines changed

persistence-modules/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
<module>spring-data-jpa-repo</module>
110110
<module>spring-data-jpa-repo-2</module>
111111
<module>spring-data-jpa-repo-4</module>
112+
<module>spring-data-jpa-repo-5</module>
112113
<module>spring-data-jdbc</module>
113114
<module>spring-data-jpa-simple</module>
114115
<module>spring-data-keyvalue</module>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
<groupId>com.baeldung</groupId>
7+
<artifactId>spring-data-jpa-repo-5</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>pom</packaging>
10+
11+
<modules>
12+
<module>spring-data-jpa-aot</module>
13+
<module>spring-data-jpa-aot-repository</module>
14+
<module>spring-data-jpa-not-aot</module>
15+
</modules>
16+
17+
<parent>
18+
<groupId>org.springframework.boot</groupId>
19+
<artifactId>spring-boot-starter-parent</artifactId>
20+
<version>4.0.0-RC1</version>
21+
</parent>
22+
23+
<properties>
24+
<java.version>25</java.version>
25+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
26+
</properties>
27+
</project>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Compile AOT
2+
3+
```shell
4+
mvn clean install -Paot-repo
5+
```
6+
7+
Compilation time: `14.200 s`
8+
9+
1) run using maven and the spring-boot plugin:
10+
11+
```shell
12+
mvn spring-boot:run -Dspring.aot.enabled=true -Dspring.aot.repositories.enabled=true
13+
```
14+
15+
Startup times:
16+
`Root WebApplicationContext: initialization completed in 477 ms`
17+
`Started Application in 2.031 seconds`
18+
19+
2) run using the jar (same as 1 mostly)
20+
21+
```shell
22+
java -Dspring.aot.enabled=true \
23+
-Dspring.aot.repositories.enabled=true \
24+
-agentlib:native-image-agent=config-output-dir=target/native-image-hints \
25+
-jar target/spring-data-jpa-aot-repository-0.0.1-SNAPSHOT.jar
26+
```
27+
28+
Startup times:
29+
`Root WebApplicationContext: initialization completed in 452 ms`
30+
`Started Application in 3.26 seconds`
31+
32+
**NOTE**:
33+
AOT is a mandatory step to transform a Spring application to a native executable, so it is automatically enabled when running within a native image. However it is also possible to use AOT optimizations on the JVM by setting the spring.aot.enabled System
34+
property to true.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
<packaging>jar</packaging>
7+
8+
<parent>
9+
<groupId>com.baeldung</groupId>
10+
<artifactId>spring-data-jpa-repo-5</artifactId>
11+
<version>0.0.1-SNAPSHOT</version>
12+
<relativePath>../../spring-data-jpa-repo-5</relativePath>
13+
</parent>
14+
15+
<artifactId>spring-data-jpa-aot-repository</artifactId>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.springframework.boot</groupId>
20+
<artifactId>spring-boot-starter-web</artifactId>
21+
</dependency>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter-data-jpa</artifactId>
25+
</dependency>
26+
27+
<dependency>
28+
<groupId>com.h2database</groupId>
29+
<artifactId>h2</artifactId>
30+
<scope>runtime</scope>
31+
</dependency>
32+
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter-test</artifactId>
36+
<scope>test</scope>
37+
</dependency>
38+
</dependencies>
39+
40+
<profiles>
41+
<profile>
42+
<id>aot-repo</id>
43+
<build>
44+
<plugins>
45+
<plugin>
46+
<groupId>org.springframework.boot</groupId>
47+
<artifactId>spring-boot-maven-plugin</artifactId>
48+
<configuration>
49+
<mainClass>com.baeldung.spring.aotrepository.Application</mainClass>
50+
<jvmArguments>
51+
-agentlib:native-image-agent=config-output-dir=target/native-image-hints/
52+
</jvmArguments>
53+
</configuration>
54+
<executions>
55+
<execution>
56+
<id>process-aot</id>
57+
<goals>
58+
<goal>process-aot</goal>
59+
</goals>
60+
</execution>
61+
</executions>
62+
</plugin>
63+
</plugins>
64+
</build>
65+
</profile>
66+
</profiles>
67+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.baeldung.spring.aotrepository;
2+
3+
import org.apache.commons.logging.Log;
4+
import org.apache.commons.logging.LogFactory;
5+
import org.springframework.boot.SpringApplication;
6+
import org.springframework.boot.autoconfigure.SpringBootApplication;
7+
8+
@SpringBootApplication
9+
public class Application {
10+
11+
private static final Log logger = LogFactory.getLog(Application.class);
12+
13+
public static void main(String[] args) {
14+
logger.info("Application starts..");
15+
16+
SpringApplication.run(Application.class, args);
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.baeldung.spring.aotrepository.entity;
2+
3+
import jakarta.persistence.Column;
4+
import jakarta.persistence.Entity;
5+
import jakarta.persistence.GeneratedValue;
6+
import jakarta.persistence.Id;
7+
import jakarta.persistence.Table;
8+
9+
@Entity
10+
@Table(name = "ADDRESS")
11+
public class Address {
12+
13+
@Id
14+
@GeneratedValue
15+
private Long id;
16+
private String street;
17+
private String city;
18+
@Column(name = "post_code")
19+
private String postCode;
20+
21+
public Long getId() {
22+
return id;
23+
}
24+
25+
public void setId(Long id) {
26+
this.id = id;
27+
}
28+
29+
public String getStreet() {
30+
return street;
31+
}
32+
33+
public void setStreet(String street) {
34+
this.street = street;
35+
}
36+
37+
public String getCity() {
38+
return city;
39+
}
40+
41+
public void setCity(String city) {
42+
this.city = city;
43+
}
44+
45+
public String getPostCode() {
46+
return postCode;
47+
}
48+
49+
public void setPostCode(String postCode) {
50+
this.postCode = postCode;
51+
}
52+
53+
@Override
54+
public String toString() {
55+
return "User[id=" + id + ", street=" + street + ", city=" + city + ", postCode=" + postCode + "]";
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.baeldung.spring.aotrepository.entity;
2+
3+
import jakarta.persistence.Entity;
4+
import jakarta.persistence.Id;
5+
import jakarta.persistence.Table;
6+
7+
@Entity
8+
@Table(name = "INVENTORY")
9+
public class Inventory {
10+
11+
@Id
12+
private Long productId;
13+
private Long balance;
14+
15+
public Long getProductId() {
16+
return productId;
17+
}
18+
19+
public void setProductId(Long productId) {
20+
this.productId = productId;
21+
}
22+
23+
public Long getBalance() {
24+
return balance;
25+
}
26+
27+
public void setBalance(Long balance) {
28+
this.balance = balance;
29+
}
30+
31+
@Override
32+
public String toString() {
33+
return "Order [productId=" + productId + ", balance=" + balance + "]";
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.baeldung.spring.aotrepository.entity;
2+
3+
import jakarta.persistence.Entity;
4+
import jakarta.persistence.Id;
5+
import jakarta.persistence.Table;
6+
7+
@Entity
8+
@Table(name = "ORDERS")
9+
public class Order {
10+
11+
@Id
12+
private Long id;
13+
private String productId;
14+
private Long amount;
15+
16+
public Long getId() {
17+
return id;
18+
}
19+
20+
public void setId(Long orderId) {
21+
this.id = orderId;
22+
}
23+
24+
public String getProductId() {
25+
return productId;
26+
}
27+
28+
public void setProductId(String productId) {
29+
this.productId = productId;
30+
}
31+
32+
public Long getAmount() {
33+
return amount;
34+
}
35+
36+
public void setAmount(Long amount) {
37+
this.amount = amount;
38+
}
39+
40+
@Override
41+
public String toString() {
42+
return "Order [productId=" + productId + ", id=" + id + ", amount=" + amount + "]";
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.baeldung.spring.aotrepository.entity;
2+
3+
import jakarta.persistence.Entity;
4+
import jakarta.persistence.Id;
5+
import jakarta.persistence.Table;
6+
7+
@Entity
8+
@Table(name = "PRODUCTS")
9+
public class Product {
10+
11+
@Id
12+
private Long id;
13+
private String name;
14+
private double price;
15+
16+
public Product() {
17+
super();
18+
}
19+
20+
private Product(Long id, String name, double price) {
21+
super();
22+
this.id = id;
23+
this.name = name;
24+
this.price = price;
25+
}
26+
27+
public Long getId() {
28+
return id;
29+
}
30+
31+
public void setId(final Long id) {
32+
this.id = id;
33+
}
34+
35+
public String getName() {
36+
return name;
37+
}
38+
39+
public void setName(final String name) {
40+
this.name = name;
41+
}
42+
43+
public double getPrice() {
44+
return price;
45+
}
46+
47+
public void setPrice(final double price) {
48+
this.price = price;
49+
}
50+
51+
@Override
52+
public String toString() {
53+
return "Product [name=" + name + ", id=" + id + ", price=" + price + "]";
54+
}
55+
}

0 commit comments

Comments
 (0)