generated from pagopa/template-java-spring-microservice
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from pagopa/config-for-nexi
Config for Nexi Postgres
- Loading branch information
Showing
90 changed files
with
1,097 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...in/java/it/gov/pagopa/nodo/datamigration/config/datasource/H2DatasourceConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package it.gov.pagopa.nodo.datamigration.config.datasource; | ||
|
||
import com.zaxxer.hikari.HikariConfig; | ||
import com.zaxxer.hikari.HikariDataSource; | ||
import jakarta.persistence.EntityManagerFactory; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | ||
import org.springframework.orm.jpa.JpaTransactionManager; | ||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; | ||
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; | ||
import org.springframework.transaction.PlatformTransactionManager; | ||
import org.springframework.transaction.annotation.EnableTransactionManagement; | ||
|
||
import javax.sql.DataSource; | ||
import java.util.Properties; | ||
|
||
@Configuration | ||
@EnableTransactionManagement | ||
@EnableJpaRepositories( | ||
entityManagerFactoryRef = "h2EntityManagerFactory", | ||
transactionManagerRef = "h2TransactionManager", | ||
basePackages = { "it.gov.pagopa.nodo.datamigration.repository.h2" } | ||
) | ||
public class H2DatasourceConfiguration { | ||
|
||
@Value("${persistence.h2.jdbc-url}") | ||
private String jdbcUrl; | ||
|
||
@Value("${persistence.h2.username}") | ||
private String username; | ||
|
||
@Value("${persistence.h2.password}") | ||
private String password; | ||
|
||
// @Value("${persistence.h2.default_schema}") | ||
// private String defaultSchema; | ||
|
||
@Value("${persistence.h2.driver-class-name}") | ||
private String driverClassName; | ||
|
||
@Value("${persistence.h2.hikari.connectionTimeout}") | ||
private String connectionTimeout; | ||
|
||
@Value("${persistence.h2.hikari.maxLifetime}") | ||
private String maxLifetime; | ||
|
||
@Value("${persistence.h2.hikari.keepaliveTime}") | ||
private String keepaliveTime; | ||
|
||
@Value("${persistence.h2.jdbc.batch.size}") | ||
private Integer jdbcBatchSize; | ||
|
||
@Bean(name = "h2DataSource") | ||
public DataSource dataSource() { | ||
HikariConfig hikariConfig = new HikariConfig(); | ||
hikariConfig.setUsername(username); | ||
hikariConfig.setPassword(password); | ||
hikariConfig.setJdbcUrl(jdbcUrl); | ||
hikariConfig.setDriverClassName(driverClassName); | ||
hikariConfig.setConnectionTimeout(Long.parseLong(connectionTimeout)); | ||
hikariConfig.setMaxLifetime(Long.parseLong(maxLifetime)); | ||
hikariConfig.setKeepaliveTime(Long.parseLong(keepaliveTime)); | ||
return new HikariDataSource(hikariConfig); | ||
} | ||
|
||
@Bean(name = "h2EntityManagerFactory") | ||
public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean ( | ||
EntityManagerFactoryBuilder builder, | ||
@Qualifier("h2DataSource") DataSource dataSource | ||
) { | ||
LocalContainerEntityManagerFactoryBean entityManager = builder | ||
.dataSource(dataSource) | ||
.packages("it.gov.pagopa.nodo.datamigration.entity") | ||
.persistenceUnit("h2Unit") | ||
.build(); | ||
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); | ||
entityManager.setJpaVendorAdapter(vendorAdapter); | ||
|
||
|
||
Properties props = new Properties(); | ||
props.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect"); | ||
props.put("hibernate.database-platform", "org.hibernate.dialect.H2Dialect"); | ||
props.put("hibernate.jdbc.batch_size", jdbcBatchSize); | ||
props.put("hibernate.ddl-auto", "none"); | ||
props.put("hibernate.hbm2ddl.auto", "create-drop"); | ||
props.put("hibernate.jdbc.lob.non_contextual_creation", "true"); | ||
entityManager.setJpaProperties(props); | ||
|
||
return entityManager; | ||
} | ||
|
||
@Bean(name = "h2TransactionManager") | ||
public PlatformTransactionManager transactionManager ( | ||
@Qualifier("h2EntityManagerFactory") EntityManagerFactory entityManagerFactory) { | ||
return new JpaTransactionManager(entityManagerFactory); | ||
} | ||
} | ||
|
Oops, something went wrong.