forked from yannbriancon/spring-hibernate-query-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves yannbriancon#26 Added HibernateQueryOnRequestResetIntercepto…
…r which can be used to reset query detection state on each request
- Loading branch information
Martin Hollerweger
committed
May 18, 2021
1 parent
b0c9abb
commit 6eaa8c4
Showing
4 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/com/yannbriancon/interceptor/HibernateQueryOnRequestResetInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.yannbriancon.interceptor; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.servlet.HandlerInterceptor; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
@Component | ||
@ComponentScan(basePackages = {"com.yannbriancon"}) | ||
public class HibernateQueryOnRequestResetInterceptor implements HandlerInterceptor { | ||
|
||
@Autowired | ||
HibernateQueryInterceptor hibernateQueryInterceptor; | ||
|
||
@Override | ||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | ||
|
||
// Reset query detection state on each new request | ||
hibernateQueryInterceptor.resetNPlusOneQueryDetectionState(); | ||
return true; | ||
} | ||
} |