Skip to content

Commit d413bdf

Browse files
committed
Fix errors after merge with main
1 parent 451568f commit d413bdf

File tree

6 files changed

+155
-75
lines changed

6 files changed

+155
-75
lines changed

hibernate-core/src/main/java/org/hibernate/stat/internal/QueryStatisticsImpl.java

-4
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,6 @@ void incrementPlanCacheHitCount() {
202202
planCacheHitCount.increment();
203203
}
204204

205-
void incrementPlanCacheMissCount() {
206-
planCacheMissCount.increment();
207-
}
208-
209205
public String toString() {
210206
return "QueryStatistics"
211207
+ "[query=" + query

hibernate-core/src/main/java/org/hibernate/stat/internal/StatisticsImpl.java

+3-12
Original file line numberDiff line numberDiff line change
@@ -805,20 +805,11 @@ public void queryCompiled(String hql, long microseconds) {
805805
}
806806

807807
@Override
808-
public void queryPlanCacheHit(String query) {
808+
public void queryPlanCacheHit(String hql) {
809809
queryPlanCacheHitCount.increment();
810810

811-
if ( query != null ) {
812-
getQueryStatistics( query ).incrementPlanCacheHitCount();
813-
}
814-
}
815-
816-
@Override
817-
public void queryPlanCacheMiss(String query) {
818-
queryPlanCacheMissCount.increment();
819-
820-
if ( query != null ) {
821-
getQueryStatistics( query ).incrementPlanCacheMissCount();
811+
if ( hql != null ) {
812+
getQueryStatistics( hql ).incrementPlanCacheHitCount();
822813
}
823814
}
824815

hibernate-core/src/main/java/org/hibernate/stat/spi/StatisticsImplementor.java

+2-11
Original file line numberDiff line numberDiff line change
@@ -251,18 +251,9 @@ public interface StatisticsImplementor extends Statistics, Service {
251251
/**
252252
* Callback indicating a get from the query plan cache resulted in a hit.
253253
*
254-
* @param query The query
255-
*/
256-
default void queryPlanCacheHit(String query) {
257-
//For backward compatibility
258-
}
259-
260-
/**
261-
* Callback indicating a get from the query plan cache resulted in a miss.
262-
*
263-
* @param query The query
254+
* @param hql The query
264255
*/
265-
default void queryPlanCacheMiss(String query) {
256+
default void queryPlanCacheHit(String hql) {
266257
//For backward compatibility
267258
}
268259

hibernate-core/src/test/java/org/hibernate/orm/test/stat/internal/QueryPlanCacheStatisticsTest.java

-48
Original file line numberDiff line numberDiff line change
@@ -168,54 +168,6 @@ public void testCreateQueryHitCount(SessionFactoryScope scope) {
168168
} );
169169
}
170170

171-
@Test
172-
@TestForIssue( jiraKey = "HHH-14632" )
173-
public void testCreateNativeQueryHitCount(SessionFactoryScope scope) {
174-
statistics.clear();
175-
176-
scope.inTransaction( entityManager -> {
177-
178-
List<Employee> employees = entityManager.createNativeQuery(
179-
"select * from employee e", Employee.class )
180-
.getResultList();
181-
182-
assertEquals( 5, employees.size() );
183-
184-
//First time, we get a cache miss, so the query is compiled
185-
assertEquals( 1, statistics.getQueryPlanCacheMissCount() );
186-
//The hit count should be 0 as we don't need to go to the cache after we already compiled the query
187-
assertEquals( 0, statistics.getQueryPlanCacheHitCount() );
188-
} );
189-
190-
scope.inTransaction( entityManager -> {
191-
192-
List<Employee> employees = entityManager.createNativeQuery(
193-
"select * from employee e", Employee.class )
194-
.getResultList();
195-
196-
assertEquals( 5, employees.size() );
197-
198-
//The miss count is still 1, as now we got the query plan from the cache
199-
assertEquals( 1, statistics.getQueryPlanCacheMissCount() );
200-
//And the cache hit count increases.
201-
assertEquals( 1, statistics.getQueryPlanCacheHitCount() );
202-
} );
203-
204-
scope.inTransaction( entityManager -> {
205-
206-
List<Employee> employees = entityManager.createNativeQuery(
207-
"select * from employee e", Employee.class )
208-
.getResultList();
209-
210-
assertEquals( 5, employees.size() );
211-
212-
//The miss count is still 1, as now we got the query plan from the cache
213-
assertEquals( 1, statistics.getQueryPlanCacheMissCount() );
214-
//And the cache hit count increases.
215-
assertEquals( 2, statistics.getQueryPlanCacheHitCount() );
216-
} );
217-
}
218-
219171
@Test
220172
@TestForIssue( jiraKey = "HHH-13077" )
221173
public void testCreateNamedQueryHitCount(SessionFactoryScope scope) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.stat.internal;
8+
9+
import java.util.List;
10+
import java.util.Map;
11+
import javax.persistence.Entity;
12+
import javax.persistence.GeneratedValue;
13+
import javax.persistence.Id;
14+
import javax.persistence.NamedQuery;
15+
import javax.persistence.Table;
16+
17+
import org.hibernate.SessionFactory;
18+
import org.hibernate.cfg.Environment;
19+
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
20+
import org.hibernate.stat.Statistics;
21+
22+
import org.hibernate.testing.TestForIssue;
23+
import org.junit.Test;
24+
25+
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
26+
import static org.junit.Assert.assertEquals;
27+
28+
/**
29+
* @author Gail Badner
30+
*/
31+
@TestForIssue(jiraKey = "HHH-12855")
32+
public class QueryPlanCacheStatisticsTest extends BaseEntityManagerFunctionalTestCase {
33+
34+
private Statistics statistics;
35+
36+
@Override
37+
public Class[] getAnnotatedClasses() {
38+
return new Class[] {
39+
Employee.class
40+
};
41+
}
42+
43+
@Override
44+
protected void addConfigOptions(Map options) {
45+
options.put( Environment.GENERATE_STATISTICS, "true" );
46+
}
47+
48+
@Override
49+
protected void afterEntityManagerFactoryBuilt() {
50+
SessionFactory sessionFactory = entityManagerFactory().unwrap( SessionFactory.class );
51+
statistics = sessionFactory.getStatistics();
52+
53+
doInJPA( this::entityManagerFactory, entityManager -> {
54+
for ( long i = 1; i <= 5; i++ ) {
55+
if ( i % 3 == 0 ) {
56+
entityManager.flush();
57+
}
58+
Employee employee = new Employee();
59+
employee.setName( String.format( "Employee: %d", i ) );
60+
entityManager.persist( employee );
61+
}
62+
} );
63+
}
64+
65+
@Test
66+
@TestForIssue( jiraKey = "HHH-14632" )
67+
public void testCreateNativeQueryHitCount() {
68+
statistics.clear();
69+
70+
doInJPA( this::entityManagerFactory, entityManager -> {
71+
72+
List<Employee> employees = entityManager.createNativeQuery(
73+
"select * from employee e", Employee.class )
74+
.getResultList();
75+
76+
assertEquals( 5, employees.size() );
77+
78+
//First time, we get a cache miss, so the query is compiled
79+
assertEquals( 1, statistics.getQueryPlanCacheMissCount() );
80+
//The hit count should be 0 as we don't need to go to the cache after we already compiled the query
81+
assertEquals( 0, statistics.getQueryPlanCacheHitCount() );
82+
} );
83+
84+
doInJPA( this::entityManagerFactory, entityManager -> {
85+
86+
List<Employee> employees = entityManager.createNativeQuery(
87+
"select * from employee e", Employee.class )
88+
.getResultList();
89+
90+
assertEquals( 5, employees.size() );
91+
92+
//The miss count is still 1, as now we got the query plan from the cache
93+
assertEquals( 1, statistics.getQueryPlanCacheMissCount() );
94+
//And the cache hit count increases.
95+
assertEquals( 1, statistics.getQueryPlanCacheHitCount() );
96+
} );
97+
98+
doInJPA( this::entityManagerFactory, entityManager -> {
99+
100+
List<Employee> employees = entityManager.createNativeQuery(
101+
"select * from employee e", Employee.class )
102+
.getResultList();
103+
104+
assertEquals( 5, employees.size() );
105+
106+
//The miss count is still 1, as now we got the query plan from the cache
107+
assertEquals( 1, statistics.getQueryPlanCacheMissCount() );
108+
//And the cache hit count increases.
109+
assertEquals( 2, statistics.getQueryPlanCacheHitCount() );
110+
} );
111+
}
112+
113+
@Entity(name = "Employee")
114+
@Table(name = "employee")
115+
@NamedQuery(
116+
name = "find_employee_by_name",
117+
query = "select e from Employee e where e.name = :name"
118+
)
119+
public static class Employee {
120+
121+
@Id
122+
@GeneratedValue
123+
private Long id;
124+
125+
private String name;
126+
127+
public Long getId() {
128+
return id;
129+
}
130+
131+
public void setId(Long id) {
132+
this.id = id;
133+
}
134+
135+
public String getName() {
136+
return name;
137+
}
138+
139+
public void setName(String name) {
140+
this.name = name;
141+
}
142+
}
143+
144+
}

hibernate-core/src/test/resources/log4j2.properties

+6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ logger.type-basic-binder.level=trace
4242
logger.type-basic-extractor.name=org.hibernate.type.descriptor.jdbc.BasicExtractor
4343
logger.type-basic-extractor.level=trace
4444

45+
logger.jdbc-bind.name=org.hibernate.orm.jdbc.bind
46+
logger.jdbc-bind.level=trace
47+
48+
logger.jdbc-extract.name=org.hibernate.orm.jdbc.extract
49+
logger.jdbc-extract.level=trace
50+
4551
logger.hql-internal-ast.name=org.hibernate.hql.internal.ast
4652
logger.hql-internal-ast.level=debug
4753

0 commit comments

Comments
 (0)