From d767e030af8972585eb7104d051224bdda44cd2b Mon Sep 17 00:00:00 2001 From: loy Date: Wed, 19 Sep 2018 11:14:35 +0800 Subject: [PATCH 1/2] =?UTF-8?q?REPORT-11437=20=E8=B0=83=E6=95=B4druid?= =?UTF-8?q?=E6=BA=90=E7=A0=81=EF=BC=8C=E6=94=AF=E6=8C=81=E8=AF=BB=E5=8F=96?= =?UTF-8?q?hibernate=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../druid/pool/DruidDataSourceFactory.java | 154 ++++++++++++++++++ 1 file changed, 154 insertions(+) diff --git a/fine-druid/src/com/fr/third/alibaba/druid/pool/DruidDataSourceFactory.java b/fine-druid/src/com/fr/third/alibaba/druid/pool/DruidDataSourceFactory.java index e91429c07..5ab99fa48 100644 --- a/fine-druid/src/com/fr/third/alibaba/druid/pool/DruidDataSourceFactory.java +++ b/fine-druid/src/com/fr/third/alibaba/druid/pool/DruidDataSourceFactory.java @@ -39,27 +39,46 @@ public class DruidDataSourceFactory implements ObjectFactory { static final int UNKNOWN_TRANSACTIONISOLATION = -1; + private final static String HIBERNATE_PREFIX = "hibernate."; + private final static String HIBERNATE_CONN_PREFIX = "connection."; + public final static String PROP_DEFAULTAUTOCOMMIT = "defaultAutoCommit"; public final static String PROP_DEFAULTREADONLY = "defaultReadOnly"; public final static String PROP_DEFAULTTRANSACTIONISOLATION = "defaultTransactionIsolation"; public final static String PROP_DEFAULTCATALOG = "defaultCatalog"; public final static String PROP_DRIVERCLASSNAME = "driverClassName"; + public final static String HB_PROP_DRIVERCLASSNAME = HIBERNATE_PREFIX + HIBERNATE_CONN_PREFIX + "driver_class"; public final static String PROP_MAXACTIVE = "maxActive"; + public final static String HB_PROP_MAXACTIVE = HIBERNATE_PREFIX + "maxActive"; public final static String PROP_MAXIDLE = "maxIdle"; + public final static String HB_PROP_MAXIDLE = HIBERNATE_PREFIX + "maxIdle"; public final static String PROP_MINIDLE = "minIdle"; + public final static String HB_PROP_MINIDLE = HIBERNATE_PREFIX + "minIdle"; public final static String PROP_INITIALSIZE = "initialSize"; + public final static String HB_PROP_INITIALSIZE = HIBERNATE_PREFIX + "initialSize"; public final static String PROP_MAXWAIT = "maxWait"; + public final static String HB_PROP_MAXWAIT = HIBERNATE_PREFIX + "maxWait"; public final static String PROP_TESTONBORROW = "testOnBorrow"; + public final static String HB_PROP_TESTONBORROW = HIBERNATE_PREFIX + "testOnBorrow"; public final static String PROP_TESTONRETURN = "testOnReturn"; + public final static String HB_PROP_TESTONRETURN = HIBERNATE_PREFIX + "testOnReturn"; public final static String PROP_TIMEBETWEENEVICTIONRUNSMILLIS = "timeBetweenEvictionRunsMillis"; + public final static String HB_PROP_TIMEBETWEENEVICTIONRUNSMILLIS = HIBERNATE_PREFIX + "timeBetweenEvictionRunsMillis"; public final static String PROP_NUMTESTSPEREVICTIONRUN = "numTestsPerEvictionRun"; + public final static String HB_PROP_NUMTESTSPEREVICTIONRUN = HIBERNATE_PREFIX + "numTestsPerEvictionRun"; public final static String PROP_MINEVICTABLEIDLETIMEMILLIS = "minEvictableIdleTimeMillis"; + public final static String HB_PROP_MINEVICTABLEIDLETIMEMILLIS = HIBERNATE_PREFIX + "minEvictableIdleTimeMillis"; public final static String PROP_PHY_TIMEOUT_MILLIS = "phyTimeoutMillis"; public final static String PROP_TESTWHILEIDLE = "testWhileIdle"; + public final static String HB_PROP_TESTWHILEIDLE = HIBERNATE_PREFIX + "testWhileIdle"; public final static String PROP_PASSWORD = "password"; + public final static String HB_PROP_PASSWORD = HIBERNATE_PREFIX + HIBERNATE_CONN_PREFIX + "password"; public final static String PROP_URL = "url"; + public final static String HB_PROP_URL = HIBERNATE_PREFIX + HIBERNATE_CONN_PREFIX + "url"; public final static String PROP_USERNAME = "username"; + public final static String HB_PROP_USERNAME = HIBERNATE_PREFIX + HIBERNATE_CONN_PREFIX + "username"; public final static String PROP_VALIDATIONQUERY = "validationQuery"; + public final static String HB_PROP_VALIDATIONQUERY = HIBERNATE_PREFIX + "validationQuery"; public final static String PROP_VALIDATIONQUERY_TIMEOUT = "validationQueryTimeout"; public final static String PROP_INITCONNECTIONSQLS = "initConnectionSqls"; @@ -198,56 +217,161 @@ public class DruidDataSourceFactory implements ObjectFactory { value = (String) properties.get(PROP_DRIVERCLASSNAME); if (value != null) { dataSource.setDriverClassName(value); + } else { + value = (String) properties.get(HB_PROP_DRIVERCLASSNAME); + if (value != null) { + dataSource.setDriverClassName(value); + } } value = (String) properties.get(PROP_MAXACTIVE); if (value != null) { dataSource.setMaxActive(Integer.parseInt(value)); + } else { + Object o = properties.get(HB_PROP_MAXACTIVE); + if (o != null) { + if (o instanceof Integer) { + dataSource.setMaxActive((Integer) o); + } else { + value = (String) o; + dataSource.setMaxActive(Integer.parseInt(value)); + } + } } value = (String) properties.get(PROP_MAXIDLE); if (value != null) { dataSource.setMaxIdle(Integer.parseInt(value)); + } else { + Object o = properties.get(HB_PROP_MAXIDLE); + if (o != null) { + if (o instanceof Integer) { + dataSource.setMaxIdle((Integer) o); + } else { + value = (String) o; + dataSource.setMaxIdle(Integer.parseInt(value)); + } + } } value = (String) properties.get(PROP_MINIDLE); if (value != null) { dataSource.setMinIdle(Integer.parseInt(value)); + } else { + Object o = properties.get(HB_PROP_MINIDLE); + if (o != null) { + if (o instanceof Integer) { + dataSource.setMinIdle((Integer) o); + } else { + value = (String) o; + dataSource.setMinIdle(Integer.parseInt(value)); + } + } } value = (String) properties.get(PROP_INITIALSIZE); if (value != null) { dataSource.setInitialSize(Integer.parseInt(value)); + } else { + Object o = properties.get(HB_PROP_INITIALSIZE); + if (o != null) { + if (o instanceof Integer) { + dataSource.setInitialSize((Integer) o); + } else { + value = (String) o; + dataSource.setInitialSize(Integer.parseInt(value)); + } + } } value = (String) properties.get(PROP_MAXWAIT); if (value != null) { dataSource.setMaxWait(Long.parseLong(value)); + } else { + Object o = properties.get(HB_PROP_MAXWAIT); + if (o != null) { + if (o instanceof Integer) { + dataSource.setMaxWait((Integer) o); + } else { + value = (String) o; + dataSource.setMaxWait(Integer.parseInt(value)); + } + } } value = (String) properties.get(PROP_TESTONBORROW); if (value != null) { dataSource.setTestOnBorrow(Boolean.valueOf(value).booleanValue()); + } else { + Object o = properties.get(HB_PROP_TESTONBORROW); + if (o != null) { + if (o instanceof Boolean) { + dataSource.setTestOnBorrow((Boolean) o); + } else { + value = (String) o; + dataSource.setTestOnBorrow(Boolean.valueOf(value).booleanValue()); + } + } } value = (String) properties.get(PROP_TESTONRETURN); if (value != null) { dataSource.setTestOnReturn(Boolean.valueOf(value).booleanValue()); + } else { + Object o = properties.get(HB_PROP_TESTONRETURN); + if (o != null) { + if (o instanceof Boolean) { + dataSource.setTestOnReturn((Boolean) o); + } else { + value = (String) o; + dataSource.setTestOnReturn(Boolean.valueOf(value).booleanValue()); + } + } } value = (String) properties.get(PROP_TIMEBETWEENEVICTIONRUNSMILLIS); if (value != null) { dataSource.setTimeBetweenEvictionRunsMillis(Long.parseLong(value)); + } else { + Object o = properties.get(HB_PROP_TIMEBETWEENEVICTIONRUNSMILLIS); + if (o != null) { + if (o instanceof Integer) { + dataSource.setTimeBetweenEvictionRunsMillis((Integer) o); + } else { + value = (String) o; + dataSource.setTimeBetweenEvictionRunsMillis(Integer.parseInt(value)); + } + } } value = (String) properties.get(PROP_NUMTESTSPEREVICTIONRUN); if (value != null) { dataSource.setNumTestsPerEvictionRun(Integer.parseInt(value)); + } else { + Object o = properties.get(HB_PROP_NUMTESTSPEREVICTIONRUN); + if (o != null) { + if (o instanceof Integer) { + dataSource.setNumTestsPerEvictionRun((Integer) o); + } else { + value = (String) o; + dataSource.setNumTestsPerEvictionRun(Integer.parseInt(value)); + } + } } value = (String) properties.get(PROP_MINEVICTABLEIDLETIMEMILLIS); if (value != null) { dataSource.setMinEvictableIdleTimeMillis(Long.parseLong(value)); + } else { + Object o = properties.get(HB_PROP_MINEVICTABLEIDLETIMEMILLIS); + if (o != null) { + if (o instanceof Integer) { + dataSource.setMinEvictableIdleTimeMillis((Integer) o); + } else { + value = (String) o; + dataSource.setMinEvictableIdleTimeMillis(Integer.parseInt(value)); + } + } } value = (String) properties.get(PROP_PHY_TIMEOUT_MILLIS); @@ -258,26 +382,56 @@ public class DruidDataSourceFactory implements ObjectFactory { value = (String) properties.get(PROP_TESTWHILEIDLE); if (value != null) { dataSource.setTestWhileIdle(Boolean.valueOf(value).booleanValue()); + } else { + Object o = properties.get(HB_PROP_TESTWHILEIDLE); + if (o != null) { + if (o instanceof Boolean) { + dataSource.setTestWhileIdle((Boolean) o); + } else { + value = (String) o; + dataSource.setTestWhileIdle(Boolean.valueOf(value).booleanValue()); + } + } } value = (String) properties.get(PROP_PASSWORD); if (value != null) { dataSource.setPassword(value); + } else { + value = (String) properties.get(HB_PROP_PASSWORD); + if (value != null) { + dataSource.setPassword(value); + } } value = (String) properties.get(PROP_URL); if (value != null) { dataSource.setUrl(value); + } else { + value = (String) properties.get(HB_PROP_URL); + if (value != null) { + dataSource.setUrl(value); + } } value = (String) properties.get(PROP_USERNAME); if (value != null) { dataSource.setUsername(value); + } else { + value = (String) properties.get(HB_PROP_USERNAME); + if (value != null) { + dataSource.setUsername(value); + } } value = (String) properties.get(PROP_VALIDATIONQUERY); if (value != null) { dataSource.setValidationQuery(value); + } else { + value = (String) properties.get(HB_PROP_VALIDATIONQUERY); + if (value != null) { + dataSource.setValidationQuery(value); + } } value = (String) properties.get(PROP_VALIDATIONQUERY_TIMEOUT); From 67a16f2f08537a52e831881e6c8e85ab6b532a89 Mon Sep 17 00:00:00 2001 From: loy Date: Wed, 19 Sep 2018 12:49:38 +0800 Subject: [PATCH 2/2] =?UTF-8?q?REPORT-11437=20=E8=B0=83=E6=95=B4druid?= =?UTF-8?q?=E6=BA=90=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/third/alibaba/druid/pool/DruidDataSourceFactory.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fine-druid/src/com/fr/third/alibaba/druid/pool/DruidDataSourceFactory.java b/fine-druid/src/com/fr/third/alibaba/druid/pool/DruidDataSourceFactory.java index 5ab99fa48..256decf5d 100644 --- a/fine-druid/src/com/fr/third/alibaba/druid/pool/DruidDataSourceFactory.java +++ b/fine-druid/src/com/fr/third/alibaba/druid/pool/DruidDataSourceFactory.java @@ -425,11 +425,11 @@ public class DruidDataSourceFactory implements ObjectFactory { } value = (String) properties.get(PROP_VALIDATIONQUERY); - if (value != null) { + if (value != null && value.length() > 0) { dataSource.setValidationQuery(value); } else { value = (String) properties.get(HB_PROP_VALIDATIONQUERY); - if (value != null) { + if (value != null && value.length() > 0) { dataSource.setValidationQuery(value); } }