good LaTex math symbol tutorial

http://www.forkosh.com/mimetextutorial.html

Advertisements

How to add multiple database support to Spring application

Define multiple configuration files. In each configuration file, specify the JpaVendorAdapter, datasource, enityManager, entityManagerFactory, and transactionManager. You can set a default configuration file and multiple other configuration files.

A sample goes as below:

Default configuration file:

@Configuration
@EnableTransactionManagement
@EnableAutoConfiguration
@EnableJpaRepositories(
        entityManagerFactoryRef = "entityManagerFactory",
        transactionManagerRef = "transactionManager",
        basePackages = {"bmo.hub.bpm.foundation.appmonitor.db.repo"}
)
public class AppConfig {

    @Autowired
    private JpaVendorAdapter jpaVendorAdapter;

    @Autowired
    private DataSource dataSource;

    @Bean(name = "entityManager")
    public EntityManager entityManager() {
        return entityManagerFactory().createEntityManager();
    }

    @Primary
    @Bean(name = "entityManagerFactory")
    public EntityManagerFactory entityManagerFactory() {
        LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
        emf.setDataSource(dataSource);
        emf.setJpaVendorAdapter(jpaVendorAdapter);
        emf.setPackagesToScan("bmo.hub.bpm.foundation.appmonitor.db.entity");
        emf.setPersistenceUnitName("default");
        emf.afterPropertiesSet();

        return emf.getObject();
    }

    @Bean(name = "transactionManager")
    public PlatformTransactionManager transactionManager() {
        JpaTransactionManager tm = new JpaTransactionManager();
        tm.setEntityManagerFactory(entityManagerFactory());

        return tm;
    }
}

Another configuration file:

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
        entityManagerFactoryRef = "mortgageEntityManagerFactory",
        transactionManagerRef = "mortgageTransactionManager",
        basePackages = {"bmo.hub.bpm.foundation.appmonitor.db.repo.mortgage"}
)
public class MortgageConfig {

    @Autowired
    private JpaVendorAdapter jpaVendorAdapter;

//    @Autowired
//    private DataSource dataSource;
    @Value("${spring.datasource.mortgage.url}")
    private String databaseUrl;

    @Value("${spring.datasource.mortgage.username}")
    private String username;

    @Value("${spring.datasource.mortgage.password}")
    private String password;

    @Value("${spring.datasource.mortgage.driver-class}")
    private String driverClass;

    @Bean(name = "mortgageEntityManager")
    public EntityManager entityManager() {
        return entityManagerFactory().createEntityManager();
    }

    public DataSource dataSource() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource(databaseUrl, username, password);
        dataSource.setDriverClassName(driverClass);
        return dataSource;
    }

    @Primary
    @Bean(name = "mortgageEntityManagerFactory")
    public EntityManagerFactory entityManagerFactory() {
        LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
        emf.setDataSource(dataSource());
        emf.setJpaVendorAdapter(jpaVendorAdapter);
        emf.setPackagesToScan("bmo.hub.bpm.foundation.appmonitor.db.entity.mortgage");
        emf.afterPropertiesSet();

        return emf.getObject();
    }

    @Bean(name = "mortgageTransactionManager")
    public PlatformTransactionManager transactionManager() {
        JpaTransactionManager tm = new JpaTransactionManager();
        tm.setEntityManagerFactory(entityManagerFactory());

        return tm;
    }
}

And the properties file (application.yml):

selenium:
  grid:
    url: http://localhost:4444/wd/hub

scheduling:
  job:
    cron: 0 0/3 * * * *

spring:
  datasource:
    url: jdbc:oracle:thin:@10.193.61.167:1521:garnish
    username: row_dev
    password: Welcome#1
    driver-class: oracle.jdbc.driver.OracleDriver

    mortgage:
      url: jdbc:oracle:thin:@10.193.46.193:1521:mortgage
      username: mortgage
      password: MORTGAGE
      driver-class: oracle.jdbc.driver.OracleDriver

    hikari:
      connection-timeout: 60000
      maximum-pool-size: 5