package it.digione.dg1cloud.config;
|
|
import java.io.Serializable;
|
import java.util.HashMap;
|
import java.util.Map;
|
|
import javax.persistence.EntityManagerFactory;
|
import javax.sql.DataSource;
|
|
import org.eclipse.persistence.config.BatchWriting;
|
import org.eclipse.persistence.config.PersistenceUnitProperties;
|
import org.eclipse.persistence.config.TargetServer;
|
import org.springframework.beans.factory.ObjectProvider;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
import org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration;
|
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
|
import org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.PropertySource;
|
import org.springframework.context.annotation.PropertySources;
|
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
import org.springframework.orm.jpa.JpaTransactionManager;
|
import org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter;
|
import org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter;
|
import org.springframework.transaction.PlatformTransactionManager;
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
import org.springframework.transaction.jta.JtaTransactionManager;
|
|
@ComponentScan
|
@Configuration
|
@PropertySources({
|
@PropertySource(value = "classpath:/it/digione/dg1cloud/config/dg1cloud.properties", ignoreResourceNotFound=false),
|
@PropertySource(value = "file:/etc/digione/dg1cloud/dg1cloud.properties", ignoreResourceNotFound=false)
|
})
|
@EnableAutoConfiguration
|
@EnableConfigurationProperties
|
@EnableJpaRepositories("it.digione.dg1cloud.repository")
|
@EntityScan("it.digione.dg1cloud.model")
|
@EnableTransactionManagement
|
public class AppConfig extends JpaBaseConfiguration implements Serializable{
|
|
protected AppConfig(DataSource dataSource, JpaProperties properties,
|
ObjectProvider<JtaTransactionManager> jtaTransactionManager,
|
ObjectProvider<TransactionManagerCustomizers> transactionManagerCustomizers) {
|
super(dataSource, properties, jtaTransactionManager, transactionManagerCustomizers);
|
}
|
|
/**
|
*
|
*/
|
private static final long serialVersionUID = -662074265587285778L;
|
|
@Value("${application.version}")
|
private String applicationVersion;
|
public String getApplicationVersion() {
|
return applicationVersion;
|
}
|
|
@Value("${repository.base.upload.path}")
|
private String repositoryBaseUploadPath;
|
public String getRepositoryBaseUploadPath() {
|
return repositoryBaseUploadPath;
|
}
|
|
@Value("${repository.base.storage.path}")
|
private String repositoryBaseStoragePath;
|
public String getRepositoryBaseStoragePath() {
|
return repositoryBaseStoragePath;
|
}
|
|
@Value("${external.server.address.base.url}")
|
private String externalBaseUrl;
|
public String getExternalBaseUrl() {
|
return externalBaseUrl;
|
}
|
|
@Bean
|
public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
|
final JpaTransactionManager transactionManager = new JpaTransactionManager();
|
transactionManager.setEntityManagerFactory(emf);
|
return transactionManager;
|
}
|
|
@Override
|
protected AbstractJpaVendorAdapter createJpaVendorAdapter() {
|
return new EclipseLinkJpaVendorAdapter();
|
}
|
|
@Override
|
protected Map<String, Object> getVendorProperties() {
|
final Map<String, Object> map = new HashMap<>();
|
map.put(PersistenceUnitProperties.BATCH_WRITING, BatchWriting.JDBC);
|
map.put(PersistenceUnitProperties.WEAVING, "static");
|
map.put(PersistenceUnitProperties.DEPLOY_ON_STARTUP, "true");
|
map.put(PersistenceUnitProperties.TARGET_SERVER, TargetServer.DEFAULT);
|
return map;
|
}
|
|
}
|