Fix errors after merge with main

This commit is contained in:
Andrea Boriero 2021-05-31 15:57:06 +02:00
parent 451568f322
commit d413bdf2e9
6 changed files with 155 additions and 75 deletions

View File

@ -202,10 +202,6 @@ public class QueryStatisticsImpl implements QueryStatistics {
planCacheHitCount.increment();
}
void incrementPlanCacheMissCount() {
planCacheMissCount.increment();
}
public String toString() {
return "QueryStatistics"
+ "[query=" + query

View File

@ -805,20 +805,11 @@ public class StatisticsImpl implements StatisticsImplementor, Service, Manageabl
}
@Override
public void queryPlanCacheHit(String query) {
public void queryPlanCacheHit(String hql) {
queryPlanCacheHitCount.increment();
if ( query != null ) {
getQueryStatistics( query ).incrementPlanCacheHitCount();
}
}
@Override
public void queryPlanCacheMiss(String query) {
queryPlanCacheMissCount.increment();
if ( query != null ) {
getQueryStatistics( query ).incrementPlanCacheMissCount();
if ( hql != null ) {
getQueryStatistics( hql ).incrementPlanCacheHitCount();
}
}

View File

@ -251,18 +251,9 @@ public interface StatisticsImplementor extends Statistics, Service {
/**
* Callback indicating a get from the query plan cache resulted in a hit.
*
* @param query The query
* @param hql The query
*/
default void queryPlanCacheHit(String query) {
//For backward compatibility
}
/**
* Callback indicating a get from the query plan cache resulted in a miss.
*
* @param query The query
*/
default void queryPlanCacheMiss(String query) {
default void queryPlanCacheHit(String hql) {
//For backward compatibility
}

View File

@ -168,54 +168,6 @@ public class QueryPlanCacheStatisticsTest {
} );
}
@Test
@TestForIssue( jiraKey = "HHH-14632" )
public void testCreateNativeQueryHitCount(SessionFactoryScope scope) {
statistics.clear();
scope.inTransaction( entityManager -> {
List<Employee> employees = entityManager.createNativeQuery(
"select * from employee e", Employee.class )
.getResultList();
assertEquals( 5, employees.size() );
//First time, we get a cache miss, so the query is compiled
assertEquals( 1, statistics.getQueryPlanCacheMissCount() );
//The hit count should be 0 as we don't need to go to the cache after we already compiled the query
assertEquals( 0, statistics.getQueryPlanCacheHitCount() );
} );
scope.inTransaction( entityManager -> {
List<Employee> employees = entityManager.createNativeQuery(
"select * from employee e", Employee.class )
.getResultList();
assertEquals( 5, employees.size() );
//The miss count is still 1, as now we got the query plan from the cache
assertEquals( 1, statistics.getQueryPlanCacheMissCount() );
//And the cache hit count increases.
assertEquals( 1, statistics.getQueryPlanCacheHitCount() );
} );
scope.inTransaction( entityManager -> {
List<Employee> employees = entityManager.createNativeQuery(
"select * from employee e", Employee.class )
.getResultList();
assertEquals( 5, employees.size() );
//The miss count is still 1, as now we got the query plan from the cache
assertEquals( 1, statistics.getQueryPlanCacheMissCount() );
//And the cache hit count increases.
assertEquals( 2, statistics.getQueryPlanCacheHitCount() );
} );
}
@Test
@TestForIssue( jiraKey = "HHH-13077" )
public void testCreateNamedQueryHitCount(SessionFactoryScope scope) {

View File

@ -0,0 +1,144 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.stat.internal;
import java.util.List;
import java.util.Map;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Environment;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.stat.Statistics;
import org.hibernate.testing.TestForIssue;
import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
/**
* @author Gail Badner
*/
@TestForIssue(jiraKey = "HHH-12855")
public class QueryPlanCacheStatisticsTest extends BaseEntityManagerFunctionalTestCase {
private Statistics statistics;
@Override
public Class[] getAnnotatedClasses() {
return new Class[] {
Employee.class
};
}
@Override
protected void addConfigOptions(Map options) {
options.put( Environment.GENERATE_STATISTICS, "true" );
}
@Override
protected void afterEntityManagerFactoryBuilt() {
SessionFactory sessionFactory = entityManagerFactory().unwrap( SessionFactory.class );
statistics = sessionFactory.getStatistics();
doInJPA( this::entityManagerFactory, entityManager -> {
for ( long i = 1; i <= 5; i++ ) {
if ( i % 3 == 0 ) {
entityManager.flush();
}
Employee employee = new Employee();
employee.setName( String.format( "Employee: %d", i ) );
entityManager.persist( employee );
}
} );
}
@Test
@TestForIssue( jiraKey = "HHH-14632" )
public void testCreateNativeQueryHitCount() {
statistics.clear();
doInJPA( this::entityManagerFactory, entityManager -> {
List<Employee> employees = entityManager.createNativeQuery(
"select * from employee e", Employee.class )
.getResultList();
assertEquals( 5, employees.size() );
//First time, we get a cache miss, so the query is compiled
assertEquals( 1, statistics.getQueryPlanCacheMissCount() );
//The hit count should be 0 as we don't need to go to the cache after we already compiled the query
assertEquals( 0, statistics.getQueryPlanCacheHitCount() );
} );
doInJPA( this::entityManagerFactory, entityManager -> {
List<Employee> employees = entityManager.createNativeQuery(
"select * from employee e", Employee.class )
.getResultList();
assertEquals( 5, employees.size() );
//The miss count is still 1, as now we got the query plan from the cache
assertEquals( 1, statistics.getQueryPlanCacheMissCount() );
//And the cache hit count increases.
assertEquals( 1, statistics.getQueryPlanCacheHitCount() );
} );
doInJPA( this::entityManagerFactory, entityManager -> {
List<Employee> employees = entityManager.createNativeQuery(
"select * from employee e", Employee.class )
.getResultList();
assertEquals( 5, employees.size() );
//The miss count is still 1, as now we got the query plan from the cache
assertEquals( 1, statistics.getQueryPlanCacheMissCount() );
//And the cache hit count increases.
assertEquals( 2, statistics.getQueryPlanCacheHitCount() );
} );
}
@Entity(name = "Employee")
@Table(name = "employee")
@NamedQuery(
name = "find_employee_by_name",
query = "select e from Employee e where e.name = :name"
)
public static class Employee {
@Id
@GeneratedValue
private Long id;
private String name;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}

View File

@ -42,6 +42,12 @@ logger.type-basic-binder.level=trace
logger.type-basic-extractor.name=org.hibernate.type.descriptor.jdbc.BasicExtractor
logger.type-basic-extractor.level=trace
logger.jdbc-bind.name=org.hibernate.orm.jdbc.bind
logger.jdbc-bind.level=trace
logger.jdbc-extract.name=org.hibernate.orm.jdbc.extract
logger.jdbc-extract.level=trace
logger.hql-internal-ast.name=org.hibernate.hql.internal.ast
logger.hql-internal-ast.level=debug