Leonardo Vannucci
2018-08-01 5554f5ebced8adb7b7982481120d0ca00767c7f9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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/application.properties", ignoreResourceNotFound=true)
       })
@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;
   }    
   
}