Permalink
Browse files

Criando cenarios de testes de pool de conexoes com banco de dados rel…

…acional
  • Loading branch information...
emmanuelneri committed Mar 15, 2018
1 parent 16dc6bb commit c8e3bce76e3dc6e0f0d9ed42aaa191baaa86337a
@@ -118,6 +118,12 @@
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.7.8</version>
</dependency>
</dependencies>
<build>
@@ -0,0 +1,19 @@
package br.com.emmanuelneri;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.sql.DataSource;
@Configuration
public class DefaultDataSourceConfiguration {
@Bean
@ConfigurationProperties("spring.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
}
@@ -0,0 +1,38 @@
package br.com.emmanuelneri;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.sql.DataSource;
@Configuration
public class HikariConfiguration {
@Value("${spring.datasource.url}")
private String url;
@Value("${spring.datasource.driver-class-name}")
private String driver;
@Value("${spring.datasource.username}")
private String username;
@Value("${spring.datasource.password}")
private String password;
@Bean
public DataSource dataSource() {
final HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setJdbcUrl(url);
hikariConfig.setDriverClassName(driver);
hikariConfig.setUsername(username);
hikariConfig.setPassword(password);
hikariConfig.setMaximumPoolSize(20);
return new HikariDataSource(hikariConfig);
}
}
@@ -3,5 +3,8 @@
import br.com.emmanuelneri.model.Carrier;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface CarrierRepository extends JpaRepository<Carrier, Long> {
List<Carrier> findAllByName(String name);
}
@@ -4,5 +4,9 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import java.util.List;
public interface CustomerRepository extends JpaRepository<Customer, Long>, QueryDslPredicateExecutor<Customer> {
List<Customer> findAllByName(String name);
}
@@ -18,8 +18,11 @@ public Carrier save(Carrier carrier) {
return carrierRepository.save(carrier);
}
@Cacheable("carriers")
public List<Carrier> findAll() {
return carrierRepository.findAll();
}
public List<Carrier> findByName(String name) {
return carrierRepository.findAllByName(name);
}
}
@@ -40,4 +40,8 @@ public Customer save(Customer customer) {
public List<Customer> search(CustomerSearchTO searchTO) {
return Lists.newArrayList(customerRepository.findAll(searchTO.toPredicate()));
}
public List<Customer> findByName(String name) {
return customerRepository.findAllByName(name);
}
}

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit c8e3bce

Please sign in to comment.