public final class PoolUtilities extends Object
| Constructor and Description |
|---|
PoolUtilities() |
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
createInstance(String className,
Class<T> clazz,
Object... args)
Create and instance of the specified class using the constructor matching the specified
arguments.
|
static ThreadPoolExecutor |
createThreadPoolExecutor(int queueSize,
String threadName,
ThreadFactory threadFactory,
RejectedExecutionHandler policy)
Create a ThreadPoolExecutor.
|
static long |
elapsedTimeMs(long start)
Get the elapsed time in millisecond between the specified start time and now.
|
static void |
executeSqlAutoCommit(Connection connection,
String sql)
Execute the user-specified init SQL.
|
static int |
getTransactionIsolation(String transactionIsolationName)
Get the int value of a transaction isolation level by name.
|
static DataSource |
initializeDataSource(String dsClassName,
DataSource dataSource,
Properties dataSourceProperties,
String jdbcUrl,
String username,
String password)
Create/initialize the underlying DataSource.
|
static boolean |
isJdbc40Compliant(Connection connection)
Return true if the driver appears to be JDBC 4.0 compliant.
|
static boolean |
isJdbc41Compliant(Connection connection)
Return true if the driver appears to be JDBC 4.1 compliant.
|
static void |
quietlyCloseConnection(Connection connection)
Close connection and eat any exception.
|
static void |
quietlySleep(long millis)
Sleep and transform an InterruptedException into a RuntimeException.
|
static void |
setLoginTimeout(DataSource dataSource,
long connectionTimeout,
org.slf4j.Logger logger)
Set the loginTimeout on the specified DataSource.
|
static int |
setNetworkTimeout(Executor executor,
Connection connection,
long timeoutMs,
boolean isUseNetworkTimeout)
Set the network timeout, if
isUseNetworkTimeout is true, and return the
pre-existing value of the network timeout. |
static void |
setQueryTimeout(Statement statement,
int timeoutSec)
Set the query timeout, if it is supported by the driver.
|
public static void quietlyCloseConnection(Connection connection)
connection - the connection to closepublic static long elapsedTimeMs(long start)
start - the start timepublic static void executeSqlAutoCommit(Connection connection, String sql) throws SQLException
connection - the connection to initializesql - the SQL to executeSQLException - throws if the init SQL execution failspublic static void quietlySleep(long millis)
millis - the number of milliseconds to sleeppublic static <T> T createInstance(String className, Class<T> clazz, Object... args)
className - the name of the classto instantiateclazz - a class to cast the result asargs - arguments to a constructorpublic static DataSource initializeDataSource(String dsClassName, DataSource dataSource, Properties dataSourceProperties, String jdbcUrl, String username, String password)
public static int getTransactionIsolation(String transactionIsolationName)
transactionIsolationName - the name of the transaction isolation levelpublic static ThreadPoolExecutor createThreadPoolExecutor(int queueSize, String threadName, ThreadFactory threadFactory, RejectedExecutionHandler policy)
queueSize - the queue sizethreadName - the thread namethreadFactory - an optional ThreadFactorypublic static boolean isJdbc40Compliant(Connection connection) throws SQLException
connection - a Connection to checkSQLException - re-thrown exception from Connection.getNetworkTimeout()public static boolean isJdbc41Compliant(Connection connection) throws SQLException
connection - a Connection to checkSQLException - re-thrown exception from Connection.getNetworkTimeout()public static void setQueryTimeout(Statement statement, int timeoutSec) throws SQLException
statement - a statement to set the query timeout ontimeoutSec - the number of seconds before timeoutSQLException - re-thrown exception from Statement.setQueryTimeout()public static int setNetworkTimeout(Executor executor, Connection connection, long timeoutMs, boolean isUseNetworkTimeout) throws SQLException
isUseNetworkTimeout is true, and return the
pre-existing value of the network timeout.executor - an Executorconnection - the connection to set the network timeout ontimeoutMs - the number of milliseconds before timeoutisUseNetworkTimeout - true if the network timeout should be set, false otherwiseSQLException - thrown if the network timeout cannot be setpublic static void setLoginTimeout(DataSource dataSource, long connectionTimeout, org.slf4j.Logger logger)
dataSource - the DataSourceconnectionTimeout - the timeout in millisecondslogger - a logger to use for a warningCopyright © 2014 Zaxxer.com. All Rights Reserved.