Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit dae92e7

Browse files
committedJan 28, 2022
fix eclipse-ee4j#1408 SQL statement is printed in exceptions despite eclipselink.logging.level.sql is OFF
Signed-off-by: Ryosuke Okada <ryosuke.okada@fujitsu.com>
1 parent 1bef069 commit dae92e7

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed
 

‎foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/exceptions/DatabaseException.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.eclipse.persistence.internal.sessions.AbstractSession;
2323
import org.eclipse.persistence.exceptions.i18n.ExceptionMessageGenerator;
2424
import org.eclipse.persistence.sessions.DataRecord;
25+
import org.eclipse.persistence.logging.SessionLog;
2526

2627
/**
2728
* <P><B>Purpose</B>:
@@ -210,7 +211,7 @@ public String getMessage() {
210211
} else {
211212
writer.write("000");
212213
}
213-
if (getCall() != null) {
214+
if (getCall() != null && session.shouldLog(SessionLog.FINE, SessionLog.SQL)) {
214215
writer.write(cr());
215216
writer.write(getIndentationString());
216217
writer.write(ExceptionMessageGenerator.getHeader("CallHeader"));

‎foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/sessions/AbstractSession.java

+6
Original file line numberDiff line numberDiff line change
@@ -1856,6 +1856,9 @@ public Object executeQuery(DatabaseQuery query, AbstractRecord row, int retryCou
18561856
if (queryException.getSession() == null) {
18571857
queryException.setSession(this);
18581858
}
1859+
if (queryException.getQuery().getSession() == null) {
1860+
queryException.getQuery().setSession(this);
1861+
}
18591862
} else if (exception instanceof DatabaseException) {
18601863
DatabaseException databaseException = (DatabaseException)exception;
18611864
if (databaseException.getQuery() == null) {
@@ -1867,6 +1870,9 @@ public Object executeQuery(DatabaseQuery query, AbstractRecord row, int retryCou
18671870
if (databaseException.getSession() == null) {
18681871
databaseException.setSession(this);
18691872
}
1873+
if (databaseException.getQuery().getSession() == null) {
1874+
databaseException.getQuery().setSession(this);
1875+
}
18701876
//if this query is a read query outside of a transaction then we may be able to retry the query
18711877
if (!isInTransaction() && query.isReadQuery() && getDatasourceLogin() instanceof DatabaseLogin) {
18721878
final int count = getLogin().getQueryRetryAttemptCount();

‎foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/queries/DatabaseQuery.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import org.eclipse.persistence.sessions.remote.*;
6161
import org.eclipse.persistence.sessions.DatabaseRecord;
6262
import org.eclipse.persistence.sessions.SessionProfiler;
63+
import org.eclipse.persistence.logging.SessionLog;
6364

6465
/**
6566
* <p>
@@ -2681,10 +2682,13 @@ public String toString() {
26812682
if ((getName() != null) && (!getName().equals(""))) {
26822683
nameString = "name=\"" + getName() + "\" ";
26832684
}
2684-
if (isSQLCallQuery()) {
2685-
queryString = "sql=\"" + getSQLString() + "\"";
2686-
} else if (isJPQLCallQuery()) {
2687-
queryString = "jpql=\"" + getJPQLString() + "\"";
2685+
2686+
if (session.shouldLog(SessionLog.FINE, SessionLog.SQL)) {
2687+
if (isSQLCallQuery()) {
2688+
queryString = "sql=\"" + getSQLString() + "\"";
2689+
} else if (isJPQLCallQuery()) {
2690+
queryString = "jpql=\"" + getJPQLString() + "\"";
2691+
}
26882692
}
26892693
return getClass().getSimpleName() + "(" + nameString + referenceClassString + queryString + ")";
26902694
}

0 commit comments

Comments
 (0)
Please sign in to comment.