[jOOQ/jOOQ#13894] Add SQLDialect.precedesStrictly(SQLDialect)

This commit is contained in:
Lukas Eder 2022-08-19 11:15:04 +02:00
parent 862f3939e9
commit dd13f01390

View File

@ -1209,6 +1209,46 @@ public enum SQLDialect {
return other.predecessors().contains(this);
}
/**
* Whether this dialect strictly precedes an other dialect from the same
* family.
* <p>
* This returns:
* <ul>
* <li><code>false</code> if this dialect is the same as the other
* dialect</li>
* <li><code>true</code> if this dialect precedes the other dialect via any
* number of calls to {@link #predecessor()}</li>
* </ul>
* The above also implies that:
* <ul>
* <li><code>false</code> if the two dialects do not belong to the same
* family</li>
* </ul>
* <p>
* This is useful to see if some feature is supported by <em>"at least"</em>
* a given dialect version. Example:
*
* <pre>
* <code>
* // Do this block only if the chosen dialect was before PostgreSQL 9.3-
* if (dialect.precedesStrictly(POSTGRES_9_3)) {
* }
*
* // Do this block only if the chosen dialect was before PostgreSQL 9.4-
* else if (dialect.precedesStrictly(POSTGRES_9_4)) {
* }
*
* // Fall back to post-PostgreSQL 9.4+ behaviour
* else {
* }
* </code>
* </pre>
*/
public final boolean precedesStrictly(SQLDialect other) {
return precedes(other) && this != other;
}
/**
* Check whether this dialect supports another one.
* <p>