Commit ed5a90d8 by Boros Andras

init

parent f3d896fe
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>hu.lanoga.dojo</groupId>
<artifactId>UsersDojoJava</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>UsersDojoJava</name>
<description>Lanoga coding Dojo Java GYM</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<com.zaxxer.hikaricp.version>2.6.1</com.zaxxer.hikaricp.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--HikarCP JDBC connection pool-->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>${com.zaxxer.hikaricp.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.2.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package hu.lanoga.dojo;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(UsersDojoJavaApplication.class);
}
}
package hu.lanoga.dojo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class UsersDojoJavaApplication {
public static void main(String[] args) {
SpringApplication.run(UsersDojoJavaApplication.class, args);
}
}
package hu.lanoga.dojo.api.user;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.*;
/**
* Created by borosandras on 2017. 03. 22..
*/
@Getter
@Setter
@Entity
@Table(name = "dojo_user")
public class DojoUser {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String firstName;
private String lastName;
public DojoUser(Integer id, String firstName, String lastName) {
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
}
public DojoUser() {
}
}
package hu.lanoga.dojo.api.user;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* Created by borosandras on 2017. 03. 28..
*/
@RestController
@RequestMapping(value = "user")
public class DojoUserController {
@Autowired
private DojoUserService dojoUserService;
@RequestMapping(value = "dummy", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public List<DojoUser> dummyGetCall() {
return dojoUserService.getAllUser();
}
}
package hu.lanoga.dojo.api.user;
import hu.lanoga.dojo.util.LngJpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.io.Serializable;
import java.util.List;
/**
* Created by borosandras on 2017. 03. 23..
*/
@Repository
public interface DojoUserRepository extends LngJpaRepository<DojoUser, Serializable> {
@Query(value = "select d from DojoUser d")
List<DojoUser> findAllUser();
}
package hu.lanoga.dojo.api.user;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* Created by borosandras on 2017. 03. 23..
*/
@Service
public class DojoUserService {
@Autowired
private DojoUserRepository dojoUserRepository;
public List<DojoUser> getAllUser() {
return dojoUserRepository.findAllUser();
}
}
package hu.lanoga.dojo.config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.io.ClassPathResource;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableAsync
@EnableScheduling
@EnableSwagger2
public class ApplicationConfig {
private static final Logger logger = LoggerFactory.getLogger(ApplicationConfig.class);
public ApplicationConfig() {
logger.info("Setting up application configuration...");
}
@Bean
public PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() {
String activeProfile = System.getProperty("spring.profiles.active", "dev");
String appConfigPropertiesFile = String.format("profiles/%s/app-config.properties", activeProfile);
String databaseConfigFile = String.format("profiles/%s/database.properties", activeProfile);
PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
configurer.setLocations(
new ClassPathResource(appConfigPropertiesFile),
new ClassPathResource(databaseConfigFile)
);
return configurer;
}
}
\ No newline at end of file
package hu.lanoga.dojo.config;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import hu.lanoga.dojo.UsersDojoJavaApplication;
import hu.lanoga.dojo.util.LngRepositoryFactoryBean;
import org.hibernate.cfg.Environment;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.orm.hibernate4.HibernateExceptionTranslator;
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 org.springframework.transaction.annotation.TransactionManagementConfigurer;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import java.util.Properties;
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(basePackageClasses = UsersDojoJavaApplication.class, repositoryFactoryBeanClass = LngRepositoryFactoryBean.class, entityManagerFactoryRef = "configureEntityManagerFactory")
//@EnableJpaAuditing(auditorAwareRef = "springSecurityAuditorAware")
public class DatasourceConfiguration implements TransactionManagementConfigurer {
@Value("${datasource.url}")
private String datasourceUrl;
@Value("${datasource.username}")
private String username;
@Value("${datasource.password}")
private String password;
@Value("${datasource.driverClassName}")
private String driverClassName;
@Value("${hibernate.dialect}")
private String hibernateDialect;
@Value("${hibernate.sql.show}")
private String sqlShow;
@Value("${hibernate.hbm2ddl.auto}")
private String hbm2ddlAuto;
@Bean
public JdbcTemplate jdbcTemplate(DataSource dataSource) {
return new JdbcTemplate(dataSource);
}
@Bean
public DataSource dataSource() {
HikariConfig config = new HikariConfig();
config.setDriverClassName(driverClassName);
config.setJdbcUrl(datasourceUrl);
config.setUsername(username);
config.setPassword(password);
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
config.addDataSourceProperty("useServerPrepStmts", "true");
return new HikariDataSource(config);
}
@Bean
public LocalContainerEntityManagerFactoryBean configureEntityManagerFactory() {
LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
emf.setDataSource(this.dataSource());
emf.setPackagesToScan("hu.lanoga.dojo");
emf.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
Properties jpaProperties = new Properties();
jpaProperties.put(org.hibernate.cfg.Environment.DIALECT, hibernateDialect);
jpaProperties.put(org.hibernate.cfg.Environment.HBM2DDL_AUTO, hbm2ddlAuto);
jpaProperties.put(Environment.SHOW_SQL, sqlShow);
jpaProperties.put(Environment.ENABLE_LAZY_LOAD_NO_TRANS, true);
emf.setJpaProperties(jpaProperties);
emf.afterPropertiesSet();
return emf;
}
@Bean
public HibernateExceptionTranslator hibernateExceptionTranslator() {
return new HibernateExceptionTranslator();
}
@Override
@Bean(name = "transactionManager")
public PlatformTransactionManager annotationDrivenTransactionManager() {
EntityManagerFactory factory = configureEntityManagerFactory().getObject();
return new JpaTransactionManager(factory);
}
}
\ No newline at end of file
package hu.lanoga.dojo.util;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.NoRepositoryBean;
import java.io.Serializable;
@NoRepositoryBean
public interface LngJpaRepository<T, ID extends Serializable> extends JpaRepository<T, ID> {
}
package hu.lanoga.dojo.util;
import org.springframework.data.jpa.repository.support.SimpleJpaRepository;
import javax.persistence.EntityManager;
import java.io.Serializable;
public class LngJpaRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRepository<T, ID> implements LngJpaRepository<T, ID> {
protected Class<T> domainClass;
private EntityManager entityManager;
public LngJpaRepositoryImpl(Class<T> domainClass, EntityManager em) {
super(domainClass, em);
this.domainClass = domainClass;
this.entityManager = em;
}
}
package hu.lanoga.dojo.util;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.support.JpaRepositoryFactory;
import org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean;
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
import javax.persistence.EntityManager;
import java.io.Serializable;
public class LngRepositoryFactoryBean<R extends JpaRepository<T, I>, T, I extends Serializable> extends JpaRepositoryFactoryBean<R, T, I> {
public LngRepositoryFactoryBean(Class<? extends R> repositoryInterface) {
super(repositoryInterface);
}
@SuppressWarnings("rawtypes")
@Override
protected RepositoryFactorySupport createRepositoryFactory(EntityManager entityManager) {
return new MyRepositoryFactory(entityManager);
}
private static class MyRepositoryFactory<T, I extends Serializable> extends JpaRepositoryFactory {
private EntityManager entityManager;
public MyRepositoryFactory(EntityManager entityManager) {
super(entityManager);
this.entityManager = entityManager;
}
}
}
liquibase.enabled=false
\ No newline at end of file
datasource.url=jdbc:postgresql://192.168.50.53:5432/UsersDojoJava
datasource.username=dojo-user
datasource.password=dojo-user
datasource.driverClassName=org.postgresql.Driver
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
hibernate.sql.show=false
hibernate.hbm2ddl.auto=create
\ No newline at end of file
package hu.lanoga.dojo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class UsersDojoJavaApplicationTests {
@Test
public void contextLoads() {
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment