- 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
Modifier and TypeFieldDescriptionstatic final boolean
The 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_AGE
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
close
(Connection conn) static void
defaultLogConnection
(Connection conn, Logger logger) Default implementation oflogConnection(java.sql.Connection)
.static void
Default 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 Connection
protected boolean
isClosed
(Connection conn) protected void
logConnection
(Connection conn) protected SQLException
newException
(String message, Throwable cause) protected SQLException
newInterruptedException
(String message, Throwable cause) protected void
printConnectionStats
(Appendable out, boolean isXhtml) protected void
resetConnection
(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, run
Methods 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:
close
in 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:
getConnection
in 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:
getConnection
in 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 level
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
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 level
readOnly
- Theread-only flag
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 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:
getConnectionObject
in classAOPool<Connection,
SQLException, SQLException> - Throws:
SQLException
-
isClosed
- Specified by:
isClosed
in classAOPool<Connection,
SQLException, SQLException> - Throws:
SQLException
-
printConnectionStats
- Overrides:
printConnectionStats
in classAOPool<Connection,
SQLException, SQLException> - Throws:
IOException
-
defaultLogConnection
Default implementation oflogConnection(java.sql.Connection)
.- Throws:
SQLException
- See Also:
-
logConnection
- Overrides:
logConnection
in 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:
resetConnection
in classAOPool<Connection,
SQLException, SQLException> - Throws:
SQLException
- See Also:
-
newException
- Specified by:
newException
in classAOPool<Connection,
SQLException, SQLException>
-
newInterruptedException
- Specified by:
newInterruptedException
in classAOPool<Connection,
SQLException, SQLException>
-
toString
-