BAEL-5545: moved batch performance related classes into existing spring-jdbc module
This commit is contained in:
parent
bce765b959
commit
5ea3e49db0
|
@ -1,60 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<artifactId>spring-jdbc-batch</artifactId>
|
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
|
||||||
<name>spring-jdbc-batch</name>
|
|
||||||
<description>Demo project for Spring Boot Jdbc batch support</description>
|
|
||||||
|
|
||||||
<parent>
|
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>parent-boot-2</artifactId>
|
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
|
||||||
<relativePath>../../parent-boot-2</relativePath>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<java.version>11</java.version>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.postgresql</groupId>
|
|
||||||
<artifactId>postgresql</artifactId>
|
|
||||||
<scope>runtime</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<source>${java.version}</source>
|
|
||||||
<target>${java.version}</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</project>
|
|
|
@ -31,6 +31,11 @@
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.postgresql</groupId>
|
||||||
|
<artifactId>postgresql</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -1,14 +1,17 @@
|
||||||
package com.baeldung.spring.jdbc.batch;
|
package com.baeldung.spring.jdbc.batch;
|
||||||
|
|
||||||
import com.baeldung.spring.jdbc.batch.service.ProductService;
|
import com.baeldung.spring.jdbc.batch.service.ProductService;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.boot.CommandLineRunner;
|
import org.springframework.boot.CommandLineRunner;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@ComponentScan(basePackages = "com.baeldung.spring.jdbc.batch")
|
||||||
public class SpringJdbcBatchPerformanceApplication implements CommandLineRunner {
|
public class SpringJdbcBatchPerformanceApplication implements CommandLineRunner {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -30,7 +33,7 @@ public class SpringJdbcBatchPerformanceApplication implements CommandLineRunner
|
||||||
long regularElapsedTime = simpleProductService.createProducts(recordCount);
|
long regularElapsedTime = simpleProductService.createProducts(recordCount);
|
||||||
long batchElapsedTime = batchProductService.createProducts(recordCount);
|
long batchElapsedTime = batchProductService.createProducts(recordCount);
|
||||||
|
|
||||||
System.out.println("-".repeat(50));
|
System.out.println(String.join("", Collections.nCopies(50, "-")));
|
||||||
System.out.format("%-20s%-5s%-10s%-5s%8sms\n", "Regular inserts", "|", recordCount, "|", regularElapsedTime);
|
System.out.format("%-20s%-5s%-10s%-5s%8sms\n", "Regular inserts", "|", recordCount, "|", regularElapsedTime);
|
||||||
System.out.format("%-20s%-5s%-10s%-5s%8sms\n", "Batch inserts", "|", recordCount, "|", batchElapsedTime);
|
System.out.format("%-20s%-5s%-10s%-5s%8sms\n", "Batch inserts", "|", recordCount, "|", batchElapsedTime);
|
||||||
System.out.printf("Total gain: %d %s\n", calculateGainInPercent(regularElapsedTime, batchElapsedTime), "%");
|
System.out.printf("Total gain: %d %s\n", calculateGainInPercent(regularElapsedTime, batchElapsedTime), "%");
|
|
@ -5,11 +5,13 @@ import com.baeldung.spring.jdbc.batch.repo.SimpleProductRepository;
|
||||||
import com.baeldung.spring.jdbc.batch.service.ProductService;
|
import com.baeldung.spring.jdbc.batch.service.ProductService;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.PropertySource;
|
||||||
|
|
||||||
import java.time.Clock;
|
import java.time.Clock;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
|
@PropertySource("classpath:com/baeldung/spring/jdbc/batch/application.properties")
|
||||||
public class AppConfig {
|
public class AppConfig {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
|
@ -2,4 +2,4 @@ spring.datasource.url=jdbc:postgresql://localhost:5432/sample-baeldung-db
|
||||||
spring.datasource.username=postgres
|
spring.datasource.username=postgres
|
||||||
spring.datasource.password=root
|
spring.datasource.password=root
|
||||||
spring.datasource.driver-class-name=org.postgresql.Driver
|
spring.datasource.driver-class-name=org.postgresql.Driver
|
||||||
spring.datasource.hikari.data-source-properties.reWriteBatchedInserts=true
|
spring.datasource.hikari.data-source-properties.reWriteBatchedInserts=true
|
|
@ -2,7 +2,6 @@ package com.baeldung.spring.jdbc.batch.service;
|
||||||
|
|
||||||
import com.baeldung.spring.jdbc.batch.model.Product;
|
import com.baeldung.spring.jdbc.batch.model.Product;
|
||||||
import com.baeldung.spring.jdbc.batch.repo.ProductRepository;
|
import com.baeldung.spring.jdbc.batch.repo.ProductRepository;
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
2
pom.xml
2
pom.xml
|
@ -1260,7 +1260,6 @@
|
||||||
<module>testing-modules/testing-assertions</module>
|
<module>testing-modules/testing-assertions</module>
|
||||||
<module>persistence-modules/fauna</module>
|
<module>persistence-modules/fauna</module>
|
||||||
<module>lightrun</module>
|
<module>lightrun</module>
|
||||||
<module>persistence-modules/spring-jdbc-batch</module>
|
|
||||||
</modules>
|
</modules>
|
||||||
</profile>
|
</profile>
|
||||||
|
|
||||||
|
@ -1328,7 +1327,6 @@
|
||||||
<module>spring-boot-modules/spring-boot-camel</module>
|
<module>spring-boot-modules/spring-boot-camel</module>
|
||||||
<module>testing-modules/testing-assertions</module>
|
<module>testing-modules/testing-assertions</module>
|
||||||
<module>persistence-modules/fauna</module>
|
<module>persistence-modules/fauna</module>
|
||||||
<module>persistence-modules/spring-jdbc-batch</module>
|
|
||||||
<module>lightrun</module>
|
<module>lightrun</module>
|
||||||
</modules>
|
</modules>
|
||||||
</profile>
|
</profile>
|
||||||
|
|
Loading…
Reference in New Issue