[jOOQ/jOOQ#7527] Added Settings.diagnosticsPatterns

This commit is contained in:
Lukas Eder 2022-10-27 12:32:30 +02:00
parent da8a79452f
commit 73534e8e42
7 changed files with 141 additions and 9 deletions

View File

@ -59,6 +59,17 @@ public interface DiagnosticsContext extends Scope {
@Nullable
QueryPart part();
/**
* The transformed object from {@link #part()} if available, or
* <code>null</code>, if there was no specific transformation to attach the
* diagnostic to.
* <p>
* This helps diagnosing pattern transformations as indicated by
* {@link DiagnosticsListener#transformPattern(DiagnosticsContext)}.
*/
@Nullable
QueryPart transformedPart();
/**
* A message describing the diagnostics and the object in question.
*/

View File

@ -41,6 +41,7 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import org.jooq.conf.Settings;
import org.jooq.impl.DSL;
import org.jooq.impl.ParserException;
@ -273,6 +274,16 @@ public interface DiagnosticsListener {

View File

@ -133,6 +133,8 @@ public class Settings
@XmlElement(defaultValue = "true")
protected Boolean diagnosticsUnnecessaryWasNullCall = true;
@XmlElement(defaultValue = "true")
protected Boolean diagnosticsPatterns = true;
@XmlElement(defaultValue = "true")
protected Boolean diagnosticsTrivialCondition = true;
@XmlElement(defaultValue = "true")
protected Boolean diagnosticsNullCondition = true;
@ -1476,6 +1478,39 @@ public class Settings
this.diagnosticsUnnecessaryWasNullCall = value;
}
/**
* Whether to run the various pattern transformation diagnostics.
* <p>
* {@link #transformPatterns} allows for applying numerous pattern transformations, which can be turned on separately when running
* diagnostics. This flag overrides the {@link #transformPatterns} flag in the diagnostics context. Individual pattern flags
* still allow to enable / disable the pattern for diagnostics.
* <p>
* Diagnostics are turned off if no {@link org.jooq.Configuration#diagnosticsListenerProviders()} are configured.
* Once configured, this diagnostic is turned on by default.
* <p>
* This feature is available in the commercial distribution only.
*
* @return
* possible object is
* {@link Boolean }
*
*/
public Boolean isDiagnosticsPatterns() {
return diagnosticsPatterns;
}
/**
* Sets the value of the diagnosticsPatterns property.
*
* @param value
* allowed object is
* {@link Boolean }
*
*/
public void setDiagnosticsPatterns(Boolean value) {
this.diagnosticsPatterns = value;
}
/**
* Whether to run the {@link org.jooq.DiagnosticsListener#trivialCondition(org.jooq.DiagnosticsContext) diagnostic.
* <p>
@ -4953,6 +4988,11 @@ public class Settings
return this;
}
public Settings withDiagnosticsPatterns(Boolean value) {
setDiagnosticsPatterns(value);
return this;
}
public Settings withDiagnosticsTrivialCondition(Boolean value) {
setDiagnosticsTrivialCondition(value);
return this;
@ -6005,6 +6045,7 @@ public class Settings
builder.append("diagnosticsTooManyColumnsFetched", diagnosticsTooManyColumnsFetched);
builder.append("diagnosticsTooManyRowsFetched", diagnosticsTooManyRowsFetched);
builder.append("diagnosticsUnnecessaryWasNullCall", diagnosticsUnnecessaryWasNullCall);
builder.append("diagnosticsPatterns", diagnosticsPatterns);
builder.append("diagnosticsTrivialCondition", diagnosticsTrivialCondition);
builder.append("diagnosticsNullCondition", diagnosticsNullCondition);
builder.append("transformPatterns", transformPatterns);
@ -6530,6 +6571,15 @@ public class Settings
return false;
}
}
if (diagnosticsPatterns == null) {
if (other.diagnosticsPatterns!= null) {
return false;
}
} else {
if (!diagnosticsPatterns.equals(other.diagnosticsPatterns)) {
return false;
}
}
if (diagnosticsTrivialCondition == null) {
if (other.diagnosticsTrivialCondition!= null) {
return false;
@ -7793,6 +7843,7 @@ public class Settings
result = ((prime*result)+((diagnosticsTooManyColumnsFetched == null)? 0 :diagnosticsTooManyColumnsFetched.hashCode()));
result = ((prime*result)+((diagnosticsTooManyRowsFetched == null)? 0 :diagnosticsTooManyRowsFetched.hashCode()));
result = ((prime*result)+((diagnosticsUnnecessaryWasNullCall == null)? 0 :diagnosticsUnnecessaryWasNullCall.hashCode()));
result = ((prime*result)+((diagnosticsPatterns == null)? 0 :diagnosticsPatterns.hashCode()));
result = ((prime*result)+((diagnosticsTrivialCondition == null)? 0 :diagnosticsTrivialCondition.hashCode()));
result = ((prime*result)+((diagnosticsNullCondition == null)? 0 :diagnosticsNullCondition.hashCode()));
result = ((prime*result)+((transformPatterns == null)? 0 :transformPatterns.hashCode()));

View File

@ -63,6 +63,7 @@ final class DefaultDiagnosticsContext extends AbstractScope implements Diagnosti
private static final JooqLogger log = JooqLogger.getLogger(DefaultDiagnosticsContext.class);
final QueryPart part;
final QueryPart transformedPart;
final String message;
ResultSet resultSet;
DiagnosticsResultSet resultSetWrapper;
@ -93,6 +94,7 @@ final class DefaultDiagnosticsContext extends AbstractScope implements Diagnosti
singleton(actualStatement),
singletonList(actualStatement),
null,
null,
exception
);
}
@ -105,6 +107,7 @@ final class DefaultDiagnosticsContext extends AbstractScope implements Diagnosti
Set<String> duplicateStatements,
List<String> repeatedStatements,
QueryPart part,
QueryPart transformedPart,
Throwable exception
) {
super(configuration);
@ -115,6 +118,7 @@ final class DefaultDiagnosticsContext extends AbstractScope implements Diagnosti
this.duplicateStatements = duplicateStatements == null ? emptySet() : duplicateStatements;
this.repeatedStatements = repeatedStatements == null ? emptyList() : repeatedStatements;
this.part = part;
this.transformedPart = transformedPart;
this.exception = exception;
}
@ -123,6 +127,11 @@ final class DefaultDiagnosticsContext extends AbstractScope implements Diagnosti
return part;
}
@Override
public final QueryPart transformedPart() {
return transformedPart;
}
@Override
public final String message() {
return message;

View File

@ -37,11 +37,11 @@
*/
package org.jooq.impl;
import static java.lang.Boolean.FALSE;
import static java.util.Arrays.asList;
import static java.util.Collections.synchronizedMap;
// ...
// ...
// ...
import static org.jooq.conf.ParamType.FORCE_INDEXED;
import static org.jooq.impl.DSL.count;
import static org.jooq.impl.DSL.noCondition;
@ -51,7 +51,6 @@ import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
@ -70,6 +69,7 @@ import org.jooq.Query;
import org.jooq.QueryPart;
import org.jooq.RenderContext;
// ...
// ...
import org.jooq.Select;
import org.jooq.conf.Settings;
import org.jooq.impl.QOM.Eq;
@ -95,7 +95,8 @@ final class DiagnosticsConnection extends DefaultConnection {
DiagnosticsConnection(Configuration configuration) {
super(configuration.connectionProvider().acquire());
this.configuration = configuration;
// [#7527] The Settings.diagnosticsPattern flag overrides the Settings.transformPatterns flag.
this.configuration = configuration.deriveSettings(s -> s.withTransformPatterns(true));
this.normalisingRenderer = configuration.deriveSettings(s -> s
// Forcing all inline parameters to be indexed helps find opportunities to use bind variables
@ -175,8 +176,12 @@ final class DiagnosticsConnection extends DefaultConnection {
configuration.connectionProvider().release(getDelegate());
}
final boolean checkPattern(Predicate<? super Settings> test) {
return DiagnosticsListeners.checkPattern(configuration.settings(), test);
}
final boolean check(Predicate<? super Settings> test) {
return !FALSE.equals(test.test(configuration.settings()));
return DiagnosticsListeners.check(configuration.settings(), test);
}
@SuppressWarnings("unchecked")
@ -218,7 +223,7 @@ final class DiagnosticsConnection extends DefaultConnection {
listeners.duplicateStatements(new DefaultDiagnosticsContext(
configuration,
"Duplicate statements encountered.",
sql, normalised, duplicates, null, queries, null
sql, normalised, duplicates, null, queries, transformed, null
));
}
@ -228,7 +233,7 @@ final class DiagnosticsConnection extends DefaultConnection {
listeners.repeatedStatements(new DefaultDiagnosticsContext(
configuration,
"Repeated statements encountered.",
sql, normalised, null, repetitions, queries, null
sql, normalised, null, repetitions, queries, transformed, null
));
}
@ -259,6 +264,19 @@ final class DiagnosticsConnection extends DefaultConnection {
@ -282,7 +300,7 @@ final class DiagnosticsConnection extends DefaultConnection {
listeners.exception(new DefaultDiagnosticsContext(
configuration,
"An unexpected exception has occurred. See exception for details.",
sql, normalised, null, null, queries, exception
sql, normalised, null, null, queries, transformed, exception
));
}

View File

@ -63,8 +63,20 @@ final class DiagnosticsListeners implements DiagnosticsListener {
return new DiagnosticsListeners(configuration.diagnosticsListenerProviders());
}
private final boolean check(DiagnosticsContext ctx, Predicate<? super Settings> test) {
return !FALSE.equals(test.test(ctx.settings()));
private static final boolean check(DiagnosticsContext ctx, Predicate<? super Settings> test) {
return check(ctx.settings(), test);
}
static final boolean check(Settings settings, Predicate<? super Settings> test) {
return !FALSE.equals(test.test(settings));
}
private static final boolean checkPattern(DiagnosticsContext ctx, Predicate<? super Settings> test) {
return checkPattern(ctx.settings(), test);
}
static final boolean checkPattern(Settings settings, Predicate<? super Settings> test) {
return !FALSE.equals(settings.isDiagnosticsPatterns()) && check(settings, test);
}
@Override
@ -126,6 +138,13 @@ final class DiagnosticsListeners implements DiagnosticsListener {

View File

@ -343,6 +343,19 @@ Diagnostics are turned off if no {@link org.jooq.Configuration#diagnosticsListen
Once configured, this diagnostic is turned on by default.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="diagnosticsPatterns" type="boolean" minOccurs="0" maxOccurs="1" default="true">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Whether to run the various pattern transformation diagnostics.
<p>
{@link #transformPatterns} allows for applying numerous pattern transformations, which can be turned on separately when running
diagnostics. This flag overrides the {@link #transformPatterns} flag in the diagnostics context. Individual pattern flags
still allow to enable / disable the pattern for diagnostics.
<p>
Diagnostics are turned off if no {@link org.jooq.Configuration#diagnosticsListenerProviders()} are configured.
Once configured, this diagnostic is turned on by default.
<p>
This feature is available in the commercial distribution only.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="diagnosticsTrivialCondition" type="boolean" minOccurs="0" maxOccurs="1" default="true">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Whether to run the {@link org.jooq.DiagnosticsListener#trivialCondition(org.jooq.DiagnosticsContext) diagnostic.
<p>