com.fivefaces.cloud.config.WarehouseDbConfiguration Maven / Gradle / Ivy
package com.fivefaces.cloud.config;
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.context.annotation.Profile;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import java.util.HashMap;
/**
* This is required so that the beans are found if this project is used as a library
*/
@Configuration
@EnableTransactionManagement
@Profile("WAREHOUSE_AWS_MYSQL")
public class WarehouseDbConfiguration {
@Bean(name = "warehouseDataSource")
@ConfigurationProperties(prefix = "warehouse.datasource")
public DataSource warehouseDataSource() {
return DataSourceBuilder.create().build();
}
@Bean(name = "warehouseEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean warehouseEntityManagerFactory(EntityManagerFactoryBuilder builder,
@Qualifier("warehouseDataSource") DataSource dataSource) {
return builder
.dataSource(dataSource)
.packages("com.fivefaces.cloud.warehouse")
.persistenceUnit("warehousePersistenceUnit")
.build();
}
@Bean(name = "warehouseTransactionManager")
public PlatformTransactionManager warehouseTransactionManager(@Qualifier("warehouseEntityManagerFactory") EntityManagerFactory warehouseEntityManagerFactory) {
return new JpaTransactionManager(warehouseEntityManagerFactory);
}
@Bean
public EntityManagerFactoryBuilder entityManagerFactoryBuilder() {
return new EntityManagerFactoryBuilder(new HibernateJpaVendorAdapter(), new HashMap<>(), null);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy