Skip to content

Commit 8cc0510

Browse files
committed
Removed ThreadLocal safety since a test can span on multiple threads (ex: a test executing a HTTP request on the server)
1 parent 9524985 commit 8cc0510

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/main/java/com/lemick/integration/hibernate/HibernateStatementCountInspector.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@
22

33
import org.hibernate.resource.jdbc.spi.StatementInspector;
44

5+
/**
6+
* NOT Thread-Safe since it is meant to be used by Spring tests that are not multi-threaded
7+
* ThreadLocal does not work because a test can span on multiple threads (ex: a test executing a HTTP request on the server)
8+
*/
59
public class HibernateStatementCountInspector implements StatementInspector {
610

7-
private static final ThreadLocal<HibernateStatistics> statisticsStore = ThreadLocal.withInitial(HibernateStatistics::new);
11+
private static final HibernateStatistics statistics = new HibernateStatistics();
812

913
private HibernateStatementParser statementParser = new JSQLHibernateStatementParser();
1014

1115
@Override
1216
public String inspect(String sql) {
13-
statementParser.parseSqlStatement(sql, statisticsStore.get());
17+
statementParser.parseSqlStatement(sql, statistics);
1418
return sql;
1519
}
1620

1721
public static HibernateStatistics getStatistics() {
18-
return statisticsStore.get();
22+
return statistics;
1923
}
2024

2125
}

0 commit comments

Comments
 (0)