This repository has been archived by the owner on Oct 24, 2023. It is now read-only.
-
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.
Finally!! Relevant reading: https://medium.com/@joeclever/using-multiple-datasources-with-spring-boot-and-spring-data-6430b00c02e7 https://scattercode.co.uk/2016/01/05/multiple-databases-with-spring-boot-and-spring-data-jpa/ Application settings is not implicitely added to new data source: spring-projects/spring-boot#3654
- Loading branch information
Showing
33 changed files
with
189 additions
and
105 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
49 changes: 49 additions & 0 deletions
49
vent-backend/src/main/kotlin/com/hernil/vent/ProtusConfig.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,49 @@ | ||
package com.hernil.vent; | ||
|
||
import javax.persistence.EntityManagerFactory; | ||
import javax.sql.DataSource; | ||
|
||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.boot.jdbc.DataSourceBuilder; | ||
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.transaction.PlatformTransactionManager; | ||
import org.springframework.transaction.annotation.EnableTransactionManagement; | ||
|
||
@Configuration | ||
@EnableTransactionManagement | ||
@EnableJpaRepositories( | ||
entityManagerFactoryRef = "protusEntityManagerFactory", | ||
transactionManagerRef = "protusTransactionManager", | ||
basePackages = { "com.hernil.vent.protus" }) | ||
public class ProtusConfig { | ||
|
||
@Bean(name = "protusDataSource") | ||
@ConfigurationProperties(prefix="spring.datasource.protus") | ||
public DataSource protusDataSource() { | ||
return DataSourceBuilder.create().build(); | ||
} | ||
|
||
@Bean(name = "protusEntityManagerFactory") | ||
public LocalContainerEntityManagerFactoryBean protusEntityManagerFactory( | ||
EntityManagerFactoryBuilder builder, | ||
@Qualifier("protusDataSource") DataSource protusDataSource) { | ||
return builder | ||
.dataSource(protusDataSource) | ||
.packages("com.hernil.vent.protus") | ||
.persistenceUnit("protus") | ||
.build(); | ||
} | ||
|
||
@Bean(name = "protusTransactionManager") | ||
public PlatformTransactionManager protusTransactionManager( | ||
@Qualifier("protusEntityManagerFactory") EntityManagerFactory protusEntityManagerFactory) { | ||
return new JpaTransactionManager(protusEntityManagerFactory); | ||
} | ||
|
||
} |
33 changes: 0 additions & 33 deletions
33
vent-backend/src/main/kotlin/com/hernil/vent/VentApplicationConfig.kt
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
vent-backend/src/main/kotlin/com/hernil/vent/VentConfig.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,54 @@ | ||
package com.hernil.vent; | ||
|
||
import javax.persistence.EntityManagerFactory; | ||
import javax.sql.DataSource; | ||
|
||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.boot.jdbc.DataSourceBuilder; | ||
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | ||
import org.springframework.orm.jpa.JpaTransactionManager; | ||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; | ||
import org.springframework.transaction.PlatformTransactionManager; | ||
import org.springframework.transaction.annotation.EnableTransactionManagement; | ||
|
||
@Configuration | ||
@EnableTransactionManagement | ||
@EnableJpaRepositories( | ||
entityManagerFactoryRef = "entityManagerFactory", | ||
basePackages = {"com.hernil.vent.application"}) | ||
public class VentConfig { | ||
|
||
@Primary | ||
@Bean(name = "dataSource") | ||
@ConfigurationProperties(prefix="spring.datasource.vent") | ||
public DataSource dataSource() { | ||
return DataSourceBuilder.create().build(); | ||
} | ||
|
||
@Primary | ||
@Bean(name = "entityManagerFactory") | ||
public LocalContainerEntityManagerFactoryBean entityManagerFactory( | ||
EntityManagerFactoryBuilder builder, JpaProperties jpaProperties, | ||
@Qualifier("dataSource") DataSource dataSource) { | ||
return builder | ||
.dataSource(dataSource) | ||
.packages("com.hernil.vent.application") | ||
.persistenceUnit("vent") | ||
.properties(jpaProperties.getHibernateProperties("dataSource")) | ||
.build(); | ||
} | ||
|
||
@Primary | ||
@Bean(name = "transactionManager") | ||
public PlatformTransactionManager transactionManager( | ||
@Qualifier("entityManagerFactory") EntityManagerFactory entityManagerFactory) { | ||
return new JpaTransactionManager(entityManagerFactory); | ||
} | ||
|
||
} |
4 changes: 2 additions & 2 deletions
4
...rnil/vent/controllers/CourseController.kt → ...plication/controllers/CourseController.kt
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
6 changes: 3 additions & 3 deletions
6
...hernil/vent/controllers/DataController.kt → ...application/controllers/DataController.kt
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
6 changes: 3 additions & 3 deletions
6
...l/vent/controllers/GreetingsController.kt → ...cation/controllers/GreetingsController.kt
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
5 changes: 2 additions & 3 deletions
5
...nil/vent/controllers/StudentController.kt → ...lication/controllers/StudentController.kt
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
3 changes: 2 additions & 1 deletion
3
...ain/kotlin/com/hernil/vent/domain/Data.kt → ...om/hernil/vent/application/domain/Data.kt
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
2 changes: 1 addition & 1 deletion
2
...kotlin/com/hernil/vent/domain/Greeting.kt → ...ernil/vent/application/domain/Greeting.kt
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
package com.hernil.vent.domain | ||
package com.hernil.vent.application.domain | ||
|
||
data class Greeting(val id: Long, val content: String) |
2 changes: 1 addition & 1 deletion
2
...n/kotlin/com/hernil/vent/domain/Person.kt → .../hernil/vent/application/domain/Person.kt
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
2 changes: 1 addition & 1 deletion
2
.../kotlin/com/hernil/vent/domain/Teacher.kt → ...hernil/vent/application/domain/Teacher.kt
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
6 changes: 3 additions & 3 deletions
6
...nil/vent/domain/mappers/CourseStudents.kt → ...lication/domain/mappers/CourseStudents.kt
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
8 changes: 8 additions & 0 deletions
8
vent-backend/src/main/kotlin/com/hernil/vent/application/services/DataRepository.kt
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,8 @@ | ||
package com.hernil.vent.application.services | ||
|
||
import com.hernil.vent.application.domain.Data | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
import org.springframework.stereotype.Repository | ||
|
||
@Repository | ||
interface DataRepository : JpaRepository<Data, Long> |
2 changes: 1 addition & 1 deletion
2
...om/hernil/vent/protus/ActionTypeEntity.kt → ...il/vent/protus/domain/ActionTypeEntity.kt
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.hernil.vent.protus | ||
package com.hernil.vent.protus.domain | ||
|
||
import javax.persistence.* | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...n/com/hernil/vent/protus/CoursesEntity.kt → ...ernil/vent/protus/domain/CoursesEntity.kt
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.hernil.vent.protus | ||
package com.hernil.vent.protus.domain | ||
|
||
import javax.persistence.* | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...rnil/vent/protus/LearnersAnswersEntity.kt → ...nt/protus/domain/LearnersAnswersEntity.kt
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.hernil.vent.protus | ||
package com.hernil.vent.protus.domain | ||
|
||
import javax.persistence.* | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
.../com/hernil/vent/protus/LearnersEntity.kt → ...rnil/vent/protus/domain/LearnersEntity.kt
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
2 changes: 1 addition & 1 deletion
2
...n/com/hernil/vent/protus/LessonsEntity.kt → ...ernil/vent/protus/domain/LessonsEntity.kt
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.hernil.vent.protus | ||
package com.hernil.vent.protus.domain | ||
|
||
import javax.persistence.* | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
.../com/hernil/vent/protus/MessagesEntity.kt → ...rnil/vent/protus/domain/MessagesEntity.kt
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
2 changes: 1 addition & 1 deletion
2
...ernil/vent/protus/OfferedAnswersEntity.kt → ...ent/protus/domain/OfferedAnswersEntity.kt
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.hernil.vent.protus | ||
package com.hernil.vent.protus.domain | ||
|
||
import javax.persistence.* | ||
|
||
|
Oops, something went wrong.