-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change to a simple configuration with only one data source management.
- Loading branch information
Showing
15 changed files
with
55 additions
and
401 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,23 @@ | ||
package sample; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.orm.jpa.JpaTransactionManager; | ||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; | ||
|
||
import jakarta.persistence.EntityManagerFactory; | ||
import sample.context.DomainHelper; | ||
import sample.context.orm.OrmInterceptor; | ||
import sample.context.orm.OrmRepository; | ||
import sample.context.orm.repository.DefaultRepository; | ||
import sample.context.orm.repository.SystemRepository; | ||
|
||
/** | ||
* Represents a database connection definition for an application. | ||
*/ | ||
@Configuration | ||
public class ApplicationDbConfig { | ||
|
||
/** Represents a connection definition to a standard schema. */ | ||
@Configuration | ||
static class DefaultDbConfig { | ||
|
||
@Bean | ||
@Primary | ||
OrmRepository defaultRepository(DomainHelper dh, OrmInterceptor interceptor) { | ||
return DefaultRepository.of(dh, interceptor); | ||
} | ||
|
||
@Bean(name = DefaultRepository.BeanNameDs, destroyMethod = "close") | ||
@Primary | ||
DataSource dataSource(ApplicationProperties props) { | ||
return props.getDatasource().getApp().dataSource(); | ||
} | ||
|
||
@Bean(name = DefaultRepository.BeanNameEmf) | ||
@Primary | ||
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean( | ||
ApplicationProperties props, | ||
@Qualifier(DefaultRepository.BeanNameDs) final DataSource dataSource) { | ||
return props.getDatasource().getApp().entityManagerFactoryBean(dataSource); | ||
} | ||
|
||
@Bean(name = DefaultRepository.BeanNameTx) | ||
@Primary | ||
JpaTransactionManager transactionManager( | ||
ApplicationProperties props, | ||
@Qualifier(DefaultRepository.BeanNameEmf) final EntityManagerFactory emf) { | ||
return props.getDatasource().getApp().transactionManager(emf); | ||
} | ||
|
||
} | ||
|
||
/** Represents a connection definition to the system schema. */ | ||
@Configuration | ||
static class SystemDbConfig { | ||
|
||
@Bean | ||
SystemRepository systemRepository(DomainHelper dh, OrmInterceptor interceptor) { | ||
return SystemRepository.of(dh, interceptor); | ||
} | ||
|
||
@Bean(name = SystemRepository.BeanNameDs, destroyMethod = "close") | ||
DataSource systemDataSource(ApplicationProperties props) { | ||
return props.getDatasource().getSystem().dataSource(); | ||
} | ||
|
||
@Bean(name = SystemRepository.BeanNameEmf) | ||
LocalContainerEntityManagerFactoryBean systemEntityManagerFactoryBean( | ||
ApplicationProperties props, | ||
@Qualifier(SystemRepository.BeanNameDs) final DataSource dataSource) { | ||
return props.getDatasource().getSystem().entityManagerFactoryBean(dataSource); | ||
} | ||
|
||
@Bean(name = SystemRepository.BeanNameTx) | ||
JpaTransactionManager systemTransactionManager( | ||
ApplicationProperties props, | ||
@Qualifier(SystemRepository.BeanNameEmf) final EntityManagerFactory emf) { | ||
return props.getDatasource().getSystem().transactionManager(emf); | ||
} | ||
|
||
@Bean | ||
@Primary | ||
OrmRepository defaultRepository(DomainHelper dh, OrmInterceptor interceptor) { | ||
return OrmRepository.of(dh, interceptor); | ||
} | ||
|
||
} |
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
81 changes: 0 additions & 81 deletions
81
src/main/java/sample/context/orm/OrmDataSourceProperties.java
This file was deleted.
Oops, something went wrong.
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
69 changes: 0 additions & 69 deletions
69
src/main/java/sample/context/orm/OrmRepositoryProperties.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.