[jOOQ/jOOQ#7284] Replace common patterns in query object model
- NOT NOT DISTINCT - Idempotent function repetitions - UPPER - LOWER - LTRIM - RTRIM - TRIM
This commit is contained in:
parent
b402ffca75
commit
74aec2ac91
@ -121,6 +121,10 @@ public class Settings
|
||||
protected Boolean transformPatternsNegNeg = true;
|
||||
@XmlElement(defaultValue = "true")
|
||||
protected Boolean transformPatternsBitNotBitNot = true;
|
||||
@XmlElement(defaultValue = "true")
|
||||
protected Boolean transformPatternsNotNotDistinct = true;
|
||||
@XmlElement(defaultValue = "true")
|
||||
protected Boolean transformPatternsIdempotentFunctionRepetition = true;
|
||||
@XmlElement(defaultValue = "false")
|
||||
protected Boolean transformAnsiJoinToTableLists = false;
|
||||
@XmlElement(defaultValue = "WHEN_NEEDED")
|
||||
@ -1183,9 +1187,7 @@ public class Settings
|
||||
/**
|
||||
* Transform <code>NOT(NOT(x))</code> to <code>x</code>
|
||||
* <p>
|
||||
* For various reasons, there may be a redundant nesting of <code>NOT</code> unary operators, e.g. as a
|
||||
* left over of some prior transformation, including manual ones. This transformation will simplify such
|
||||
* redundant negations by removing them.
|
||||
* This transformation removes a redundant logic negation.
|
||||
* <p>
|
||||
* To enable this feature, {@link #transformPatterns} must be enabled as well.
|
||||
* <p>
|
||||
@ -1215,9 +1217,7 @@ public class Settings
|
||||
/**
|
||||
* Transform <code>-(-(x))</code> to <code>x</code>
|
||||
* <p>
|
||||
* For various reasons, there may be a redundant nesting of <code>-</code> unary operators, e.g. as a
|
||||
* left over of some prior transformation, including manual ones. This transformation will simplify such
|
||||
* redundant negations by removing them.
|
||||
* This transformation removes a redundant arithmetic negation.
|
||||
* <p>
|
||||
* To enable this feature, {@link #transformPatterns} must be enabled as well.
|
||||
* <p>
|
||||
@ -1245,11 +1245,9 @@ public class Settings
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform <code>~(~(x))</code> to <code>x</code>
|
||||
* Transform <code>~(~(x))</code> to <code>x</code>.
|
||||
* <p>
|
||||
* For various reasons, there may be a redundant nesting of <code>~</code> unary operators, e.g. as a
|
||||
* left over of some prior transformation, including manual ones. This transformation will simplify such
|
||||
* redundant negations by removing them.
|
||||
* This transformation removes a redundant bitwise negation.
|
||||
* <p>
|
||||
* To enable this feature, {@link #transformPatterns} must be enabled as well.
|
||||
* <p>
|
||||
@ -1276,6 +1274,72 @@ public class Settings
|
||||
this.transformPatternsBitNotBitNot = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform <code>NOT (a IS NOT DISTINCT FROM b)</code> to <code>a IS DISTINCT FROM b</code>
|
||||
* <p>
|
||||
* This transformation removes a redundant logical negation from the <code>DISTINCT</code> predicate.
|
||||
* <p>
|
||||
* This feature is available in the commercial distribution only.
|
||||
*
|
||||
* @return
|
||||
* possible object is
|
||||
* {@link Boolean }
|
||||
*
|
||||
*/
|
||||
public Boolean isTransformPatternsNotNotDistinct() {
|
||||
return transformPatternsNotNotDistinct;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the transformPatternsNotNotDistinct property.
|
||||
*
|
||||
* @param value
|
||||
* allowed object is
|
||||
* {@link Boolean }
|
||||
*
|
||||
*/
|
||||
public void setTransformPatternsNotNotDistinct(Boolean value) {
|
||||
this.transformPatternsNotNotDistinct = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform all repetitions of idempotent functions, such as <code>UPPER(UPPER(s))</code> to <code>UPPER(s)</code>
|
||||
* <p>
|
||||
* Idempotent functions that are covered so far, include:
|
||||
* <ul>
|
||||
* <li><code>LTRIM(LTRIM(s))</code> to <code>LTRIM(s)</code></li>
|
||||
* <li><code>LTRIM(TRIM(s))</code> to <code>TRIM(s)</code></li>
|
||||
* <li><code>RTRIM(RTRIM(s))</code> to <code>RTRIM(s)</code></li>
|
||||
* <li><code>RTRIM(TRIM(s))</code> to <code>TRIM(s)</code></li>
|
||||
* <li><code>TRIM(LTRIM(s))</code> to <code>TRIM(s)</code></li>
|
||||
* <li><code>TRIM(RTRIM(s))</code> to <code>TRIM(s)</code></li>
|
||||
* <li><code>UPPER(UPPER(s))</code> to <code>UPPER(s)</code></li>
|
||||
* <li><code>LOWER(LOWER(s))</code> to <code>LOWER(s)</code></li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* This feature is available in the commercial distribution only.
|
||||
*
|
||||
* @return
|
||||
* possible object is
|
||||
* {@link Boolean }
|
||||
*
|
||||
*/
|
||||
public Boolean isTransformPatternsIdempotentFunctionRepetition() {
|
||||
return transformPatternsIdempotentFunctionRepetition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the transformPatternsIdempotentFunctionRepetition property.
|
||||
*
|
||||
* @param value
|
||||
* allowed object is
|
||||
* {@link Boolean }
|
||||
*
|
||||
*/
|
||||
public void setTransformPatternsIdempotentFunctionRepetition(Boolean value) {
|
||||
this.transformPatternsIdempotentFunctionRepetition = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform ANSI join to table lists if possible.
|
||||
* <p>
|
||||
@ -3537,6 +3601,16 @@ public class Settings
|
||||
return this;
|
||||
}
|
||||
|
||||
public Settings withTransformPatternsNotNotDistinct(Boolean value) {
|
||||
setTransformPatternsNotNotDistinct(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Settings withTransformPatternsIdempotentFunctionRepetition(Boolean value) {
|
||||
setTransformPatternsIdempotentFunctionRepetition(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Settings withTransformAnsiJoinToTableLists(Boolean value) {
|
||||
setTransformAnsiJoinToTableLists(value);
|
||||
return this;
|
||||
@ -4365,6 +4439,8 @@ public class Settings
|
||||
builder.append("transformPatternsNotNot", transformPatternsNotNot);
|
||||
builder.append("transformPatternsNegNeg", transformPatternsNegNeg);
|
||||
builder.append("transformPatternsBitNotBitNot", transformPatternsBitNotBitNot);
|
||||
builder.append("transformPatternsNotNotDistinct", transformPatternsNotNotDistinct);
|
||||
builder.append("transformPatternsIdempotentFunctionRepetition", transformPatternsIdempotentFunctionRepetition);
|
||||
builder.append("transformAnsiJoinToTableLists", transformAnsiJoinToTableLists);
|
||||
builder.append("transformInConditionSubqueryWithLimitToDerivedTable", transformInConditionSubqueryWithLimitToDerivedTable);
|
||||
builder.append("transformQualify", transformQualify);
|
||||
@ -4805,6 +4881,24 @@ public class Settings
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (transformPatternsNotNotDistinct == null) {
|
||||
if (other.transformPatternsNotNotDistinct!= null) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!transformPatternsNotNotDistinct.equals(other.transformPatternsNotNotDistinct)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (transformPatternsIdempotentFunctionRepetition == null) {
|
||||
if (other.transformPatternsIdempotentFunctionRepetition!= null) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!transformPatternsIdempotentFunctionRepetition.equals(other.transformPatternsIdempotentFunctionRepetition)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (transformAnsiJoinToTableLists == null) {
|
||||
if (other.transformAnsiJoinToTableLists!= null) {
|
||||
return false;
|
||||
@ -5703,6 +5797,8 @@ public class Settings
|
||||
result = ((prime*result)+((transformPatternsNotNot == null)? 0 :transformPatternsNotNot.hashCode()));
|
||||
result = ((prime*result)+((transformPatternsNegNeg == null)? 0 :transformPatternsNegNeg.hashCode()));
|
||||
result = ((prime*result)+((transformPatternsBitNotBitNot == null)? 0 :transformPatternsBitNotBitNot.hashCode()));
|
||||
result = ((prime*result)+((transformPatternsNotNotDistinct == null)? 0 :transformPatternsNotNotDistinct.hashCode()));
|
||||
result = ((prime*result)+((transformPatternsIdempotentFunctionRepetition == null)? 0 :transformPatternsIdempotentFunctionRepetition.hashCode()));
|
||||
result = ((prime*result)+((transformAnsiJoinToTableLists == null)? 0 :transformAnsiJoinToTableLists.hashCode()));
|
||||
result = ((prime*result)+((transformInConditionSubqueryWithLimitToDerivedTable == null)? 0 :transformInConditionSubqueryWithLimitToDerivedTable.hashCode()));
|
||||
result = ((prime*result)+((transformQualify == null)? 0 :transformQualify.hashCode()));
|
||||
|
||||
@ -84,10 +84,13 @@ import org.jooq.conf.SettingsTools;
|
||||
import org.jooq.exception.ControlFlowSignal;
|
||||
import org.jooq.exception.DataAccessException;
|
||||
import org.jooq.impl.QOM.BitNot;
|
||||
import org.jooq.impl.QOM.IsNotDistinctFrom;
|
||||
import org.jooq.impl.QOM.Ltrim;
|
||||
import org.jooq.impl.QOM.Neg;
|
||||
import org.jooq.impl.QOM.Not;
|
||||
import org.jooq.impl.QOM.Rtrim;
|
||||
import org.jooq.impl.QOM.Trim;
|
||||
import org.jooq.impl.QOM.Upper;
|
||||
import org.jooq.impl.ScopeMarker.ScopeContent;
|
||||
import org.jooq.tools.JooqLogger;
|
||||
import org.jooq.tools.StringUtils;
|
||||
@ -713,10 +716,11 @@ class DefaultRenderContext extends AbstractContext<RenderContext> implements Ren
|
||||
if (isQuery == null) {
|
||||
isQuery = internal instanceof Query;
|
||||
|
||||
if (TRUE.equals(settings().isTransformPatterns()) && configuration().requireCommercial(() -> "SQL transformations are a commercial only feature. Please consider upgrading to the jOOQ Professional Edition or jOOQ Enterprise Edition.")) {
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -832,6 +836,77 @@ class DefaultRenderContext extends AbstractContext<RenderContext> implements Ren
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -295,9 +295,7 @@ This feature is available in the commercial distribution only.]]></jxb:javadoc><
|
||||
<element name="transformPatternsNotNot" type="boolean" minOccurs="0" maxOccurs="1" default="true">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Transform <code>NOT(NOT(x))</code> to <code>x</code>
|
||||
<p>
|
||||
For various reasons, there may be a redundant nesting of <code>NOT</code> unary operators, e.g. as a
|
||||
left over of some prior transformation, including manual ones. This transformation will simplify such
|
||||
redundant negations by removing them.
|
||||
This transformation removes a redundant logic negation.
|
||||
<p>
|
||||
To enable this feature, {@link #transformPatterns} must be enabled as well.
|
||||
<p>
|
||||
@ -307,9 +305,7 @@ This feature is available in the commercial distribution only.]]></jxb:javadoc><
|
||||
<element name="transformPatternsNegNeg" type="boolean" minOccurs="0" maxOccurs="1" default="true">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Transform <code>-(-(x))</code> to <code>x</code>
|
||||
<p>
|
||||
For various reasons, there may be a redundant nesting of <code>-</code> unary operators, e.g. as a
|
||||
left over of some prior transformation, including manual ones. This transformation will simplify such
|
||||
redundant negations by removing them.
|
||||
This transformation removes a redundant arithmetic negation.
|
||||
<p>
|
||||
To enable this feature, {@link #transformPatterns} must be enabled as well.
|
||||
<p>
|
||||
@ -317,17 +313,41 @@ This feature is available in the commercial distribution only.]]></jxb:javadoc><
|
||||
</element>
|
||||
|
||||
<element name="transformPatternsBitNotBitNot" type="boolean" minOccurs="0" maxOccurs="1" default="true">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Transform <code>~(~(x))</code> to <code>x</code>
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Transform <code>~(~(x))</code> to <code>x</code>.
|
||||
<p>
|
||||
For various reasons, there may be a redundant nesting of <code>~</code> unary operators, e.g. as a
|
||||
left over of some prior transformation, including manual ones. This transformation will simplify such
|
||||
redundant negations by removing them.
|
||||
This transformation removes a redundant bitwise negation.
|
||||
<p>
|
||||
To enable this feature, {@link #transformPatterns} must be enabled as well.
|
||||
<p>
|
||||
This feature is available in the commercial distribution only.]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
</element>
|
||||
|
||||
<element name="transformPatternsNotNotDistinct" type="boolean" minOccurs="0" maxOccurs="1" default="true">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Transform <code>NOT (a IS NOT DISTINCT FROM b)</code> to <code>a IS DISTINCT FROM b</code>
|
||||
<p>
|
||||
This transformation removes a redundant logical negation from the <code>DISTINCT</code> predicate.
|
||||
<p>
|
||||
This feature is available in the commercial distribution only.]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
</element>
|
||||
|
||||
<element name="transformPatternsIdempotentFunctionRepetition" type="boolean" minOccurs="0" maxOccurs="1" default="true">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Transform all repetitions of idempotent functions, such as <code>UPPER(UPPER(s))</code> to <code>UPPER(s)</code>
|
||||
<p>
|
||||
Idempotent functions that are covered so far, include:
|
||||
<ul>
|
||||
<li><code>LTRIM(LTRIM(s))</code> to <code>LTRIM(s)</code></li>
|
||||
<li><code>LTRIM(TRIM(s))</code> to <code>TRIM(s)</code></li>
|
||||
<li><code>RTRIM(RTRIM(s))</code> to <code>RTRIM(s)</code></li>
|
||||
<li><code>RTRIM(TRIM(s))</code> to <code>TRIM(s)</code></li>
|
||||
<li><code>TRIM(LTRIM(s))</code> to <code>TRIM(s)</code></li>
|
||||
<li><code>TRIM(RTRIM(s))</code> to <code>TRIM(s)</code></li>
|
||||
<li><code>UPPER(UPPER(s))</code> to <code>UPPER(s)</code></li>
|
||||
<li><code>LOWER(LOWER(s))</code> to <code>LOWER(s)</code></li>
|
||||
</ul>
|
||||
<p>
|
||||
This feature is available in the commercial distribution only.]]></jxb:javadoc></jxb:property></appinfo></annotation>
|
||||
</element>
|
||||
|
||||
<element name="transformAnsiJoinToTableLists" type="boolean" minOccurs="0" maxOccurs="1" default="false">
|
||||
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Transform ANSI join to table lists if possible.
|
||||
<p>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user