@ProfileConnection - quick-perf/doc GitHub Wiki

The ProfileConnection annotation profiles the database connection.

The annotation profiles the calls to the java.sql.Connection methods and the calls to the javax.sql.DataSource.getConnection() method.

See also @ExpectNoConnectionLeak.

🔧 Elements

Name Type Meaning Default value
level Level Allows defining the profiling level. The default value is INFO. With a TRACE level, the annotation profiles more java.sql.Connection methods: Connection.createStatement(), Connection.createStatement(int, int), Connection.createStatement(int, int, int), Connection.prepareStatement(String), Connection.prepareStatement(String, int[]), Connection.prepareStatement(String, String[]), Connection.prepareStatement(String, int), Connection.prepareStatement(String, int, int), Connection.prepareStatement(String, int, int, int), Connection.prepareCall(String), Connection.prepareCall(String, int, int), Connection.prepareCall(String, int, int, int), Connection.createBlb(), Connection.createClob(), Connection.createNClob(), Connection.createSQLXML(), Connection.createArrayOf(String, Object[]), Connection.createStruct(String, Object[]) Level.INFO
displayStackTrace boolean Allows displaying the stack traces of the profiled java.sql.Connection methods and the profiled javax.sql.DataSource.getConnection() method. false
filterStackTrace boolean If the stack trace display is enabled, the filterStackTrace element allows removing elements from the stack traces coming from QuickPerf, JUnit 4, JUnit 5, and TestNG. true
stackDepth short If the stack trace display is enabled, the stackDepth element allows configuring the number of elements to display on the stack traces. With a -1 value, the annotation does not limit the stack depth. -1
beforeAndAfterTestMethodExecution boolean Allows profiling the java.sql.Connection before and after the test method execution. The default behavior is not to profile the database connection before and after the test method execution. false

🔎 Example

    @Test
    @ProfileConnection
    public void code() {
    ...
    }

On the console:

connection 657628458 - javax.sql.DataSource.getConnection()
connection 657628458 - java.sql.Connection.close()

🔎 Hibernate example with stack trace display

    @Test
    @ProfileConnection(displayStackTrace = true)
    public void example_with_hibernate_application() {
    ...
    }
connection 67985650 - javax.sql.DataSource.getConnection()
	org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122)
	org.hibernate.internal.NonContextualJdbcConnectionAccess.obtainConnection(NonContextualJdbcConnectionAccess.java:35)
	org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:106)
	org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getPhysicalConnection(LogicalConnectionManagedImpl.java:136)
	org.hibernate.internal.SessionImpl.connection(SessionImpl.java:544)
	SqlTestBase.getConnection(SqlTestBase.java:71)
	ProfileConnectionTest$ProfileConnectionClass.test(ProfileConnectionTest.java:60)
connection 67985650 - java.sql.Connection.prepareStatement(String sql) [sql: select isbn from Book]
	ProfileConnectionTest$ProfileConnectionClass.test(ProfileConnectionTest.java:61)
connection 67985650 - java.sql.Connection.close()
	ProfileConnectionTest$ProfileConnectionClass.test(ProfileConnectionTest.java:63)

🔎 Spring Boot example

    @Test
    @ProfileConnection(displayStackTrace = true)
    public void example_with_spring_boot_application() {
    ...
    }

On the console:

connection 1920110923 - javax.sql.DataSource.getConnection()
	com.zaxxer.hikari.HikariDataSource$$EnhancerBySpringCGLIB$$a2cb4f00.getConnection(<generated>)
	org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122)
	org.hibernate.internal.NonContextualJdbcConnectionAccess.obtainConnection(NonContextualJdbcConnectionAccess.java:35)
	org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:106)
	org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getPhysicalConnection(LogicalConnectionManagedImpl.java:136)
	org.hibernate.internal.SessionImpl.connection(SessionImpl.java:541)
	java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
	java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	java.base/java.lang.reflect.Method.invoke(Method.java:567)
	org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:246)
	org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:230)
	org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle.doGetConnection(HibernateJpaDialect.java:424)
	org.springframework.orm.jpa.vendor.HibernateJpaDialect.beginTransaction(HibernateJpaDialect.java:173)
	org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:401)
	org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:378)
	org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:474)
	org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:289)
	org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
	org.quickperf.spring.springboottest.service.PlayerService$$EnhancerBySpringCGLIB$$4c424778.findPlayersWithTeamName(<generated>)
	org.quickperf.spring.springboottest.service.SpringDbConnectionProfiling.should_find_all_players_with_team_name(SpringDbConnectionProfiling.java:49)
connection 1920110923 - java.sql.Connection.setReadOnly(boolean readOnly) [readOnly: true]
	org.springframework.jdbc.datasource.DataSourceUtils.prepareConnectionForTransaction(DataSourceUtils.java:184)
	org.springframework.orm.jpa.vendor.HibernateJpaDialect.beginTransaction(HibernateJpaDialect.java:174)
	org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:401)
	org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:378)
	org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:474)
	org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:289)
	org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
	org.quickperf.spring.springboottest.service.PlayerService$$EnhancerBySpringCGLIB$$4c424778.findPlayersWithTeamName(<generated>)
	org.quickperf.spring.springboottest.service.SpringDbConnectionProfiling.should_find_all_players_with_team_name(SpringDbConnectionProfiling.java:49)
