public final class PoolUtilities
extends java.lang.Object
| Constructor and Description |
|---|
PoolUtilities() |
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
createInstance(java.lang.String className,
java.lang.Class<T> clazz,
java.lang.Object... args)
Create and instance of the specified class using the constructor matching the specified
arguments.
|
static java.util.concurrent.ThreadPoolExecutor |
createThreadPoolExecutor(int queueSize,
java.lang.String threadName,
java.util.concurrent.ThreadFactory threadFactory,
java.util.concurrent.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 |
executeSql(java.sql.Connection connection,
java.lang.String sql,
boolean isAutoCommit)
Execute the user-specified init SQL.
|
static int |
getTransactionIsolation(java.lang.String transactionIsolationName)
Get the int value of a transaction isolation level by name.
|
static javax.sql.DataSource |
initializeDataSource(java.lang.String dsClassName,
javax.sql.DataSource dataSource,
java.util.Properties dataSourceProperties,
java.lang.String jdbcUrl,
java.lang.String username,
java.lang.String password)
Create/initialize the underlying DataSource.
|
static boolean |
isJdbc40Compliant(java.sql.Connection connection)
Return true if the driver appears to be JDBC 4.0 compliant.
|
static void |
quietlyCloseConnection(java.sql.Connection connection)
Close connection and eat any exception.
|
static void |
quietlySleep(long millis)
Sleep and transform an InterruptedException into a RuntimeException.
|
static void |
setLoginTimeout(javax.sql.DataSource dataSource,
long connectionTimeout,
org.slf4j.Logger logger)
Set the loginTimeout on the specified DataSource.
|
static int |
setNetworkTimeout(java.util.concurrent.Executor executor,
java.sql.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(java.sql.Statement statement,
int timeoutSec)
Set the query timeout, if it is supported by the driver.
|
static void |
setupConnection(java.sql.Connection connection,
boolean isAutoCommit,
boolean isReadOnly,
int transactionIsolation,
java.lang.String catalog)
Setup a connection intial state.
|
public static void quietlyCloseConnection(java.sql.Connection connection)
connection - the connection to closepublic static long elapsedTimeMs(long start)
start - the start timepublic static void executeSql(java.sql.Connection connection,
java.lang.String sql,
boolean isAutoCommit)
throws java.sql.SQLException
connection - the connection to initializesql - the SQL to executejava.sql.SQLException - throws if the init SQL execution failspublic static void quietlySleep(long millis)
millis - the number of milliseconds to sleeppublic static <T> T createInstance(java.lang.String className,
java.lang.Class<T> clazz,
java.lang.Object... args)
className - the name of the classto instantiateclazz - a class to cast the result asargs - arguments to a constructorpublic static javax.sql.DataSource initializeDataSource(java.lang.String dsClassName,
javax.sql.DataSource dataSource,
java.util.Properties dataSourceProperties,
java.lang.String jdbcUrl,
java.lang.String username,
java.lang.String password)
public static int getTransactionIsolation(java.lang.String transactionIsolationName)
transactionIsolationName - the name of the transaction isolation levelpublic static void setupConnection(java.sql.Connection connection,
boolean isAutoCommit,
boolean isReadOnly,
int transactionIsolation,
java.lang.String catalog)
throws java.sql.SQLException
connection - a ConnectionisAutoCommit - auto-commit stateisReadOnly - read-only statetransactionIsolation - transaction isolationcatalog - default catalogjava.sql.SQLException - thrown from driverpublic static java.util.concurrent.ThreadPoolExecutor createThreadPoolExecutor(int queueSize,
java.lang.String threadName,
java.util.concurrent.ThreadFactory threadFactory,
java.util.concurrent.RejectedExecutionHandler policy)
queueSize - the queue sizethreadName - the thread namethreadFactory - an optional ThreadFactorypublic static boolean isJdbc40Compliant(java.sql.Connection connection)
throws java.sql.SQLException
connection - a Connection to checkjava.sql.SQLException - re-thrown exception from Connection.getNetworkTimeout()public static void setQueryTimeout(java.sql.Statement statement,
int timeoutSec)
throws java.sql.SQLException
statement - a statement to set the query timeout ontimeoutSec - the number of seconds before timeoutjava.sql.SQLException - re-thrown exception from Statement.setQueryTimeout()public static int setNetworkTimeout(java.util.concurrent.Executor executor,
java.sql.Connection connection,
long timeoutMs,
boolean isUseNetworkTimeout)
throws java.sql.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 otherwisejava.sql.SQLException - thrown if the network timeout cannot be setpublic static void setLoginTimeout(javax.sql.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.