Last active
August 15, 2024 07:34
-
-
Save dakoctba/1047ca084118ff46a1a917726f99a2b2 to your computer and use it in GitHub Desktop.
Revisions
-
dakoctba revised this gist
Jan 22, 2020 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1 +0,0 @@ -
dakoctba revised this gist
Jan 22, 2020 . No changes.There are no files selected for viewing
-
dakoctba revised this gist
Jan 22, 2020 . 2 changed files with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -37,9 +37,9 @@ public Jdbi secondaryJdbi(@Qualifier("datasource2") DataSource ds, List<JdbiPlug } @Bean public JdbiPlugin sqlObjectPlugin() { return new SqlObjectPlugin(); } @Bean public CityDAO cityDao(@Qualifier("jdbi-1") Jdbi jdbi) { This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1 +1 @@ # Spring Boot + JDBI + Multiple Databases -
dakoctba revised this gist
Jan 22, 2020 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,2 +1 @@ # Spring Boot + JDBI + Multiple Databases -
dakoctba revised this gist
Jan 22, 2020 . 1 changed file with 54 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,54 @@ import java.util.List; import javax.sql.DataSource; import org.jdbi.v3.core.Jdbi; import org.jdbi.v3.core.mapper.RowMapper; import org.jdbi.v3.core.spi.JdbiPlugin; import org.jdbi.v3.sqlobject.SqlObjectPlugin; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy; import br.com.company.produto.dao.dominio.CityDAO; import br.com.company.produto.dao.dw.ProfessionDAO; @Configuration public class AppConfig { @Bean("jdbi-1") public Jdbi jdbi(@Qualifier("datasource1") DataSource ds, List<JdbiPlugin> plugins, List<RowMapper<?>> mappers) { TransactionAwareDataSourceProxy proxy = new TransactionAwareDataSourceProxy(ds); Jdbi jdbi = Jdbi.create(proxy); plugins.forEach(plugin -> jdbi.installPlugin(plugin)); mappers.forEach(mapper -> jdbi.registerRowMapper(mapper)); return jdbi; } @Bean("jdbi-2") public Jdbi secondaryJdbi(@Qualifier("datasource2") DataSource ds, List<JdbiPlugin> plugins, List<RowMapper<?>> mappers) { TransactionAwareDataSourceProxy proxy = new TransactionAwareDataSourceProxy(ds); Jdbi jdbi = Jdbi.create(proxy); plugins.forEach(plugin -> jdbi.installPlugin(plugin)); mappers.forEach(mapper -> jdbi.registerRowMapper(mapper)); return jdbi; } @Bean public JdbiPlugin sqlObjectPlugin() { return new SqlObjectPlugin(); } @Bean public CityDAO cityDao(@Qualifier("jdbi-1") Jdbi jdbi) { return jdbi.onDemand(CityDAO.class); } @Bean public ProfessionDAO professionDao(@Qualifier("jdbi-2") Jdbi jdbi) { return jdbi.onDemand(ProfessionDAO.class); } } -
dakoctba revised this gist
Jan 22, 2020 . 1 changed file with 43 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ import javax.sql.DataSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import org.springframework.jdbc.datasource.DataSourceTransactionManager; @Configuration public class DataSourceConfig { @Bean(name = "datasource1") @ConfigurationProperties("spring.datasource.db1") @Primary public DataSource db1Datasource() { return DataSourceBuilder.create().build(); } @Bean(name = "datasource2") @ConfigurationProperties("spring.datasource.db2") public DataSource db2Datasource() { return DataSourceBuilder.create().build(); } @Bean(name="tm1") @Autowired @Primary DataSourceTransactionManager tm1(@Qualifier ("datasource1") DataSource datasource) { DataSourceTransactionManager txm = new DataSourceTransactionManager(datasource); return txm; } @Bean(name="tm2") @Autowired DataSourceTransactionManager tm2(@Qualifier ("datasource2") DataSource datasource) { DataSourceTransactionManager txm = new DataSourceTransactionManager(datasource); return txm; } } -
dakoctba revised this gist
Jan 22, 2020 . 1 changed file with 20 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false spring.jpa.database=default # # Primary database # spring.datasource.db1.jdbcUrl=jdbc:postgresql://localhost:5432/<database> spring.datasource.db1.driver-class-name=org.postgresql.Driver spring.datasource.db1.username=postgres spring.datasource.db1.password=postgres # # Secondary database # spring.datasource.db2.jdbcUrl=jdbc:postgresql://localhost:5432/<database> spring.datasource.db2.driver-class-name=org.postgresql.Driver spring.datasource.db2.username=postgres spring.datasource.db2.password=postgres -
dakoctba created this gist
Jan 22, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ # Spring Boot + JDBI + Multiple Databases