Skip to content

Commit 2e077e6

Browse files
Update README.md
1 parent 018172b commit 2e077e6

File tree

1 file changed

+11
-0
lines changed
  • HibernateSpringBootCountSQLStatements

1 file changed

+11
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1+
**[Count and Assert SQL Statements](https://github.com/AnghelLeonard/Hibernate-SpringBoot/tree/master/HibernateSpringBootCountSQLStatements)**
12

3+
**Description:** This application is a sample of counting and asserting SQL statements triggered "behind the scene". Is very useful to count the SQL statements in order to ensure that your code is not generating more SQLs that you may think (e.g., N+1 can be easily detected by asserting the number of expected statements).
4+
5+
**Key points:**\
6+
- in pom.xml add dependencies for `datasource-proxy` and Vlad Mihalcea's `db-util`\
7+
- create the `ProxyDataSourceBuilder` with `countQuery()`\
8+
- reset the counter via `SQLStatementCountValidator.reset()`\
9+
- assert `INSERT`, `UPDATE`, `DELETE` and `SELECT` via `assertInsert/Update/Delete/Select/Count(long expectedNumberOfSql)`
10+
11+
**Output example (when the number of expected SQLs is not equal with the reality an exception is thrown):**\
12+
![](https://github.com/AnghelLeonard/Hibernate-SpringBoot/blob/master/HibernateSpringBootCountSQLStatements/sample.png)

0 commit comments

Comments
 (0)