|
|
|
@ -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); |
|
|
|
|