Skip to content

Commit

Permalink
fix #404
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Oct 11, 2017
1 parent 444f950 commit d390fd0
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 3 deletions.
6 changes: 6 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 2.0.0.M2

### 缺陷修正

1. [ISSUE #404](https://github.com/shardingjdbc/sharding-jdbc/issues/404) sharding-jdbc-spring-boot-starter不支持HikariDataSource

## 2.0.0.M1

### 里程碑
Expand Down
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<h2.version>1.4.196</h2.version>
<postgresql.version>9.1-901-1.jdbc4</postgresql.version>
<mssql.version>6.1.7.jre7-preview</mssql.version>
<hikari-cp.version>2.4.11</hikari-cp.version>
<junit.version>4.12</junit.version>
<hamcrest.version>1.3</hamcrest.version>
<dbunit.version>2.5.3</dbunit.version>
Expand Down Expand Up @@ -193,6 +194,12 @@
<version>${mssql.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP-java7</artifactId>
<version>${hikari-cp.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions sharding-jdbc-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP-java7</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private static String getSetterMethodName(final String propertyName) {
private static void callSetterMethod(final DataSource dataSource, final String methodName, final String setterValue) {
for (Class<?> each : generalClassType) {
try {
Method method = dataSource.getClass().getDeclaredMethod(methodName, each);
Method method = dataSource.getClass().getMethod(methodName, each);
if (boolean.class == each || Boolean.class == each) {
method.invoke(dataSource, Boolean.valueOf(setterValue));
} else if (int.class == each || Integer.class == each) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
StringUtilTest.class,
InlineExpressionParserTest.class,
SQLUtilTest.class,
EventBusInstanceTest.class
EventBusInstanceTest.class,
DataSourceUtilTest.class
})
public class AllUtilTests {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 1999-2015 dangdang.com.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* </p>
*/

package io.shardingjdbc.core.util;

import com.zaxxer.hikari.HikariDataSource;
import org.apache.commons.dbcp.BasicDataSource;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

public final class DataSourceUtilTest {

@Test
public void assertDataSourceForDBCP() throws ReflectiveOperationException {
Map<String, Object> dataSourceProperties = new HashMap<>(3, 1);
dataSourceProperties.put("driverClassName", org.h2.Driver.class.getName());
dataSourceProperties.put("url", "jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL");
dataSourceProperties.put("username", "sa");
BasicDataSource actual = (BasicDataSource) DataSourceUtil.getDataSource(BasicDataSource.class.getName(), dataSourceProperties);
assertThat(actual.getDriverClassName(), is(org.h2.Driver.class.getName()));
assertThat(actual.getUrl(), is("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL"));
assertThat(actual.getUsername(), is("sa"));
}

@Test
public void assertDataSourceForHikariCP() throws ReflectiveOperationException {
Map<String, Object> dataSourceProperties = new HashMap<>(3, 1);
dataSourceProperties.put("driverClassName", org.h2.Driver.class.getName());
dataSourceProperties.put("jdbcUrl", "jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL");
dataSourceProperties.put("username", "sa");
HikariDataSource actual = (HikariDataSource) DataSourceUtil.getDataSource(HikariDataSource.class.getName(), dataSourceProperties);
assertThat(actual.getDriverClassName(), is(org.h2.Driver.class.getName()));
assertThat(actual.getJdbcUrl(), is("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL"));
assertThat(actual.getUsername(), is("sa"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static void createDataSourceBean(final ApplicationContext applicationContext, fi
BeanDefinition beanDefinition = new GenericBeanDefinition();
beanDefinition.setBeanClassName(dataSource.getClass().getName());
beanFactory.registerBeanDefinition(dataSourceName, beanDefinition);
Method[] methods = dataSource.getClass().getDeclaredMethods();
Method[] methods = dataSource.getClass().getMethods();
Map<String, Method> getterMethods = new TreeMap<>();
Map<String, Method> setterMethods = new TreeMap<>();
for (Method each : methods) {
Expand Down

0 comments on commit d390fd0

Please sign in to comment.