🪖 A library for counting queries for Spring Data JPA application

Overview

🪖 Query-Counter

Query-Counter is a library for counting queries for Spring Data JPA application, currently supporting Hibernate only. It aims to help beginners figure out how many queries are generated within a transaction or any specific range. There are several use-cases for test as follows:

  • Counting the exact number of queries generated within a transaction or any specific range.
  • Understanding lazy loading fetch strategy of ORM framework.
  • Detecting N + 1.

You can report bug or request new features via Issue tab.


Requirements

  • JDK 1.8 or higher.
  • Spring Boot & Spring Data JPA (Hibernate)

Installation

Maven

pom.xml

<dependency>
  <groupId>io.github.xlffm3</groupId>
  <artifactId>query-counter</artifactId>
  <version>1.0.1</version>
</dependency>

Gradle

build.gradle

testImplementation 'io.github.xlffm3:query-counter:1.0.1'

Features

application.properties

query-counter.enabled=true
query-counter.count-level=read_only

You can choose whether to enable Query-Counter or not. false is default. You can also specify count level. Query-Counter supports three count-level as follows:

  • READ_ONLY (default)
  • WRITE_ONLY
  • ALL

QueryTest.java

@SpringBootTest
public class QueryTest {

    @Autowired
    private QueryCounter queryCounter;
    
    @Autowired
    private HibernateQueryCounter hibernateQueryCounter;
    
    @Autowired
    private UserService userService;
    
    @Test
    void test() {
        queryCounter.startCountingQuery();
        userService.findAllWithNPlusOne();
        Long queryCounts = queryCounter.getQueryCounts();
        
        assertThat(queryCounts).isEqualTo(15L);
    }
}

The only implementation of QueryCounter interface Query-Counter provides is HibernateQueryCounter yet. HibernateQueryCounter is registered as a Spring Bean.



You might also like...

Dynamically filters JPA entities with a simple query syntax. Provides JPA/Hibernate predicates and Spring Data specifications.

Spring Filter You need a way to dynamically filter entities without any effort? Just add me to your pom.xml. Your API will gain a full featured search

Dec 13, 2022

In this project, we will implement two Spring Boot Java Web application called, streamer-data-jpa and streamer-data-r2dbc.

In this project, we will implement two Spring Boot Java Web application called, streamer-data-jpa and streamer-data-r2dbc.

In this project, we will implement two Spring Boot Java Web application called, streamer-data-jpa and streamer-data-r2dbc. They both will fetch 1 million of customer's data from MySQL and stream them to Kafka. The main goal is to compare the application's performance and resource utilization.

Nov 2, 2022

Querystream - Build JPA Criteria queries using a Stream-like API

QueryStream QueryStream allows you to perform JPA queries using a Stream-like API. Just like a Java 8 Stream, a QueryStream is built up in a pipeline,

Sep 24, 2022

Spring Boot JWT Authentication example with Spring Security & Spring Data JPA

Spring Boot JWT Authentication example with Spring Security & Spring Data JPA

Jan 26, 2022

An examples of creating test records in the database with Spring Boot + Spring Data + JPA usage.

Spring Boot + JPA — Clear Tests An examples of creating test records in the database with Spring Boot + Spring Data + JPA usage. Check out the article

Nov 24, 2022

An example of how to working with paging in Spring for GraphQL / Spring Data JPA

Spring for GraphQL Paging This repo contains the code for a live coding session I did on: Spring Data JPA GraphQL Paging & Sorting The reason I put th

Nov 28, 2022

Java project of math function and counting

Java project of math function and counting

This is program for some math function created by me. They are not exactly efficient, they are just for education purposses.

Feb 2, 2022

MapReduce Code for Counting the numbers in JAVA

Anurag000-rgb/MapReduce-Repetation_Counting MapReduce Code for Counting the numbers in JAVA Basically in this project But it good to write in Apache Spark using scala Rather In Apache MapReduce

Mar 1, 2022

Counting In-game Timer for Minecraft SpeedRun

SpeedRunIGT What is this mod? The Timer Mod for Minecraft Speedrun Features Display RTA/IGT timers In-game Auto Start & Pause the timer Support Many C

Jan 1, 2023

循序渐进,学习Spring Boot、Spring Boot & Shiro、Spring Batch、Spring Cloud、Spring Cloud Alibaba、Spring Security & Spring Security OAuth2,博客Spring系列源码:https://mrbird.cc

Spring 系列教程 该仓库为个人博客https://mrbird.cc中Spring系列源码,包含Spring Boot、Spring Boot & Shiro、Spring Cloud,Spring Boot & Spring Security & Spring Security OAuth2

