package ca.uhn.fhirtest.config; import java.util.Properties; import javax.persistence.EntityManagerFactory; import javax.sql.DataSource; import org.apache.commons.dbcp2.BasicDataSource; import org.hibernate.dialect.DerbyTenSevenDialect; import org.hibernate.dialect.PostgreSQL94Dialect; import org.hibernate.jpa.HibernatePersistenceProvider; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.orm.jpa.JpaTransactionManager; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.transaction.annotation.EnableTransactionManagement; import ca.uhn.fhir.jpa.config.BaseJavaConfigDstu1; import ca.uhn.fhir.jpa.dao.DaoConfig; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor; import ca.uhn.fhirtest.interceptor.PublicSecurityInterceptor; @Configuration @Import(CommonConfig.class) @EnableTransactionManagement() public class TestDstu1Config extends BaseJavaConfigDstu1 { public static final String FHIR_DB_USERNAME = "${fhir.db.username}"; public static final String FHIR_DB_PASSWORD = "${fhir.db.password}"; @Value(FHIR_DB_USERNAME) private String myDbUsername; @Value(FHIR_DB_PASSWORD) private String myDbPassword; public static final String FHIR_LUCENE_LOCATION_DSTU = "${fhir.lucene.location.dstu}"; @Value(FHIR_LUCENE_LOCATION_DSTU) private String myFhirLuceneLocation; /** * This lets the "@Value" fields reference properties from the properties file */ @Bean public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { return new PropertySourcesPlaceholderConfigurer(); } @Bean() public DaoConfig daoConfig() { DaoConfig retVal = new DaoConfig(); retVal.setSubscriptionEnabled(false); retVal.setAllowMultipleDelete(false); retVal.setAllowExternalReferences(true); retVal.getTreatBaseUrlsAsLocal().add("http://fhirtest.uhn.ca/baseDstu1"); retVal.getTreatBaseUrlsAsLocal().add("https://fhirtest.uhn.ca/baseDstu1"); return retVal; } @Bean(name = "myPersistenceDataSourceDstu1", destroyMethod = "close") public DataSource dataSource() { BasicDataSource retVal = new BasicDataSource(); retVal.setDriver(new org.postgresql.Driver()); retVal.setUrl("jdbc:postgresql://localhost/fhirtest_dstu"); retVal.setUsername(myDbUsername); retVal.setPassword(myDbPassword); return retVal; } @Bean() public JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) { JpaTransactionManager retVal = new JpaTransactionManager(); retVal.setEntityManagerFactory(entityManagerFactory); return retVal; } @Bean() public LocalContainerEntityManagerFactoryBean entityManagerFactory() { LocalContainerEntityManagerFactoryBean retVal = new LocalContainerEntityManagerFactoryBean(); retVal.setPersistenceUnitName("PU_HapiFhirJpaDstu1"); retVal.setDataSource(dataSource()); retVal.setPackagesToScan("ca.uhn.fhir.jpa.entity"); retVal.setPersistenceProvider(new HibernatePersistenceProvider()); retVal.setJpaProperties(jpaProperties()); return retVal; } private Properties jpaProperties() { Properties extraProperties = new Properties(); extraProperties.put("hibernate.dialect", PostgreSQL94Dialect.class.getName()); extraProperties.put("hibernate.format_sql", "true"); extraProperties.put("hibernate.show_sql", "false"); extraProperties.put("hibernate.hbm2ddl.auto", "update"); extraProperties.put("hibernate.jdbc.batch_size", "20"); extraProperties.put("hibernate.cache.use_query_cache", "false"); extraProperties.put("hibernate.cache.use_second_level_cache", "false"); extraProperties.put("hibernate.cache.use_structured_entries", "false"); extraProperties.put("hibernate.cache.use_minimal_puts", "false"); extraProperties.put("hibernate.search.default.directory_provider", "filesystem"); extraProperties.put("hibernate.search.default.indexBase", myFhirLuceneLocation); extraProperties.put("hibernate.search.lucene_version", "LUCENE_CURRENT"); return extraProperties; } }