Skip to content

Commit

Permalink
Merge pull request #148 from yg3630536/feature/fix-mysql-driver
Browse files Browse the repository at this point in the history
add connection pool
  • Loading branch information
chenhaozx committed Jun 18, 2019
2 parents aafe479 + c6baca7 commit dc6458b
Show file tree
Hide file tree
Showing 7 changed files with 484 additions and 160 deletions.
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ List weidentity_contract = [
"com.webank:weidentity-contract-java:1.2.2"
]

List mysql_driver = [
"mysql:mysql-connector-java:5.1.44"
List db_driver = [
"mysql:mysql-connector-java:5.1.44",
"org.apache.commons:commons-dbcp2:2.5.0"
]

List web3sdk = [
Expand All @@ -92,7 +93,7 @@ List zxing = [

// In this section you declare the dependencies for your production and test code
dependencies {
compile logger, spring, lombok, apache_commons, json, web3sdk, weidentity_contract, mysql_driver, zxing
compile logger, spring, lombok, apache_commons, json, web3sdk, weidentity_contract, db_driver, zxing
testCompile logger, spring, lombok, apache_commons, json, web3sdk, junit, jmockit
}

Expand Down
92 changes: 90 additions & 2 deletions src/main/java/com/webank/weid/constant/DataDriverConstant.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,76 @@ public final class DataDriverConstant {
* jdbc user password properties.
*/
public static final String JDBC_USER_PASSWORD = "jdbc.password";


/**
* jdbc maxActive properties.
*/
public static final String JDBC_MAX_ACTIVE = "jdbc.maxActive";

/**
* jdbc minIdle properties.
*/
public static final String JDBC_MIN_IDLE = "jdbc.minIdle";

/**
* jdbc minIdle properties.
*/
public static final String JDBC_MAX_IDLE = "jdbc.maxIdle";

/**
* jdbc maxWait properties.
*/
public static final String JDBC_MAX_WAIT = "jdbc.maxWait";

/**
* jdbc timeBetweenEvictionRunsMillis properties.
*/
public static final String JDBC_TIME_BETWEEN_ERM = "jdbc.timeBetweenEvictionRunsMillis";

/**
* jdbc numTestsPerEvictionRun properties.
*/
public static final String JDBC_NUM_TEST_PER_ER = "jdbc.numTestsPerEvictionRun";

/**
* jdbc maxWait properties.
*/
public static final String JDBC_MIN_EITM = "jdbc.minEvictableIdleTimeMillis";

/**
* jdbc driverClassName.
*/
public static final String JDBC_MYSQL_DRIVER_CLASS_NAME = "com.mysql.jdbc.Driver";

/**
* jdbc removeAbandoned.
*/
public static final String JDBC_REMOVE_ABANDONED = "true";

/**
* jdbc removeAbandonedTimeout.
*/
public static final String JDBC_REMOVE_ABANDONED_TIMEOUT = "180";

/**
* jdbc testOnBorrow.
*/
public static final String JDBC_TEST_ON_BORROW = "false";

/**
* jdbc testOnWhile.
*/
public static final String JDBC_TEST_ON_WHILE = "true";

/**
* jdbc validationQuery.
*/
public static final String JDBC_VALIDATION_QUERY = "SELECT 1";

/**
* sql execute status.
*/
public static final Integer SQL_EXECUTE_FAILED_STATUS = -1;
public static final Integer SQL_EXECUTE_FAILED_STATUS = 0;

/**
* jdbc user password properties.
Expand All @@ -70,4 +135,27 @@ public final class DataDriverConstant {
* sql index.
*/
public static final int SQL_INDEX_THIRD = 3;

/**
* the key of ConnectionPool.
*/
public static final String POOL_DRIVER_CLASS_NAME = "driverClassName";
public static final String POOL_URL = "url";
public static final String POOL_USERNAME = "username";
public static final String POOL_PASSWORD = "password";
public static final String POOL_MAX_ACTIVE = "maxActive";
public static final String POOL_MIN_IDLE = "minIdle";
public static final String POOL_MAX_IDLE = "maxIdle";
public static final String POOL_MAX_WAIT = "maxWait";
public static final String POOL_MAX_REMOVE_ABANDONED = "removeAbandoned";
public static final String POOL_MAX_REMOVE_ABANDONED_TIMEOUT = "removeAbandonedTimeout";
public static final String POOL_TEST_ON_BORROW = "testOnBorrow";
public static final String POOL_TEST_ON_WHILE = "testWhileIdle";
public static final String POOL_TIME_BETWEEN_ERM = "timeBetweenEvictionRunsMillis";
public static final String POOL_NUM_TEST_PER_ER = "numTestsPerEvictionRun";
public static final String POOL_VALIDATION_QUERY = "validationQuery";
public static final String POOL_MIN_EITM = "minEvictableIdleTimeMillis";



}
8 changes: 8 additions & 0 deletions src/main/java/com/webank/weid/constant/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,14 @@ public enum ErrorCode {
"amop server side has no direct route callback."
),

/**
* can not get the connection from pool.
*/
SQL_GET_CONNECTION_ERROR(
160013,
"can not get the connection from pool, please check the error log."
),

/**
* other uncatched exceptions or error.
*/
Expand Down

0 comments on commit dc6458b

Please sign in to comment.