Package org.hibernate.testing.orm.jdbc
Class PreparedStatementSpyConnectionProvider
- java.lang.Object
-
- org.hibernate.testing.jdbc.ConnectionProviderDelegate
-
- org.hibernate.testing.orm.jdbc.PreparedStatementSpyConnectionProvider
-
- All Implemented Interfaces:
Serializable
,ConnectionProvider
,Service
,Configurable
,ServiceRegistryAwareService
,Stoppable
,Wrapped
public class PreparedStatementSpyConnectionProvider extends ConnectionProviderDelegate
ThisConnectionProvider
extends any other ConnectionProvider that would be used by default taken the current configuration properties, and it intercept the underlyingPreparedStatement
method calls.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description JdbcSpies.SpyContext
spyContext
-
Constructor Summary
Constructors Constructor Description PreparedStatementSpyConnectionProvider()
PreparedStatementSpyConnectionProvider(boolean forceSupportsAggressiveRelease)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Connection
actualConnection()
void
clear()
Clears the recorded PreparedStatements and reset the associated Mocks.void
closeConnection(Connection connection)
Release a connection from Hibernate use.List<Connection>
getAcquiredConnections()
Get a list of current acquired Connections.Connection
getConnection()
Obtains a connection for Hibernate use according to the underlying strategy of this provider.List<String>
getExecuteStatements()
Get the SQL statements that were executed since the last clear operation.List<String>
getExecuteUpdateStatements()
Get the SQL update statements that were executed since the last clear operation.List<String>
getPreparedSQLStatements()
Get the PreparedStatements SQL statements.PreparedStatement
getPreparedStatement(String sql)
Get one and only one PreparedStatement associated to the given SQL statement.List<PreparedStatement>
getPreparedStatements()
Get the PreparedStatements that were executed since the last clear operation.List<PreparedStatement>
getPreparedStatements(String sql)
Get the PreparedStatements that are associated to the following SQL statement.Map<PreparedStatement,String>
getPreparedStatementsAndSql()
List<Connection>
getReleasedConnections()
Get a list of current released Connections.void
stop()
Stop phase notification-
Methods inherited from class org.hibernate.testing.jdbc.ConnectionProviderDelegate
configure, getConnectionProvider, getDatabaseConnectionInfo, injectServices, isUnwrappableAs, setConnectionProvider, supportsAggressiveRelease, unwrap
-
-
-
-
Field Detail
-
spyContext
public final JdbcSpies.SpyContext spyContext
-
-
Method Detail
-
actualConnection
protected Connection actualConnection() throws SQLException
- Throws:
SQLException
-
getConnection
public Connection getConnection() throws SQLException
Description copied from interface:ConnectionProvider
Obtains a connection for Hibernate use according to the underlying strategy of this provider.- Specified by:
getConnection
in interfaceConnectionProvider
- Overrides:
getConnection
in classConnectionProviderDelegate
- Returns:
- The obtained JDBC connection
- Throws:
SQLException
- Indicates a problem opening a connection
-
closeConnection
public void closeConnection(Connection connection) throws SQLException
Description copied from interface:ConnectionProvider
Release a connection from Hibernate use.- Specified by:
closeConnection
in interfaceConnectionProvider
- Overrides:
closeConnection
in classConnectionProviderDelegate
- Parameters:
connection
- The JDBC connection to release- Throws:
SQLException
- Indicates a problem closing the connection
-
stop
public void stop()
Description copied from interface:Stoppable
Stop phase notification- Specified by:
stop
in interfaceStoppable
- Overrides:
stop
in classConnectionProviderDelegate
-
clear
public void clear()
Clears the recorded PreparedStatements and reset the associated Mocks.
-
getPreparedStatement
public PreparedStatement getPreparedStatement(String sql)
Get one and only one PreparedStatement associated to the given SQL statement.- Parameters:
sql
- SQL statement.- Returns:
- matching PreparedStatement.
- Throws:
IllegalArgumentException
- If there is no matching PreparedStatement or multiple instances, an exception is being thrown.
-
getPreparedStatements
public List<PreparedStatement> getPreparedStatements(String sql)
Get the PreparedStatements that are associated to the following SQL statement.- Parameters:
sql
- SQL statement.- Returns:
- list of recorded PreparedStatements matching the SQL statement.
-
getPreparedStatements
public List<PreparedStatement> getPreparedStatements()
Get the PreparedStatements that were executed since the last clear operation.- Returns:
- list of recorded PreparedStatements.
-
getPreparedStatementsAndSql
public Map<PreparedStatement,String> getPreparedStatementsAndSql()
- Returns:
- the PreparedStatements that were executed since the last clear operation, along with each statement's corresponding SQL.
-
getPreparedSQLStatements
public List<String> getPreparedSQLStatements()
Get the PreparedStatements SQL statements.- Returns:
- list of recorded PreparedStatements SQL statements.
-
getExecuteStatements
public List<String> getExecuteStatements()
Get the SQL statements that were executed since the last clear operation.- Returns:
- list of recorded update statements.
-
getExecuteUpdateStatements
public List<String> getExecuteUpdateStatements()
Get the SQL update statements that were executed since the last clear operation.- Returns:
- list of recorded update statements.
-
getAcquiredConnections
public List<Connection> getAcquiredConnections()
Get a list of current acquired Connections.- Returns:
- list of current acquired Connections
-
getReleasedConnections
public List<Connection> getReleasedConnections()
Get a list of current released Connections.- Returns:
- list of current released Connections
-
-