Skip to content

Commit 37349e0

Browse files
committed
fix eclipse-ee4j#1408 SQL statement is printed in exceptions despite eclipselink.logging.level.sql is OFF
Signed-off-by: Ryosuke Okada <[email protected]>
1 parent 1bef069 commit 37349e0

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-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

+8
Original file line numberDiff line numberDiff line change
@@ -1856,6 +1856,10 @@ 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+
}
1862+
queryException.getQuery().setOccurException(true);
18591863
} else if (exception instanceof DatabaseException) {
18601864
DatabaseException databaseException = (DatabaseException)exception;
18611865
if (databaseException.getQuery() == null) {
@@ -1867,6 +1871,10 @@ public Object executeQuery(DatabaseQuery query, AbstractRecord row, int retryCou
18671871
if (databaseException.getSession() == null) {
18681872
databaseException.setSession(this);
18691873
}
1874+
if (databaseException.getQuery().getSession() == null) {
1875+
databaseException.getQuery().setSession(this);
1876+
}
1877+
databaseException.getQuery().setOccurException(true);
18701878
//if this query is a read query outside of a transaction then we may be able to retry the query
18711879
if (!isInTransaction() && query.isReadQuery() && getDatasourceLogin() instanceof DatabaseLogin) {
18721880
final int count = getLogin().getQueryRetryAttemptCount();

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

+28-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>
@@ -336,6 +337,9 @@ public enum ParameterType {POSITIONAL, NAMED}
336337
/** Allow the reserved pound char used to delimit bind parameters to be overridden */
337338
protected String parameterDelimiter;
338339

340+
/** Flag to control the sql log */
341+
protected boolean occurException = false;
342+
339343
/**
340344
* PUBLIC: Initialize the state of the query
341345
*/
@@ -2670,6 +2674,20 @@ public void storeBypassCache() {
26702674
setShouldStoreBypassCache(true);
26712675
}
26722676

2677+
/**
2678+
* Return true if exception has occured.
2679+
*/
2680+
public boolean isOccurException() {
2681+
return occurException;
2682+
}
2683+
2684+
/**
2685+
* Set if exception has occurd.
2686+
*/
2687+
public void setOccurException(boolean occurException) {
2688+
this.occurException = occurException;
2689+
}
2690+
26732691
@Override
26742692
public String toString() {
26752693
String referenceClassString = "";
@@ -2681,11 +2699,17 @@ public String toString() {
26812699
if ((getName() != null) && (!getName().equals(""))) {
26822700
nameString = "name=\"" + getName() + "\" ";
26832701
}
2684-
if (isSQLCallQuery()) {
2685-
queryString = "sql=\"" + getSQLString() + "\"";
2686-
} else if (isJPQLCallQuery()) {
2687-
queryString = "jpql=\"" + getJPQLString() + "\"";
2702+
2703+
if (isOccurException()) {
2704+
if (session.shouldLog(SessionLog.FINE, SessionLog.SQL)) {
2705+
if (isSQLCallQuery()) {
2706+
queryString = "sql=\"" + getSQLString() + "\"";
2707+
} else if (isJPQLCallQuery()) {
2708+
queryString = "jpql=\"" + getJPQLString() + "\"";
2709+
}
2710+
}
26882711
}
2712+
26892713
return getClass().getSimpleName() + "(" + nameString + referenceClassString + queryString + ")";
26902714
}
26912715

0 commit comments

Comments
 (0)