Skip to content

Commit 229e43d

Browse files
committed
HHH-17989 - Fix for StatisticsImplementor.closeStatement() never called
Signed-off-by: Jan Schatteman <[email protected]>
1 parent 7002ee8 commit 229e43d

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

hibernate-core/src/main/java/org/hibernate/resource/jdbc/spi/JdbcEventHandler.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ public void jdbcPrepareStatementStart() {
8080
if ( sessionListener != null ) {
8181
sessionListener.jdbcPrepareStatementStart();
8282
}
83+
84+
if ( statistics != null && statistics.isStatisticsEnabled() ) {
85+
statistics.prepareStatement();
86+
}
8387
}
8488

8589
public void jdbcPrepareStatementEnd() {
@@ -88,7 +92,7 @@ public void jdbcPrepareStatementEnd() {
8892
}
8993

9094
if ( statistics != null && statistics.isStatisticsEnabled() ) {
91-
statistics.prepareStatement();
95+
statistics.closeStatement();
9296
}
9397
}
9498

hibernate-core/src/test/java/org/hibernate/orm/test/stateless/StatelessSessionStatisticsTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,22 @@ void test(SessionFactoryScope scope) {
3737
assertEquals(0, statistics.getEntityUpdateCount());
3838
assertEquals(0, statistics.getEntityDeleteCount());
3939
assertEquals(0, statistics.getEntityLoadCount());
40+
assertEquals(0, statistics.getPrepareStatementCount());
4041
Person person = new Person();
4142
person.name = "Gavin";
4243
person.handles.add("@1ovthafew");
4344
scope.inStatelessTransaction(s -> s.insert(person));
4445
assertEquals(1, statistics.getEntityInsertCount());
4546
assertEquals(1, statistics.getCollectionRecreateCount());
47+
assertEquals(3, statistics.getPrepareStatementCount());
48+
assertEquals(3, statistics.getCloseStatementCount());
4649
scope.inStatelessSession(s -> s.get(Person.class, person.id));
4750
assertEquals(1, statistics.getEntityLoadCount());
4851
assertEquals(0, statistics.getEntityFetchCount());
4952
assertEquals(1, statistics.getCollectionLoadCount());
5053
assertEquals(0, statistics.getCollectionFetchCount());
54+
assertEquals(4, statistics.getPrepareStatementCount());
55+
assertEquals(4, statistics.getCloseStatementCount());
5156
person.name = "Gavin King";
5257
scope.inStatelessTransaction(s -> s.update(person));
5358
assertEquals(1, statistics.getEntityUpdateCount());
@@ -56,25 +61,37 @@ void test(SessionFactoryScope scope) {
5661
assertEquals(2, statistics.getEntityLoadCount());
5762
assertEquals(2, statistics.getCollectionLoadCount());
5863
assertEquals(0, statistics.getCollectionFetchCount());
64+
assertEquals(8, statistics.getPrepareStatementCount());
65+
assertEquals(8, statistics.getCloseStatementCount());
5966
scope.inStatelessSession(s -> s.get(s.createEntityGraph(Person.class), FETCH, person.id));
6067
assertEquals(3, statistics.getEntityLoadCount());
6168
assertEquals(2, statistics.getCollectionLoadCount());
6269
assertEquals(0, statistics.getCollectionFetchCount());
70+
assertEquals(9, statistics.getPrepareStatementCount());
71+
assertEquals(9, statistics.getCloseStatementCount());
6372
scope.inStatelessSession(s -> s.fetch(s.get(s.createEntityGraph(Person.class), FETCH, person.id).handles));
6473
assertEquals(4, statistics.getEntityLoadCount());
6574
assertEquals(3, statistics.getCollectionLoadCount());
6675
assertEquals(1, statistics.getCollectionFetchCount());
76+
assertEquals(11, statistics.getPrepareStatementCount());
77+
assertEquals(11, statistics.getCloseStatementCount());
6778
scope.inStatelessSession(s -> s.createQuery("from Person", Person.class).getSingleResult());
6879
assertEquals(5, statistics.getEntityLoadCount());
6980
assertEquals(4, statistics.getCollectionLoadCount());
7081
assertEquals(2, statistics.getCollectionFetchCount());
82+
assertEquals(13, statistics.getPrepareStatementCount());
83+
assertEquals(13, statistics.getCloseStatementCount());
7184
person.handles.add("hello world");
7285
scope.inStatelessTransaction(s -> s.upsert(person));
7386
assertEquals(2, statistics.getCollectionUpdateCount());
87+
assertEquals(17, statistics.getPrepareStatementCount());
88+
assertEquals(17, statistics.getCloseStatementCount());
7489
scope.inStatelessTransaction(s -> s.delete(person));
7590
assertEquals(1, statistics.getEntityDeleteCount());
7691
assertEquals(1, statistics.getCollectionRemoveCount());
7792
assertEquals(4, statistics.getTransactionCount());
93+
assertEquals(19, statistics.getPrepareStatementCount());
94+
assertEquals(19, statistics.getCloseStatementCount());
7895
}
7996

8097
@Entity(name="Person")

hibernate-core/src/test/java/org/hibernate/orm/test/stats/StatisticsWithNoCachingTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
@DomainModel
2222
@SessionFactory
2323
@ServiceRegistry(
24-
settingProviders = @SettingProvider(provider = StatisticsWithNoCachingTest.RegionFacrotySettingProvider.class, settingName = AvailableSettings.CACHE_REGION_FACTORY)
24+
settingProviders = @SettingProvider(provider = StatisticsWithNoCachingTest.RegionFactorySettingProvider.class, settingName = AvailableSettings.CACHE_REGION_FACTORY)
2525
)
2626
public class StatisticsWithNoCachingTest {
2727

28-
public static class RegionFacrotySettingProvider implements SettingProvider.Provider<String> {
28+
public static class RegionFactorySettingProvider implements SettingProvider.Provider<String> {
2929

3030
@Override
3131
public String getSetting() {

0 commit comments

Comments
 (0)