Fix statistics for native query

This commit is contained in:
Andrea Boriero 2021-11-24 09:40:43 +01:00 committed by Andrea Boriero
parent da05181c3a
commit acd78256eb
2 changed files with 15 additions and 7 deletions

View File

@ -68,4 +68,14 @@ public class SqmJdbcExecutionContextAdapter implements ExecutionContext {
public Callback getCallback() { public Callback getCallback() {
return sqmExecutionContext.getCallback(); return sqmExecutionContext.getCallback();
} }
@Override
public boolean hasQueryExecutionToBeAddedToStatistics() {
return true;
}
@Override
public String getQueryIdentifier(String sql) {
return sql;
}
} }

View File

@ -167,17 +167,15 @@ public class StatsTest extends BaseUnitTestCase {
assertEquals( maxTime, sf.getStatistics().getQueryExecutionMaxTime() ); assertEquals( maxTime, sf.getStatistics().getQueryExecutionMaxTime() );
// assertEquals( continents, stats.getQueryExecutionMaxTimeQueryString() ); // assertEquals( continents, stats.getQueryExecutionMaxTimeQueryString() );
Iterator itr = s.createQuery( continents ).list().iterator(); s.createQuery( continents ).list().iterator();
// iterate() should increment the execution count
assertEquals( "unexpected execution count", 2, continentStats.getExecutionCount() ); assertEquals( "unexpected execution count", 2, continentStats.getExecutionCount() );
// but should not effect the cumulative row count assertEquals( "unexpected row count", 2, continentStats.getExecutionRowCount() );
assertEquals( "unexpected row count", results, continentStats.getExecutionRowCount() );
Hibernate.close( itr );
ScrollableResults scrollableResults = s.createQuery( continents ).scroll(); ScrollableResults scrollableResults = s.createQuery( continents ).scroll();
// same deal with scroll()... // same deal with scroll()...
assertEquals( "unexpected execution count", 3, continentStats.getExecutionCount() ); assertEquals( "unexpected execution count", 2, continentStats.getExecutionCount() );
assertEquals( "unexpected row count", results, continentStats.getExecutionRowCount() ); assertEquals( "unexpected row count", 2, continentStats.getExecutionRowCount() );
// scroll through data because SybaseASE15Dialect throws NullPointerException // scroll through data because SybaseASE15Dialect throws NullPointerException
// if data is not read before closing the ResultSet // if data is not read before closing the ResultSet
while ( scrollableResults.next() ) { while ( scrollableResults.next() ) {