|
|
@ -15,13 +15,8 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package com.fr.third.alibaba.druid.pool; |
|
|
|
package com.fr.third.alibaba.druid.pool; |
|
|
|
|
|
|
|
|
|
|
|
import java.sql.Connection; |
|
|
|
import com.fr.third.alibaba.druid.support.logging.Log; |
|
|
|
import java.sql.SQLException; |
|
|
|
import com.fr.third.alibaba.druid.support.logging.LogFactory; |
|
|
|
import java.util.Collections; |
|
|
|
|
|
|
|
import java.util.Hashtable; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import java.util.Properties; |
|
|
|
|
|
|
|
import java.util.StringTokenizer; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.naming.Context; |
|
|
|
import javax.naming.Context; |
|
|
|
import javax.naming.Name; |
|
|
|
import javax.naming.Name; |
|
|
@ -29,9 +24,13 @@ import javax.naming.RefAddr; |
|
|
|
import javax.naming.Reference; |
|
|
|
import javax.naming.Reference; |
|
|
|
import javax.naming.spi.ObjectFactory; |
|
|
|
import javax.naming.spi.ObjectFactory; |
|
|
|
import javax.sql.DataSource; |
|
|
|
import javax.sql.DataSource; |
|
|
|
|
|
|
|
import java.sql.Connection; |
|
|
|
import com.fr.third.alibaba.druid.support.logging.Log; |
|
|
|
import java.sql.SQLException; |
|
|
|
import com.fr.third.alibaba.druid.support.logging.LogFactory; |
|
|
|
import java.util.Collections; |
|
|
|
|
|
|
|
import java.util.Hashtable; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import java.util.Properties; |
|
|
|
|
|
|
|
import java.util.StringTokenizer; |
|
|
|
|
|
|
|
|
|
|
|
public class DruidDataSourceFactory implements ObjectFactory { |
|
|
|
public class DruidDataSourceFactory implements ObjectFactory { |
|
|
|
|
|
|
|
|
|
|
@ -58,6 +57,10 @@ public class DruidDataSourceFactory implements ObjectFactory { |
|
|
|
public final static String HB_PROP_INITIALSIZE = HIBERNATE_PREFIX + "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 HB_PROP_MAXWAIT = HIBERNATE_PREFIX + "maxWait"; |
|
|
|
|
|
|
|
public final static String PROP_KEEP_ALIVE = "keepAlive"; |
|
|
|
|
|
|
|
public final static String HB_PROP_KEEP_ALIVE = HIBERNATE_PREFIX + "keepAlive"; |
|
|
|
|
|
|
|
public final static String PROP_KEEP_ALIVE_BETWEEN_TIME_MILLIS = "keepAliveBetweenTimeMillis"; |
|
|
|
|
|
|
|
public final static String HB_PROP_KEEP_ALIVE_BETWEEN_TIME_MILLIS = HIBERNATE_PREFIX + "keepAliveBetweenTimeMillis"; |
|
|
|
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 HB_PROP_TESTONBORROW = HIBERNATE_PREFIX + "testOnBorrow"; |
|
|
|
public final static String PROP_TESTONRETURN = "testOnReturn"; |
|
|
|
public final static String PROP_TESTONRETURN = "testOnReturn"; |
|
|
@ -80,11 +83,15 @@ public class DruidDataSourceFactory implements ObjectFactory { |
|
|
|
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 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 HB_PROP_VALIDATIONQUERY_TIMEOUT = HIBERNATE_PREFIX + "validationQueryTimeout"; |
|
|
|
public final static String PROP_INITCONNECTIONSQLS = "initConnectionSqls"; |
|
|
|
public final static String PROP_INITCONNECTIONSQLS = "initConnectionSqls"; |
|
|
|
public final static String PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED = "accessToUnderlyingConnectionAllowed"; |
|
|
|
public final static String PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED = "accessToUnderlyingConnectionAllowed"; |
|
|
|
public final static String PROP_REMOVEABANDONED = "removeAbandoned"; |
|
|
|
public final static String PROP_REMOVEABANDONED = "removeAbandoned"; |
|
|
|
|
|
|
|
public final static String HB_PROP_REMOVEABANDONED = HIBERNATE_PREFIX + "removeAbandoned"; |
|
|
|
public final static String PROP_REMOVEABANDONEDTIMEOUT = "removeAbandonedTimeout"; |
|
|
|
public final static String PROP_REMOVEABANDONEDTIMEOUT = "removeAbandonedTimeout"; |
|
|
|
|
|
|
|
public final static String HB_PROP_REMOVEABANDONEDTIMEOUT = HIBERNATE_PREFIX + "removeAbandonedTimeout"; |
|
|
|
public final static String PROP_LOGABANDONED = "logAbandoned"; |
|
|
|
public final static String PROP_LOGABANDONED = "logAbandoned"; |
|
|
|
|
|
|
|
public final static String HB_PROP_LOGABANDONED = HIBERNATE_PREFIX + "logAbandoned"; |
|
|
|
public final static String PROP_POOLPREPAREDSTATEMENTS = "poolPreparedStatements"; |
|
|
|
public final static String PROP_POOLPREPAREDSTATEMENTS = "poolPreparedStatements"; |
|
|
|
public final static String PROP_MAXOPENPREPAREDSTATEMENTS = "maxOpenPreparedStatements"; |
|
|
|
public final static String PROP_MAXOPENPREPAREDSTATEMENTS = "maxOpenPreparedStatements"; |
|
|
|
public final static String PROP_CONNECTIONPROPERTIES = "connectionProperties"; |
|
|
|
public final static String PROP_CONNECTIONPROPERTIES = "connectionProperties"; |
|
|
@ -105,6 +112,8 @@ public class DruidDataSourceFactory implements ObjectFactory { |
|
|
|
PROP_MINIDLE, |
|
|
|
PROP_MINIDLE, |
|
|
|
PROP_INITIALSIZE, |
|
|
|
PROP_INITIALSIZE, |
|
|
|
PROP_MAXWAIT, |
|
|
|
PROP_MAXWAIT, |
|
|
|
|
|
|
|
PROP_KEEP_ALIVE, |
|
|
|
|
|
|
|
PROP_KEEP_ALIVE_BETWEEN_TIME_MILLIS, |
|
|
|
PROP_TESTONBORROW, |
|
|
|
PROP_TESTONBORROW, |
|
|
|
PROP_TESTONRETURN, |
|
|
|
PROP_TESTONRETURN, |
|
|
|
PROP_TIMEBETWEENEVICTIONRUNSMILLIS, |
|
|
|
PROP_TIMEBETWEENEVICTIONRUNSMILLIS, |
|
|
@ -324,6 +333,36 @@ public class DruidDataSourceFactory implements ObjectFactory { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
value = (String) properties.get(PROP_KEEP_ALIVE); |
|
|
|
|
|
|
|
if (value != null) { |
|
|
|
|
|
|
|
dataSource.setKeepAlive(Boolean.parseBoolean(value)); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
Object o = properties.get(HB_PROP_KEEP_ALIVE); |
|
|
|
|
|
|
|
if (o != null) { |
|
|
|
|
|
|
|
if (o instanceof Boolean) { |
|
|
|
|
|
|
|
dataSource.setKeepAlive((Boolean) o); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
value = (String) o; |
|
|
|
|
|
|
|
dataSource.setKeepAlive(Boolean.parseBoolean(value)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
value = (String) properties.get(PROP_KEEP_ALIVE_BETWEEN_TIME_MILLIS); |
|
|
|
|
|
|
|
if (value != null) { |
|
|
|
|
|
|
|
dataSource.setKeepAliveBetweenTimeMillis(Long.parseLong(value)); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
Object o = properties.get(HB_PROP_KEEP_ALIVE_BETWEEN_TIME_MILLIS); |
|
|
|
|
|
|
|
if (o != null) { |
|
|
|
|
|
|
|
if (o instanceof Integer) { |
|
|
|
|
|
|
|
dataSource.setKeepAliveBetweenTimeMillis((int) o); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
value = (String) o; |
|
|
|
|
|
|
|
dataSource.setKeepAliveBetweenTimeMillis(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()); |
|
|
@ -462,6 +501,11 @@ public class DruidDataSourceFactory implements ObjectFactory { |
|
|
|
value = (String) properties.get(PROP_VALIDATIONQUERY_TIMEOUT); |
|
|
|
value = (String) properties.get(PROP_VALIDATIONQUERY_TIMEOUT); |
|
|
|
if (value != null) { |
|
|
|
if (value != null) { |
|
|
|
dataSource.setValidationQueryTimeout(Integer.parseInt(value)); |
|
|
|
dataSource.setValidationQueryTimeout(Integer.parseInt(value)); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
value = (String) properties.get(HB_PROP_VALIDATIONQUERY_TIMEOUT); |
|
|
|
|
|
|
|
if (value != null && value.length() > 0) { |
|
|
|
|
|
|
|
dataSource.setValidationQueryTimeout(Integer.parseInt(value)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
value = (String) properties.get(PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED); |
|
|
|
value = (String) properties.get(PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED); |
|
|
@ -472,16 +516,31 @@ public class DruidDataSourceFactory implements ObjectFactory { |
|
|
|
value = (String) properties.get(PROP_REMOVEABANDONED); |
|
|
|
value = (String) properties.get(PROP_REMOVEABANDONED); |
|
|
|
if (value != null) { |
|
|
|
if (value != null) { |
|
|
|
dataSource.setRemoveAbandoned(Boolean.valueOf(value).booleanValue()); |
|
|
|
dataSource.setRemoveAbandoned(Boolean.valueOf(value).booleanValue()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
value = (String) properties.get(HB_PROP_REMOVEABANDONED); |
|
|
|
|
|
|
|
if (value != null && value.length() > 0) { |
|
|
|
|
|
|
|
dataSource.setRemoveAbandoned(Boolean.parseBoolean(value)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
value = (String) properties.get(PROP_REMOVEABANDONEDTIMEOUT); |
|
|
|
value = (String) properties.get(PROP_REMOVEABANDONEDTIMEOUT); |
|
|
|
if (value != null) { |
|
|
|
if (value != null) { |
|
|
|
dataSource.setRemoveAbandonedTimeout(Integer.parseInt(value)); |
|
|
|
dataSource.setRemoveAbandonedTimeout(Integer.parseInt(value)); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
value = (String) properties.get(HB_PROP_REMOVEABANDONEDTIMEOUT); |
|
|
|
|
|
|
|
if (value != null && value.length() > 0) { |
|
|
|
|
|
|
|
dataSource.setRemoveAbandonedTimeout(Integer.parseInt(value)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
value = (String) properties.get(PROP_LOGABANDONED); |
|
|
|
value = (String) properties.get(PROP_LOGABANDONED); |
|
|
|
if (value != null) { |
|
|
|
if (value != null) { |
|
|
|
dataSource.setLogAbandoned(Boolean.valueOf(value).booleanValue()); |
|
|
|
dataSource.setLogAbandoned(Boolean.valueOf(value).booleanValue()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
value = (String) properties.get(HB_PROP_LOGABANDONED); |
|
|
|
|
|
|
|
if (value != null && value.length() > 0) { |
|
|
|
|
|
|
|
dataSource.setLogAbandoned(Boolean.parseBoolean(value)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
value = (String) properties.get(PROP_POOLPREPAREDSTATEMENTS); |
|
|
|
value = (String) properties.get(PROP_POOLPREPAREDSTATEMENTS); |
|
|
|