Jan 6, 2023

Projeto de LAB: Conhendo o projeto Spring data JPA com Java na prática

Conhecendo o Projeto Spring Data JPA na Prática Sejam bem-vindos ao projeto de LAB Conhecendo o Projeto Spring Data JPA na Prática oferecido gratuitam

Dec 31, 2022

This repository contains source code examples to support my course Spring Data JPA and Hibernate Beginner to Guru

Spring Data JPA - Spring Data JPA This repository contains source code examples to support my course Spring Data JPA and Hibernate Beginner to Guru Co

Aug 24, 2022

jdbi is designed to provide convenient tabular data access in Java; including templated SQL, parameterized and strongly typed queries, and Streams integration

The Jdbi library provides convenient, idiomatic access to relational databases in Java. Jdbi is built on top of JDBC. If your database has a JDBC driv

Dec 27, 2022

Spring JPA, Hibernate One To Many example in Spring Boot with @ManyToOne annotation

Spring Boot One To Many example with Spring JPA, Hibernate Implement Spring JPA One-To-Many mapping with Hibernate in a Spring Boot CRUD example using

Dec 28, 2022

Spring JPA @Query for custom query in Spring Boot example

Spring JPA @Query example (Custom query) in Spring Boot Use Spring JPA @Query for custom query in Spring Boot example: Way to use JPQL (Java Persisten

Dec 3, 2022

Spring JPA Native Query example in Spring Boot

Spring JPA Native Query example in Spring Boot

Nov 30, 2022

Spring JPA Many To Many example with Hibernate and Spring Boot CRUD Rest API - ManyToMany annotation

Spring JPA Many To Many example with Hibernate and Spring Boot CRUD Rest API - ManyToMany annotation

Dec 28, 2022

A distributed data integration framework that simplifies common aspects of big data integration such as data ingestion, replication, organization and lifecycle management for both streaming and batch data ecosystems.

Apache Gobblin Apache Gobblin is a highly scalable data management solution for structured and byte-oriented data in heterogeneous data ecosystems. Ca

Jan 4, 2023
Owner
Jinhong
👨‍💻 Chasing Yesterday
Jinhong
Spring GraphQL demo application

Spring Projects GraphQL API This repository is a demo application for introducing the Spring GraphQL project. This is currently based on Spring Boot a

Brian Clozel 4 Aug 24, 2022
Library for OpenAPI 3 with spring-boot

Full documentation Acknowledgements springdoc-openapi is made possible thanks to all of its contributors. Introduction The springdoc-openapi Java libr

springdoc-openapi 2.3k Jan 5, 2023
Spring HATEOAS - Library to support implementing representations for hyper-text driven REST web services.

Spring HATEOAS This project provides some APIs to ease creating REST representations that follow the HATEOAS principle when working with Spring and es

Spring 996 Dec 28, 2022
Spring HATEOAS - Library to support implementing representations for hyper-text driven REST web services.

Spring HATEOAS This project provides some APIs to ease creating REST representations that follow the HATEOAS principle when working with Spring and es

Spring 920 Mar 8, 2021
This repository contains HttpUrlConnection and Volley based application example

This repository contains HttpUrlConnection and Volley based application example. In this you will find implementation of both ways to consume API. This repository show examples to send receive the data in both cases.

Zeeshan 3 Jan 15, 2022
Codigician backend application.

codigician-api Getting Started You can use docker compose to run the application. # go to build directory $ cd build/ # start couchbase container $ do

codigician 2 Nov 17, 2021
A damn simple library for building production-ready RESTful web services.

Dropwizard Dropwizard is a sneaky way of making fast Java web applications. It's a little bit of opinionated glue code which bangs together a set of l

Dropwizard 8.3k Jan 5, 2023
Microserver is a Java 8 native, zero configuration, standards based, battle hardened library to run Java Rest Microservices via a standard Java main class. Supporting pure Microservice or Micro-monolith styles.

Microserver A convenient modular engine for Microservices. Microserver plugins offer seamless integration with Spring (core), Jersey, Guava, Tomcat, G

AOL 936 Dec 19, 2022
Nano-library which provides the ability to define typesafe (!) configuration templates for applications.

Configur8 Nano-library which provides the ability to define typesafe (!) Configuration templates for applications. Concept: A Configuration is a set o

David Denton 11 Oct 3, 2022
Applied Spring Data JPA technologies including mapping, connecting real DB, Hibernate, Queries, Paging & Sorting, various Relationships, Transactions

University Management In this project, I practiced & applied Spring Data JPA technologies including mapping, connecting real DB, Hibernate, Queries, P

SarvarKhalimov 2 Sep 5, 2022