- All Implemented Interfaces:
Runnable
- Author:
- AO Industries, Inc.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanThe read-only state of connections while idle in the pool.Fields inherited from class com.aoapps.hodgepodge.io.AOPool
DEFAULT_CONNECT_TIMEOUT, DEFAULT_DELAY_TIME, DEFAULT_MAX_CONNECTION_AGE, DEFAULT_MAX_IDLE_TIME, DEFAULT_SOCKET_SO_LINGER, logger, UNLIMITED_MAX_CONNECTION_AGEFields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidclose(Connection conn) static voiddefaultLogConnection(Connection conn, Logger logger) Default implementation oflogConnection(java.sql.Connection).static voidDefault implementation ofresetConnection(java.sql.Connection).Gets a read/write connection to the database with a transaction level ofConnections.DEFAULT_TRANSACTION_ISOLATION, warning when a connection is already used by this thread.getConnection(boolean readOnly) Gets a connection to the database with a transaction level ofConnections.DEFAULT_TRANSACTION_ISOLATION, warning when a connection is already used by this thread.getConnection(int maxConnections) Gets a read/write connection to the database with a transaction level ofConnections.DEFAULT_TRANSACTION_ISOLATION.getConnection(int isolationLevel, boolean readOnly) Gets a connection to the database, warning when a connection is already used by this thread.getConnection(int isolationLevel, boolean readOnly, int maxConnections) Gets a connection to the database.protected Connectionprotected booleanisClosed(Connection conn) protected voidlogConnection(Connection conn) protected SQLExceptionnewException(String message, Throwable cause) protected SQLExceptionnewInterruptedException(String message, Throwable cause) protected voidprintConnectionStats(Appendable out, boolean isXhtml) protected voidresetConnection(Connection conn) toString()Methods inherited from class com.aoapps.hodgepodge.io.AOPool
close, getConcurrency, getConnectionCount, getConnects, getLogger, getMaxConcurrency, getMaxConnectionAge, getPoolSize, getTotalTime, getTransactionCount, printStatisticsHtml, printStatisticsHTML, printStatisticsHTML, release, releaseConnection, runMethods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, yield
-
Field Details
-
IDLE_READ_ONLY
public static final boolean IDLE_READ_ONLYThe read-only state of connections while idle in the pool.- See Also:
-
-
Constructor Details
-
Method Details
-
close
If the connection not already closed, and is not auto-commit, the connection will be rolled back and set back to auto-commit before closing.
- Specified by:
closein classAOPool<Connection,SQLException, SQLException> - Throws:
SQLException
-
getConnection
Gets a read/write connection to the database with a transaction level ofConnections.DEFAULT_TRANSACTION_ISOLATION, warning when a connection is already used by this thread.The connection will be in auto-commit mode, as configured by
resetConnection(java.sql.Connection)If all the connections in the pool are busy and the pool is at capacity, waits until a connection becomes available.
The connection will be a
ConnectionTracker, which may be unwrapped viaWrapper.unwrap(java.lang.Class). The connection tracking is used to close/free all objects before returning the connection to the pool.- Overrides:
getConnectionin classAOPool<Connection,SQLException, SQLException> - Returns:
- The read/write connection to the database
- Throws:
SQLException- when an error occurs, or when a thread attempts to allocate more than half the pool- See Also:
-
getConnection
Gets a read/write connection to the database with a transaction level ofConnections.DEFAULT_TRANSACTION_ISOLATION.The connection will be in auto-commit mode, as configured by
resetConnection(java.sql.Connection)If all the connections in the pool are busy and the pool is at capacity, waits until a connection becomes available.
The connection will be a
ConnectionTracker, which may be unwrapped viaWrapper.unwrap(java.lang.Class). The connection tracking is used to close/free all objects before returning the connection to the pool.- Overrides:
getConnectionin classAOPool<Connection,SQLException, SQLException> - Parameters:
maxConnections- The maximum number of connections expected to be used by the current thread. This should normally be one to avoid potential deadlock.The connection will continue to be considered used by the allocating thread until released (via
Connection.close(), even if the connection is shared by another thread.- Returns:
- The read/write connection to the database
- Throws:
SQLException- when an error occurs, or when a thread attempts to allocate more than half the pool- See Also:
-
getConnection
Gets a connection to the database with a transaction level ofConnections.DEFAULT_TRANSACTION_ISOLATION, warning when a connection is already used by this thread.The connection will be in auto-commit mode, as configured by
resetConnection(java.sql.Connection)If all the connections in the pool are busy and the pool is at capacity, waits until a connection becomes available.
The connection will be a
ConnectionTracker, which may be unwrapped viaWrapper.unwrap(java.lang.Class). The connection tracking is used to close/free all objects before returning the connection to the pool.- Parameters:
readOnly- Theread-only flag- Returns:
- The connection to the database
- Throws:
SQLException- when an error occurs, or when a thread attempts to allocate more than half the pool- See Also:
-
getConnection
Gets a connection to the database, warning when a connection is already used by this thread.The connection will be in auto-commit mode, as configured by
resetConnection(java.sql.Connection)If all the connections in the pool are busy and the pool is at capacity, waits until a connection becomes available.
The connection will be a
ConnectionTracker, which may be unwrapped viaWrapper.unwrap(java.lang.Class). The connection tracking is used to close/free all objects before returning the connection to the pool.- Parameters:
isolationLevel- Thetransaction isolation levelreadOnly- Theread-only flag- Returns:
- The connection to the database
- Throws:
SQLException- when an error occurs, or when a thread attempts to allocate more than half the pool- See Also:
-
getConnection
public Connection getConnection(int isolationLevel, boolean readOnly, int maxConnections) throws SQLException Gets a connection to the database.The connection will be in auto-commit mode, as configured by
resetConnection(java.sql.Connection)If all the connections in the pool are busy and the pool is at capacity, waits until a connection becomes available.
The connection will be a
ConnectionTracker, which may be unwrapped viaWrapper.unwrap(java.lang.Class). The connection tracking is used to close/free all objects before returning the connection to the pool.- Parameters:
isolationLevel- Thetransaction isolation levelreadOnly- Theread-only flagmaxConnections- The maximum number of connections expected to be used by the current thread. This should normally be one to avoid potential deadlock.The connection will continue to be considered used by the allocating thread until released (via
Connection.close(), even if the connection is shared by another thread.- Returns:
- The connection to the database
- Throws:
SQLException- when an error occurs, or when a thread attempts to allocate more than half the pool- See Also:
-
getConnectionObject
- Specified by:
getConnectionObjectin classAOPool<Connection,SQLException, SQLException> - Throws:
SQLException
-
isClosed
- Specified by:
isClosedin classAOPool<Connection,SQLException, SQLException> - Throws:
SQLException
-
printConnectionStats
- Overrides:
printConnectionStatsin classAOPool<Connection,SQLException, SQLException> - Throws:
IOException
-
defaultLogConnection
Default implementation oflogConnection(java.sql.Connection).- Throws:
SQLException- See Also:
-
logConnection
- Overrides:
logConnectionin classAOPool<Connection,SQLException, SQLException> - Throws:
SQLException- See Also:
-
defaultResetConnection
Default implementation ofresetConnection(java.sql.Connection).- Warnings are cleared
- Any transaction in-progress is rolled-back
- Auto-commit is enabled
- Read-only state is set to
IDLE_READ_ONLY - Transaction isolation level set to
Connections.DEFAULT_TRANSACTION_ISOLATION
- Throws:
SQLException- See Also:
-
resetConnection
- Specified by:
resetConnectionin classAOPool<Connection,SQLException, SQLException> - Throws:
SQLException- See Also:
-
newException
- Specified by:
newExceptionin classAOPool<Connection,SQLException, SQLException>
-
newInterruptedException
- Specified by:
newInterruptedExceptionin classAOPool<Connection,SQLException, SQLException>
-
toString
-
