Skip to content

Commit

Permalink
use HikariCP connection pool. spring-projects/spring-boot#418
Browse files Browse the repository at this point in the history
  • Loading branch information
XuefengWu committed Jan 14, 2017
1 parent b27426a commit 204e1f3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -14,6 +14,7 @@
.gradle/
build/
target/
out/

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
2 changes: 2 additions & 0 deletions build.gradle
Expand Up @@ -7,6 +7,7 @@ buildscript {
classpath 'org.liquibase:liquibase-core:3.4.1'
classpath "org.liquibase:liquibase-gradle-plugin:1.1.1"
classpath 'com.h2database:h2:1.4.193'
classpath 'com.zaxxer:HikariCP:2.5.1'
}
}

Expand All @@ -32,6 +33,7 @@ targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("com.h2database:h2")
compile("com.zaxxer:HikariCP")
compile("org.springframework.boot:spring-boot-starter-web")
testCompile("org.springframework.boot:spring-boot-starter-test")
}
Expand Down
28 changes: 22 additions & 6 deletions src/main/java/hello/RepositoryConfig.java
@@ -1,5 +1,6 @@
package hello;

import com.zaxxer.hikari.HikariDataSource;
import dynamic.CustomerContextHolder;
import dynamic.CustomerRoutingDataSource;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -98,8 +99,13 @@ public DataSource goldDataSource() {
String username = "sa";
String password = "";
String driverClassName = "org.h2.Driver";
DriverManagerDataSource dataSource = new DriverManagerDataSource(databaseUrl, username, password);
dataSource.setDriverClassName(driverClassName);
String dataSourceClassName = "org.h2.jdbcx.JdbcDataSource";
HikariDataSource dataSource = new HikariDataSource();
dataSource.setMaximumPoolSize(100);
dataSource.setDataSourceClassName(dataSourceClassName);
dataSource.addDataSourceProperty("url", databaseUrl);
dataSource.addDataSourceProperty("user", username);
dataSource.addDataSourceProperty("password", password);
return dataSource;
}

Expand All @@ -109,8 +115,13 @@ public DataSource silverDataSource() {
String username = "sa";
String password = "";
String driverClassName = "org.h2.Driver";
DriverManagerDataSource dataSource = new DriverManagerDataSource(databaseUrl, username, password);
dataSource.setDriverClassName(driverClassName);
String dataSourceClassName = "org.h2.jdbcx.JdbcDataSource";
HikariDataSource dataSource = new HikariDataSource();
dataSource.setMaximumPoolSize(100);
dataSource.setDataSourceClassName(dataSourceClassName);
dataSource.addDataSourceProperty("url", databaseUrl);
dataSource.addDataSourceProperty("user", username);
dataSource.addDataSourceProperty("password", password);
return dataSource;
}

Expand All @@ -120,8 +131,13 @@ public DataSource bronzeDataSource() {
String username = "sa";
String password = "";
String driverClassName = "org.h2.Driver";
DriverManagerDataSource dataSource = new DriverManagerDataSource(databaseUrl, username, password);
dataSource.setDriverClassName(driverClassName);
String dataSourceClassName = "org.h2.jdbcx.JdbcDataSource";
HikariDataSource dataSource = new HikariDataSource();
dataSource.setMaximumPoolSize(100);
dataSource.setDataSourceClassName(dataSourceClassName);
dataSource.addDataSourceProperty("url", databaseUrl);
dataSource.addDataSourceProperty("user", username);
dataSource.addDataSourceProperty("password", password);
return dataSource;
}

Expand Down

0 comments on commit 204e1f3

Please sign in to comment.