Skip to content

Commit 9dec911

Browse files
committed
Make sure to clear the ThreadLocal variables
1 parent 95576ae commit 9dec911

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

core/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/support/CountQueryDetector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public Object invoke(MethodInvocation invocation) throws Throwable {
4141
try {
4242
return invocation.proceed();
4343
} finally {
44-
IS_COUNT_QUERY.set(false);
44+
IS_COUNT_QUERY.remove();
4545
}
4646
}
4747
}

core/src/main/java/com/cosium/spring/data/jpa/entity/graph/repository/support/RepositoryMethodEntityGraphExtractor.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ public Object invoke(MethodInvocation invocation) throws Throwable {
8484
try {
8585
return doInvoke(invocation);
8686
} finally {
87-
CURRENT_REPOSITORY.set(oldRepo);
87+
if (oldRepo == null) {
88+
CURRENT_REPOSITORY.remove();
89+
} else {
90+
CURRENT_REPOSITORY.set(oldRepo);
91+
}
8892
}
8993
}
9094

@@ -142,7 +146,11 @@ private Object doInvoke(MethodInvocation invocation) throws Throwable {
142146
return invocation.proceed();
143147
} finally {
144148
if (newEntityGraphCandidatePreValidated) {
145-
currentEntityGraph.set(genuineCandidate);
149+
if (genuineCandidate == null) {
150+
currentEntityGraph.remove();
151+
} else {
152+
currentEntityGraph.set(genuineCandidate);
153+
}
146154
}
147155
}
148156
}

0 commit comments

Comments
 (0)