From 942d4ddc619ba51dd865b27760d74b6b993a0aba Mon Sep 17 00:00:00 2001 From: Himaja Dhanyamraju <43470317+HimajaDhanyamraju2@users.noreply.github.com> Date: Tue, 9 Jul 2024 17:43:33 +0530 Subject: [PATCH] MOSIP-33046: Added in-memory batchDatasource for metadata tables (#1536) Signed-off-by: HimajaDhanyamraju2 Co-authored-by: HimajaDhanyamraju2 --- kernel/kernel-salt-generator/pom.xml | 4 ++++ .../saltgenerator/config/SaltGeneratorConfig.java | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/kernel/kernel-salt-generator/pom.xml b/kernel/kernel-salt-generator/pom.xml index 431e57af888..40e02308d00 100644 --- a/kernel/kernel-salt-generator/pom.xml +++ b/kernel/kernel-salt-generator/pom.xml @@ -41,6 +41,10 @@ + + com.h2database + h2 + org.springframework.boot spring-boot-starter-batch diff --git a/kernel/kernel-salt-generator/src/main/java/io/mosip/kernel/saltgenerator/config/SaltGeneratorConfig.java b/kernel/kernel-salt-generator/src/main/java/io/mosip/kernel/saltgenerator/config/SaltGeneratorConfig.java index f1ada3fd643..c9638c5debc 100644 --- a/kernel/kernel-salt-generator/src/main/java/io/mosip/kernel/saltgenerator/config/SaltGeneratorConfig.java +++ b/kernel/kernel-salt-generator/src/main/java/io/mosip/kernel/saltgenerator/config/SaltGeneratorConfig.java @@ -14,6 +14,7 @@ import javax.sql.DataSource; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.batch.BatchDataSource; import org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -21,6 +22,9 @@ import org.springframework.core.env.Environment; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.jdbc.datasource.DriverManagerDataSource; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; import org.springframework.orm.jpa.JpaTransactionManager; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; @@ -111,4 +115,15 @@ public PlatformTransactionManager transactionManager() { return new DataSourceTransactionManager(dataSource()); } + @Bean + @BatchDataSource + public DataSource batchDatasource() { + EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); + EmbeddedDatabase embeddedDatabase = builder + .setType(EmbeddedDatabaseType.H2) + .generateUniqueName(true) + .build(); + return embeddedDatabase; + } + }