Skip to content

Commit d4b393e

Browse files
committed
Infrastructure Made Ready
* Project lombok * log4j2 * slf4j * spring-boot * spring-data * spring-mvc * hibernate * mapstruct * postgresql
0 parents  commit d4b393e

18 files changed

Lines changed: 915 additions & 0 deletions

.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Eclipse Workspace
2+
**/.recommenders/**
3+
**/.sonarlint/**
4+
**/.metadata/**
5+
**/Servers/**
6+
7+
# Eclipse Project
8+
**.classpath
9+
**.project
10+
**.settings/
11+
12+
# Intellij
13+
**.idea/
14+
**.iml
15+
**.iws
16+
17+
# Netbeans
18+
nbactions.xml
19+
nb-configuration.xml
20+
21+
# Mac
22+
**.DS_Store
23+
24+
# Allure
25+
**allure-results**
26+
27+
# Test
28+
**test-output**
29+
30+
# TYBS
31+
**local.properties**
32+
**.springBeans
33+
**/target/**
34+
dev/release.properties
35+
dev/infra/infra-vek/src/main/resources/tybs.infra.vek.properties

jpa-specification/pom.xml

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.fd</groupId>
8+
<artifactId>jpa-specification</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<properties>
12+
<java-version>1.8</java-version>
13+
<maven.compiler.source>1.8</maven.compiler.source>
14+
<maven.compiler.target>1.8</maven.compiler.target>
15+
16+
<lombok-version>1.18.2</lombok-version>
17+
<spring.boot.version>2.0.4.RELEASE</spring.boot.version>
18+
<hamcrest-version>1.3</hamcrest-version>
19+
<mapstruct.version>1.2.0.Final</mapstruct.version>
20+
21+
<maven.plugin.compiler.version>3.6.1</maven.plugin.compiler.version>
22+
<maven.plugin.build-helper.version>3.0.0</maven.plugin.build-helper.version>
23+
24+
</properties>
25+
26+
<dependencyManagement>
27+
<dependencies>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-dependencies</artifactId>
31+
<version>${spring.boot.version}</version>
32+
<type>pom</type>
33+
<scope>import</scope>
34+
</dependency>
35+
</dependencies>
36+
</dependencyManagement>
37+
38+
<dependencies>
39+
<dependency>
40+
<groupId>org.projectlombok</groupId>
41+
<artifactId>lombok</artifactId>
42+
<version>${lombok-version}</version>
43+
</dependency>
44+
45+
<dependency>
46+
<groupId>org.springframework.boot</groupId>
47+
<artifactId>spring-boot-starter-web</artifactId>
48+
<exclusions>
49+
<exclusion>
50+
<groupId>ch.qos.logback</groupId>
51+
<artifactId>logback-classic</artifactId>
52+
</exclusion>
53+
54+
<exclusion>
55+
<groupId>org.apache.logging.log4j</groupId>
56+
<artifactId>log4j-to-slf4j</artifactId>
57+
</exclusion>
58+
</exclusions>
59+
</dependency>
60+
61+
<dependency>
62+
<groupId>org.springframework.boot</groupId>
63+
<artifactId>spring-boot-starter-data-jpa</artifactId>
64+
<exclusions>
65+
<exclusion>
66+
<groupId>ch.qos.logback</groupId>
67+
<artifactId>logback-classic</artifactId>
68+
</exclusion>
69+
70+
<exclusion>
71+
<groupId>org.apache.logging.log4j</groupId>
72+
<artifactId>log4j-to-slf4j</artifactId>
73+
</exclusion>
74+
</exclusions>
75+
</dependency>
76+
77+
<dependency>
78+
<groupId>org.apache.logging.log4j</groupId>
79+
<artifactId>log4j-core</artifactId>
80+
</dependency>
81+
82+
<dependency>
83+
<groupId>org.apache.logging.log4j</groupId>
84+
<artifactId>log4j-slf4j-impl</artifactId>
85+
</dependency>
86+
87+
<dependency>
88+
<groupId>org.hibernate</groupId>
89+
<artifactId>hibernate-c3p0</artifactId>
90+
</dependency>
91+
92+
<dependency>
93+
<groupId>org.hamcrest</groupId>
94+
<artifactId>hamcrest-all</artifactId>
95+
<version>${hamcrest-version}</version>
96+
</dependency>
97+
98+
<dependency>
99+
<groupId>org.postgresql</groupId>
100+
<artifactId>postgresql</artifactId>
101+
</dependency>
102+
103+
<dependency>
104+
<groupId>org.mapstruct</groupId>
105+
<artifactId>mapstruct-jdk8</artifactId>
106+
<version>${mapstruct.version}</version>
107+
</dependency>
108+
109+
</dependencies>
110+
111+
<build>
112+
<plugins>
113+
114+
<!-- MAVEN COMPILER PLUGIN -->
115+
<plugin>
116+
<groupId>org.apache.maven.plugins</groupId>
117+
<artifactId>maven-compiler-plugin</artifactId>
118+
<version>${maven.plugin.compiler.version}</version>
119+
<configuration>
120+
<source>${java-version}</source>
121+
<target>${java-version}</target>
122+
<annotationProcessorPaths>
123+
<path>
124+
<groupId>org.mapstruct</groupId>
125+
<artifactId>mapstruct-processor</artifactId>
126+
<version>${mapstruct.version}</version>
127+
</path>
128+
<path>
129+
<groupId>org.projectlombok</groupId>
130+
<artifactId>lombok</artifactId>
131+
<version>${lombok-version}</version>
132+
</path>
133+
</annotationProcessorPaths>
134+
</configuration>
135+
</plugin>
136+
137+
<!-- MAVEN ADD GENERATED-SOURCES TO CLASSPATH -->
138+
<plugin>
139+
<groupId>org.codehaus.mojo</groupId>
140+
<artifactId>build-helper-maven-plugin</artifactId>
141+
<version>${maven.plugin.build-helper.version}</version>
142+
<executions>
143+
<execution>
144+
<phase>generate-sources</phase>
145+
<goals>
146+
<goal>add-source</goal>
147+
</goals>
148+
<configuration>
149+
<sources>
150+
<source>target/generated-sources/annotations</source>
151+
</sources>
152+
</configuration>
153+
</execution>
154+
</executions>
155+
</plugin>
156+
</plugins>
157+
</build>
158+
159+
</project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Telif hakkı 2017 Türkiye Bilimsel ve Teknolojik Araştırma Kurumu.
3+
* Tüm haklar saklıdır.
4+
*
5+
* BU TELİF HAKKI DOSYA ÜST BİLGİSİNİ DEĞİŞTİRMEYİNİZ VEYA SİLMEYİNİZ.
6+
*
7+
* Bu kaynak kod sadece TÜBİTAK için TYBS Projesi kapsamında geliştirilmiştir;
8+
* değişiklik yapma, başka amaçlarda kullanılmak üzere kısmen veya tamamını
9+
* kopyalama ve/veya dağıtım yapma hakkınız bulunmamaktadır.
10+
*
11+
* Daha fazla bilgi ve sorularınız için TÜBİTAK ile iletişime geçiniz.
12+
*/
13+
package com.fd.jpa;
14+
15+
import org.springframework.boot.SpringApplication;
16+
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
17+
import org.springframework.boot.autoconfigure.SpringBootApplication;
18+
import org.springframework.context.annotation.ComponentScan;
19+
import org.springframework.core.Ordered;
20+
21+
/**
22+
* @author furkan.danismaz
23+
* 10/09/2018 11:12
24+
*/
25+
@SpringBootApplication
26+
@ComponentScan("com.fd")
27+
@AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE)
28+
public class App {
29+
30+
public static void main(String[] args) {
31+
SpringApplication.run(App.class, args);
32+
}
33+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Telif hakkı 2017 Türkiye Bilimsel ve Teknolojik Araştırma Kurumu.
3+
* Tüm haklar saklıdır.
4+
*
5+
* BU TELİF HAKKI DOSYA ÜST BİLGİSİNİ DEĞİŞTİRMEYİNİZ VEYA SİLMEYİNİZ.
6+
*
7+
* Bu kaynak kod sadece TÜBİTAK için TYBS Projesi kapsamında geliştirilmiştir;
8+
* değişiklik yapma, başka amaçlarda kullanılmak üzere kısmen veya tamamını
9+
* kopyalama ve/veya dağıtım yapma hakkınız bulunmamaktadır.
10+
*
11+
* Daha fazla bilgi ve sorularınız için TÜBİTAK ile iletişime geçiniz.
12+
*/
13+
package com.fd.jpa.audit;
14+
15+
import org.springframework.data.domain.AuditorAware;
16+
17+
import java.util.Optional;
18+
19+
/**
20+
* @author furkan.danismaz
21+
* 10/09/2018 13:10
22+
*/
23+
public class SpringSecurityAuditorAware implements AuditorAware<String> {
24+
25+
@Override
26+
public Optional<String> getCurrentAuditor() {
27+
return Optional.of("fdanismaz");
28+
}
29+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* Telif hakkı 2017 Türkiye Bilimsel ve Teknolojik Araştırma Kurumu.
3+
* Tüm haklar saklıdır.
4+
*
5+
* BU TELİF HAKKI DOSYA ÜST BİLGİSİNİ DEĞİŞTİRMEYİNİZ VEYA SİLMEYİNİZ.
6+
*
7+
* Bu kaynak kod sadece TÜBİTAK için TYBS Projesi kapsamında geliştirilmiştir;
8+
* değişiklik yapma, başka amaçlarda kullanılmak üzere kısmen veya tamamını
9+
* kopyalama ve/veya dağıtım yapma hakkınız bulunmamaktadır.
10+
*
11+
* Daha fazla bilgi ve sorularınız için TÜBİTAK ile iletişime geçiniz.
12+
*/
13+
package com.fd.jpa.config;
14+
15+
import com.fd.jpa.audit.SpringSecurityAuditorAware;
16+
import com.mchange.v2.c3p0.ComboPooledDataSource;
17+
import org.hibernate.jpa.HibernatePersistenceProvider;
18+
import org.springframework.beans.factory.annotation.Autowired;
19+
import org.springframework.context.annotation.Bean;
20+
import org.springframework.context.annotation.Configuration;
21+
import org.springframework.context.annotation.PropertySource;
22+
import org.springframework.core.env.Environment;
23+
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
24+
import org.springframework.data.domain.AuditorAware;
25+
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
26+
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
27+
import org.springframework.orm.jpa.JpaTransactionManager;
28+
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
29+
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
30+
import org.springframework.transaction.annotation.EnableTransactionManagement;
31+
32+
import java.beans.PropertyVetoException;
33+
import java.util.Properties;
34+
35+
/**
36+
* @author furkan.danismaz
37+
* 10/09/2018 12:05
38+
*/
39+
@Configuration
40+
@PropertySource("database.properties")
41+
@EnableTransactionManagement
42+
@EnableJpaRepositories(basePackages = "${hibernate.repositories_scan}")
43+
@EnableJpaAuditing(auditorAwareRef = "auditorAware")
44+
public class DatabaseConfiguration {
45+
46+
@Autowired
47+
private Environment environment;
48+
49+
@Bean
50+
public ComboPooledDataSource dataSource() throws PropertyVetoException {
51+
ComboPooledDataSource dataSource = new ComboPooledDataSource();
52+
dataSource.setDriverClass(this.environment.getProperty("hibernate.driver"));
53+
dataSource.setJdbcUrl(this.environment.getProperty("hibernate.db_url"));
54+
dataSource.setUser(this.environment.getProperty("hibernate.db_user"));
55+
dataSource.setPassword(this.environment.getProperty("hibernate.db_password"));
56+
57+
// C3P0 Connection Pool Settings
58+
dataSource.setAcquireIncrement(Integer.parseInt(this.environment.getProperty("hibernate.c3p0.acquire_increment")));
59+
dataSource.setInitialPoolSize(Integer.parseInt(this.environment.getProperty("hibernate.c3p0.initialPoolSize")));
60+
dataSource.setMinPoolSize(Integer.parseInt(this.environment.getProperty("hibernate.c3p0.minPoolSize")));
61+
dataSource.setMaxPoolSize(Integer.parseInt(this.environment.getProperty("hibernate.c3p0.maxPoolSize")));
62+
dataSource.setMaxIdleTime(Integer.parseInt(this.environment.getProperty("hibernate.c3p0.maxIdleTime")));
63+
dataSource.setIdleConnectionTestPeriod(Integer.parseInt(this.environment.getProperty("hibernate.c3p0.idleConnectionTestPeriod")));
64+
dataSource.setMaxStatements(Integer.parseInt(this.environment.getProperty("hibernate.c3p0.maxStatements")));
65+
66+
return dataSource;
67+
}
68+
69+
@Bean
70+
public LocalContainerEntityManagerFactoryBean entityManagerFactory() throws PropertyVetoException {
71+
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
72+
vendorAdapter.setGenerateDdl(true);
73+
74+
LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
75+
factory.setJpaVendorAdapter(vendorAdapter);
76+
factory.setPackagesToScan(this.environment.getProperty("hibernate.entities_scan"));
77+
factory.setDataSource(this.dataSource());
78+
factory.setPersistenceProviderClass(HibernatePersistenceProvider.class);
79+
factory.setJpaProperties(this.hibernateProperties());
80+
81+
return factory;
82+
}
83+
84+
@Bean
85+
public PersistenceExceptionTranslationPostProcessor exceptionTranslation(){
86+
return new PersistenceExceptionTranslationPostProcessor();
87+
}
88+
89+
@Bean
90+
public JpaTransactionManager transactionManager() throws PropertyVetoException {
91+
JpaTransactionManager transactionManager = new JpaTransactionManager();
92+
transactionManager.setEntityManagerFactory(this.entityManagerFactory().getObject());
93+
return transactionManager;
94+
}
95+
96+
@Bean
97+
public AuditorAware<String> auditorAware() {
98+
return new SpringSecurityAuditorAware();
99+
}
100+
101+
private Properties hibernateProperties() {
102+
Properties properties = new Properties();
103+
properties.put("hibernate.dialect", this.environment.getProperty("hibernate.dialect"));
104+
properties.put("hibernate.show_sql", this.environment.getProperty("hibernate.show_sql"));
105+
properties.put("hibernate.format_sql", this.environment.getProperty("hibernate.format_sql"));
106+
properties.put("hibernate.hbm2ddl.auto", this.environment.getProperty("hibernate.hbm2ddl_auto"));
107+
properties.put("org.hibernate.envers.audit_table_suffix", this.environment.getProperty("hibernate.audit_table_suffix"));
108+
properties.put("org.hibernate.envers.audit_strategy", this.environment.getProperty("hibernate.audit_strategy"));
109+
return properties;
110+
}
111+
}

0 commit comments

Comments
 (0)