|
|
@ -39,27 +39,46 @@ public class DruidDataSourceFactory implements ObjectFactory { |
|
|
|
|
|
|
|
|
|
|
|
static final int UNKNOWN_TRANSACTIONISOLATION = -1; |
|
|
|
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_DEFAULTAUTOCOMMIT = "defaultAutoCommit"; |
|
|
|
public final static String PROP_DEFAULTREADONLY = "defaultReadOnly"; |
|
|
|
public final static String PROP_DEFAULTREADONLY = "defaultReadOnly"; |
|
|
|
public final static String PROP_DEFAULTTRANSACTIONISOLATION = "defaultTransactionIsolation"; |
|
|
|
public final static String PROP_DEFAULTTRANSACTIONISOLATION = "defaultTransactionIsolation"; |
|
|
|
public final static String PROP_DEFAULTCATALOG = "defaultCatalog"; |
|
|
|
public final static String PROP_DEFAULTCATALOG = "defaultCatalog"; |
|
|
|
public final static String PROP_DRIVERCLASSNAME = "driverClassName"; |
|
|
|
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 PROP_MAXACTIVE = "maxActive"; |
|
|
|
|
|
|
|
public final static String HB_PROP_MAXACTIVE = HIBERNATE_PREFIX + "maxActive"; |
|
|
|
public final static String PROP_MAXIDLE = "maxIdle"; |
|
|
|
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 PROP_MINIDLE = "minIdle"; |
|
|
|
|
|
|
|
public final static String HB_PROP_MINIDLE = HIBERNATE_PREFIX + "minIdle"; |
|
|
|
public final static String PROP_INITIALSIZE = "initialSize"; |
|
|
|
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 PROP_MAXWAIT = "maxWait"; |
|
|
|
|
|
|
|
public final static String HB_PROP_MAXWAIT = HIBERNATE_PREFIX + "maxWait"; |
|
|
|
public final static String PROP_TESTONBORROW = "testOnBorrow"; |
|
|
|
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 PROP_TESTONRETURN = "testOnReturn"; |
|
|
|
|
|
|
|
public final static String HB_PROP_TESTONRETURN = HIBERNATE_PREFIX + "testOnReturn"; |
|
|
|
public final static String PROP_TIMEBETWEENEVICTIONRUNSMILLIS = "timeBetweenEvictionRunsMillis"; |
|
|
|
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 PROP_NUMTESTSPEREVICTIONRUN = "numTestsPerEvictionRun"; |
|
|
|
|
|
|
|
public final static String HB_PROP_NUMTESTSPEREVICTIONRUN = HIBERNATE_PREFIX + "numTestsPerEvictionRun"; |
|
|
|
public final static String PROP_MINEVICTABLEIDLETIMEMILLIS = "minEvictableIdleTimeMillis"; |
|
|
|
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_PHY_TIMEOUT_MILLIS = "phyTimeoutMillis"; |
|
|
|
public final static String PROP_TESTWHILEIDLE = "testWhileIdle"; |
|
|
|
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 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 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 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 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_VALIDATIONQUERY_TIMEOUT = "validationQueryTimeout"; |
|
|
|
|
|
|
|
|
|
|
|
public final static String PROP_INITCONNECTIONSQLS = "initConnectionSqls"; |
|
|
|
public final static String PROP_INITCONNECTIONSQLS = "initConnectionSqls"; |
|
|
@ -198,56 +217,161 @@ public class DruidDataSourceFactory implements ObjectFactory { |
|
|
|
value = (String) properties.get(PROP_DRIVERCLASSNAME); |
|
|
|
value = (String) properties.get(PROP_DRIVERCLASSNAME); |
|
|
|
if (value != null) { |
|
|
|
if (value != null) { |
|
|
|
dataSource.setDriverClassName(value); |
|
|
|
dataSource.setDriverClassName(value); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
value = (String) properties.get(HB_PROP_DRIVERCLASSNAME); |
|
|
|
|
|
|
|
if (value != null) { |
|
|
|
|
|
|
|
dataSource.setDriverClassName(value); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
value = (String) properties.get(PROP_MAXACTIVE); |
|
|
|
value = (String) properties.get(PROP_MAXACTIVE); |
|
|
|
if (value != null) { |
|
|
|
if (value != null) { |
|
|
|
dataSource.setMaxActive(Integer.parseInt(value)); |
|
|
|
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); |
|
|
|
value = (String) properties.get(PROP_MAXIDLE); |
|
|
|
if (value != null) { |
|
|
|
if (value != null) { |
|
|
|
dataSource.setMaxIdle(Integer.parseInt(value)); |
|
|
|
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); |
|
|
|
value = (String) properties.get(PROP_MINIDLE); |
|
|
|
if (value != null) { |
|
|
|
if (value != null) { |
|
|
|
dataSource.setMinIdle(Integer.parseInt(value)); |
|
|
|
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); |
|
|
|
value = (String) properties.get(PROP_INITIALSIZE); |
|
|
|
if (value != null) { |
|
|
|
if (value != null) { |
|
|
|
dataSource.setInitialSize(Integer.parseInt(value)); |
|
|
|
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); |
|
|
|
value = (String) properties.get(PROP_MAXWAIT); |
|
|
|
if (value != null) { |
|
|
|
if (value != null) { |
|
|
|
dataSource.setMaxWait(Long.parseLong(value)); |
|
|
|
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); |
|
|
|
value = (String) properties.get(PROP_TESTONBORROW); |
|
|
|
if (value != null) { |
|
|
|
if (value != null) { |
|
|
|
dataSource.setTestOnBorrow(Boolean.valueOf(value).booleanValue()); |
|
|
|
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); |
|
|
|
value = (String) properties.get(PROP_TESTONRETURN); |
|
|
|
if (value != null) { |
|
|
|
if (value != null) { |
|
|
|
dataSource.setTestOnReturn(Boolean.valueOf(value).booleanValue()); |
|
|
|
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); |
|
|
|
value = (String) properties.get(PROP_TIMEBETWEENEVICTIONRUNSMILLIS); |
|
|
|
if (value != null) { |
|
|
|
if (value != null) { |
|
|
|
dataSource.setTimeBetweenEvictionRunsMillis(Long.parseLong(value)); |
|
|
|
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); |
|
|
|
value = (String) properties.get(PROP_NUMTESTSPEREVICTIONRUN); |
|
|
|
if (value != null) { |
|
|
|
if (value != null) { |
|
|
|
dataSource.setNumTestsPerEvictionRun(Integer.parseInt(value)); |
|
|
|
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); |
|
|
|
value = (String) properties.get(PROP_MINEVICTABLEIDLETIMEMILLIS); |
|
|
|
if (value != null) { |
|
|
|
if (value != null) { |
|
|
|
dataSource.setMinEvictableIdleTimeMillis(Long.parseLong(value)); |
|
|
|
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); |
|
|
|
value = (String) properties.get(PROP_PHY_TIMEOUT_MILLIS); |
|
|
@ -258,26 +382,56 @@ public class DruidDataSourceFactory implements ObjectFactory { |
|
|
|
value = (String) properties.get(PROP_TESTWHILEIDLE); |
|
|
|
value = (String) properties.get(PROP_TESTWHILEIDLE); |
|
|
|
if (value != null) { |
|
|
|
if (value != null) { |
|
|
|
dataSource.setTestWhileIdle(Boolean.valueOf(value).booleanValue()); |
|
|
|
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); |
|
|
|
value = (String) properties.get(PROP_PASSWORD); |
|
|
|
|
|
|
|
if (value != null) { |
|
|
|
|
|
|
|
dataSource.setPassword(value); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
value = (String) properties.get(HB_PROP_PASSWORD); |
|
|
|
if (value != null) { |
|
|
|
if (value != null) { |
|
|
|
dataSource.setPassword(value); |
|
|
|
dataSource.setPassword(value); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
value = (String) properties.get(PROP_URL); |
|
|
|
value = (String) properties.get(PROP_URL); |
|
|
|
|
|
|
|
if (value != null) { |
|
|
|
|
|
|
|
dataSource.setUrl(value); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
value = (String) properties.get(HB_PROP_URL); |
|
|
|
if (value != null) { |
|
|
|
if (value != null) { |
|
|
|
dataSource.setUrl(value); |
|
|
|
dataSource.setUrl(value); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
value = (String) properties.get(PROP_USERNAME); |
|
|
|
value = (String) properties.get(PROP_USERNAME); |
|
|
|
if (value != null) { |
|
|
|
if (value != null) { |
|
|
|
dataSource.setUsername(value); |
|
|
|
dataSource.setUsername(value); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
value = (String) properties.get(HB_PROP_USERNAME); |
|
|
|
|
|
|
|
if (value != null) { |
|
|
|
|
|
|
|
dataSource.setUsername(value); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
value = (String) properties.get(PROP_VALIDATIONQUERY); |
|
|
|
value = (String) properties.get(PROP_VALIDATIONQUERY); |
|
|
|
if (value != null) { |
|
|
|
if (value != null) { |
|
|
|
dataSource.setValidationQuery(value); |
|
|
|
dataSource.setValidationQuery(value); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
value = (String) properties.get(HB_PROP_VALIDATIONQUERY); |
|
|
|
|
|
|
|
if (value != null) { |
|
|
|
|
|
|
|
dataSource.setValidationQuery(value); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
value = (String) properties.get(PROP_VALIDATIONQUERY_TIMEOUT); |
|
|
|
value = (String) properties.get(PROP_VALIDATIONQUERY_TIMEOUT); |
|
|
|