connection 1920110923 - java.sql.Connection.setAutoCommit(boolean autoCommit) [autoCommit: false]
	org.hibernate.resource.jdbc.internal.AbstractLogicalConnectionImplementor.begin(AbstractLogicalConnectionImplementor.java:67)
	org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.begin(LogicalConnectionManagedImpl.java:263)
	org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.begin(JdbcResourceLocalTransactionCoordinatorImpl.java:236)
	org.hibernate.engine.transaction.internal.TransactionImpl.begin(TransactionImpl.java:80)
	org.springframework.orm.jpa.vendor.HibernateJpaDialect.beginTransaction(HibernateJpaDialect.java:183)
	org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:401)
	org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:378)
	org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:474)
	org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:289)
	org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
	org.quickperf.spring.springboottest.service.PlayerService$$EnhancerBySpringCGLIB$$4c424778.findPlayersWithTeamName(<generated>)
	org.quickperf.spring.springboottest.service.SpringDbConnectionProfiling.should_find_all_players_with_team_name(SpringDbConnectionProfiling.java:49)
connection 1920110923 - java.sql.Connection.commit() [isolation: transaction_read_committed]
	org.hibernate.resource.jdbc.internal.AbstractLogicalConnectionImplementor.commit(AbstractLogicalConnectionImplementor.java:81)
	org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:272)
	org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:98)
	org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:532)
	org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:746)
	org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:714)
	org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:533)
	org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:304)
	org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
	org.quickperf.spring.springboottest.service.PlayerService$$EnhancerBySpringCGLIB$$4c424778.findPlayersWithTeamName(<generated>)
	org.quickperf.spring.springboottest.service.SpringDbConnectionProfiling.should_find_all_players_with_team_name(SpringDbConnectionProfiling.java:49)
connection 1920110923 - java.sql.Connection.setAutoCommit(boolean autoCommit) [autoCommit: true]
	org.hibernate.resource.jdbc.internal.AbstractLogicalConnectionImplementor.resetConnection(AbstractLogicalConnectionImplementor.java:101)
	org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.afterCompletion(LogicalConnectionManagedImpl.java:268)
	org.hibernate.resource.jdbc.internal.AbstractLogicalConnectionImplementor.commit(AbstractLogicalConnectionImplementor.java:90)
	org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:272)
	org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:98)
	org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:532)
	org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:746)
	org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:714)
	org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:533)
	org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:304)
	org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
	org.quickperf.spring.springboottest.service.PlayerService$$EnhancerBySpringCGLIB$$4c424778.findPlayersWithTeamName(<generated>)
	org.quickperf.spring.springboottest.service.SpringDbConnectionProfiling.should_find_all_players_with_team_name(SpringDbConnectionProfiling.java:49)
connection 1920110923 - java.sql.Connection.setReadOnly(boolean readOnly) [readOnly: false]
	org.springframework.jdbc.datasource.DataSourceUtils.resetConnectionAfterTransaction(DataSourceUtils.java:241)
	org.springframework.orm.jpa.vendor.HibernateJpaDialect$SessionTransactionData.resetSessionState(HibernateJpaDialect.java:394)
	org.springframework.orm.jpa.vendor.HibernateJpaDialect.cleanupTransaction(HibernateJpaDialect.java:234)
	org.springframework.orm.jpa.JpaTransactionManager.doCleanupAfterCompletion(JpaTransactionManager.java:612)
	org.springframework.transaction.support.AbstractPlatformTransactionManager.cleanupAfterCompletion(AbstractPlatformTransactionManager.java:1007)
	org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:793)
	org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:714)
	org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:533)
	org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:304)
	org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
	org.quickperf.spring.springboottest.service.PlayerService$$EnhancerBySpringCGLIB$$4c424778.findPlayersWithTeamName(<generated>)
	org.quickperf.spring.springboottest.service.SpringDbConnectionProfiling.should_find_all_players_with_team_name(SpringDbConnectionProfiling.java:49)
connection 1920110923 - java.sql.Connection.close()
	org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.closeConnection(DatasourceConnectionProviderImpl.java:127)
	org.hibernate.internal.NonContextualJdbcConnectionAccess.releaseConnection(NonContextualJdbcConnectionAccess.java:46)
	org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.releaseConnection(LogicalConnectionManagedImpl.java:196)
	org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.close(LogicalConnectionManagedImpl.java:239)
	org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.close(JdbcCoordinatorImpl.java:189)
	org.hibernate.internal.AbstractSharedSessionContract.close(AbstractSharedSessionContract.java:324)
	org.hibernate.internal.SessionImpl.closeWithoutOpenChecks(SessionImpl.java:432)
	org.hibernate.internal.SessionImpl.close(SessionImpl.java:418)
	org.springframework.orm.jpa.EntityManagerFactoryUtils.closeEntityManager(EntityManagerFactoryUtils.java:426)
	org.springframework.orm.jpa.JpaTransactionManager.doCleanupAfterCompletion(JpaTransactionManager.java:620)
	org.springframework.transaction.support.AbstractPlatformTransactionManager.cleanupAfterCompletion(AbstractPlatformTransactionManager.java:1007)
	org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:793)
	org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:714)
	org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:533)
	org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:304)
	org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
	org.quickperf.spring.springboottest.service.PlayerService$$EnhancerBySpringCGLIB$$4c424778.findPlayersWithTeamName(<generated>)
      org.quickperf.spring.springboottest.service.SpringDbConnectionProfiling.should_find_all_players_with_team_name(SpringDbConnectionProfiling.java:49)

⚠️ **GitHub.com Fallback** ⚠️