ClickhouseConfig.java
@Configuration
@EntityScan(basePackages = "test.entity.clickhouse")
@EnableJpaRepositories(
        basePackages = "test.repository.clickhouse",
        entityManagerFactoryRef = "clickhouseEntityManagerFactory",
        transactionManagerRef = "clickhouseTransactionManager",
        repositoryBaseClass = BaseRepositoryImpl.class)
//        enableDefaultTransactions = false)
@EnableTransactionManagement
public class ClickhouseConfig {
    @Autowired
    @Qualifier("clickhouseDataSource")
    private DataSource dataSource;

    @Autowired
    @Qualifier("vendorClickhouseProperties")
    private Map<String, Object> vendorProperties;

    @Bean(name = "clickhouseEntityManagerFactory")
    public LocalContainerEntityManagerFactoryBean clickhouseEntityManagerFactory(EntityManagerFactoryBuilder builder) {
        return builder
                .dataSource(dataSource)
                .properties(vendorProperties)
                .packages("com.zcunsoft.tracking.report.entity.clickhouse")
                .persistenceUnit("clickhousePersistenceUnit")
                .build();

    }

    @Bean(name = "clickhouseEntityManager")
    public EntityManager entityManager(EntityManagerFactoryBuilder builder) {
        return clickhouseEntityManagerFactory(builder).getObject().createEntityManager();
    }

    @Bean(name = "clickhouseTransactionManager")
    PlatformTransactionManager transactionManager(EntityManagerFactoryBuilder builder) {
        return new JpaTransactionManager(clickhouseEntityManagerFactory(builder).getObject());
    }


    @Bean(name = "clickHouseJdbcTemplate")
    public NamedParameterJdbcTemplate clickHouseJdbcTemplate(
            @Qualifier("clickhouseDataSource") DataSource dataSource) {
        return new NamedParameterJdbcTemplate(dataSource);
    }
}

  

posted on 2023-03-03 10:23  默西塞德  阅读(341)  评论(0编辑  收藏  举报