// Path: java.spring.jpa.multi/myapp/src/main/my/java/spring/jpa/multi/models/Organization.java
// @Entity
// @Table(name = "Organization", schema = "mytest")
// public class Organization {
// 
//     @Id
//     @GeneratedValue(strategy = GenerationType.IDENTITY)
//     private Integer id;
// 
//     @Column(unique = true, nullable = false)
//     private String name;
// 
//     public Integer getId() {
//         return id;
//     }
// 
//     public void setId(Integer id) {
//         this.id = id;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// }
// 
// Path: java.spring.jpa.multi/myapp/src/main/my/java/spring/jpa/multi/repositories/interfaces/OrganizationRepository.java
// public interface OrganizationRepository extends JpaRepository<Organization, Integer> {
// }
// 
// Path: java.spring.jpa.multi/myapp/src/main/my/java/spring/jpa/multi/repositories/source2/Source2OrganizationRepositoryImpl.java
// public class Source2OrganizationRepositoryImpl {
// }


import my.java.spring.jpa.multi.models.Organization;
import my.java.spring.jpa.multi.repositories.interfaces.OrganizationRepository;
import my.java.spring.jpa.multi.repositories.source2.Source2OrganizationRepositoryImpl;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
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.JpaVendorAdapter;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaDialect;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;

    @Bean(TransactionManagerBeanName)
    public PlatformTransactionManager transactionManager(
            @Qualifier(EntityManagerFactoryBeanName) EntityManagerFactory entityManagerFactory) {
        return new JpaTransactionManager(entityManagerFactory);
    }

    @Bean(EntityManagerFactoryBeanName)
    public LocalContainerEntityManagerFactoryBean entityManagerFactory(
            @Qualifier(DataSourceBeanName) DataSource dataSource,
            @Qualifier(JpaVendorAdapterBeanName) JpaVendorAdapter vendorAdapter) {

        LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
        entityManagerFactoryBean.setDataSource(dataSource);
        entityManagerFactoryBean.setJpaVendorAdapter(vendorAdapter);
        entityManagerFactoryBean.setJpaDialect(new HibernateJpaDialect());
        entityManagerFactoryBean.setPackagesToScan(Organization.class.getPackage().getName());
        entityManagerFactoryBean.setPersistenceUnitName("mysqlsource2");
        entityManagerFactoryBean.afterPropertiesSet();

        return entityManagerFactoryBean;
    }

    @Bean(JpaVendorAdapterBeanName)
    @ConfigurationProperties(prefix = "source2.mysql.jpa")
    public JpaVendorAdapter jpaVendorAdapter() {
        return new HibernateJpaVendorAdapter();
    }

    @Bean(DataSourceBeanName)
// Path: java.spring.jpa.multi/myapp/src/main/my/java/spring/jpa/multi/models/Organization.java
// @Entity
// @Table(name = "Organization", schema = "mytest")
// public class Organization {
// 
//     @Id
//     @GeneratedValue(strategy = GenerationType.IDENTITY)
//     private Integer id;
// 
//     @Column(unique = true, nullable = false)
//     private String name;
// 
//     public Integer getId() {
//         return id;
//     }
// 
//     public void setId(Integer id) {
//         this.id = id;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// }
// 
// Path: java.spring.jpa.multi/myapp/src/main/my/java/spring/jpa/multi/repositories/interfaces/OrganizationRepository.java
// public interface OrganizationRepository extends JpaRepository<Organization, Integer> {
// }
// 
// Path: java.spring.jpa.multi/myapp/src/main/my/java/spring/jpa/multi/repositories/source2/Source2OrganizationRepositoryImpl.java
// public class Source2OrganizationRepositoryImpl {
// }


// Path: java.spring.jpa.multi/myapp/src/main/my/java/spring/jpa/multi/repositories/config/MySqlSource2Config.java
import my.java.spring.jpa.multi.models.Organization;
import my.java.spring.jpa.multi.repositories.interfaces.OrganizationRepository;
import my.java.spring.jpa.multi.repositories.source2.Source2OrganizationRepositoryImpl;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
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.JpaVendorAdapter;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaDialect;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;


    @Bean(TransactionManagerBeanName)
    public PlatformTransactionManager transactionManager(
            @Qualifier(EntityManagerFactoryBeanName) EntityManagerFactory entityManagerFactory) {
        return new JpaTransactionManager(entityManagerFactory);
    }

    @Bean(EntityManagerFactoryBeanName)
    public LocalContainerEntityManagerFactoryBean entityManagerFactory(
            @Qualifier(DataSourceBeanName) DataSource dataSource,
            @Qualifier(JpaVendorAdapterBeanName) JpaVendorAdapter vendorAdapter) {

        LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
        entityManagerFactoryBean.setDataSource(dataSource);
        entityManagerFactoryBean.setJpaVendorAdapter(vendorAdapter);
        entityManagerFactoryBean.setJpaDialect(new HibernateJpaDialect());
        entityManagerFactoryBean.setPackagesToScan(Organization.class.getPackage().getName());
        entityManagerFactoryBean.setPersistenceUnitName("mysqlsource2");
        entityManagerFactoryBean.afterPropertiesSet();

        return entityManagerFactoryBean;
    }

    @Bean(JpaVendorAdapterBeanName)
    @ConfigurationProperties(prefix = "source2.mysql.jpa")
    public JpaVendorAdapter jpaVendorAdapter() {
        return new HibernateJpaVendorAdapter();
    }

    @Bean(DataSourceBeanName)
    @ConfigurationProperties(prefix = "source2.mysql.datasource")