[jOOQ/jOOQ#8577] Also support NOT LIKE ANY and LIKE ALL

In addition to `LIKE ANY` and `NOT LIKE ALL` the inverse predicates `NOT
LIKE ANY` and `LIKE ALL` are now also supported.
This commit is contained in:
Knut Wannheden 2019-06-26 12:33:30 +02:00
parent c5a3ef1b52
commit 3eba94c925
4 changed files with 108 additions and 27 deletions

View File

@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<version>2.0.2.RELEASE</version>
</parent>
<groupId>org.jooq</groupId>
@ -34,25 +34,6 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jooq</artifactId>
<!-- Exclude the default jOOQ dependency if
1. You want a more or less recent jOOQ dependency
2. You want to depend on a commercial jOOQ distribution
-->
<exclusions>
<exclusion>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Keep this explicit dependency only if you excluded jOOQ above -->
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
<version>${jooq.version}</version>
</dependency>
<dependency>
@ -140,7 +121,6 @@
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>${jooq.version}</version>
<executions>
<execution>
@ -177,6 +157,13 @@
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

View File

@ -1658,9 +1658,71 @@ extends
@Support
LikeEscapeStep likeAny(Collection<?> values);
/**
* Create a condition to negatively pattern-check this field against any element in an array of values.
* <p>
* SQL: <code>(this not like value0 or this not like value1 or ...)</code>
*
* @see LikeEscapeStep#escape(char)
*/
@Support
LikeEscapeStep notLikeAny(String... values);
/**
* Create a condition to negatively pattern-check this field against any element in an array of values.
* <p>
* SQL: <code>(this not like value0 or this not like value1 or ...)</code>
*
* @see LikeEscapeStep#escape(char)
*/
@Support
@SuppressWarnings("unchecked")
LikeEscapeStep notLikeAny(Field<String>... fields);
/**
* Create a condition to negatively pattern-check this field against any element in an array of values.
* <p>
* SQL: <code>(this not like value0 or this not like value1 or ...)</code>
*
* @see LikeEscapeStep#escape(char)
*/
@Support
LikeEscapeStep notLikeAny(Collection<?> values);
/**
* Create a condition to pattern-check this field against all elements in an array of values.
* <p>
* SQL: <code>(this like value0 and this like value1 and ...)</code>
*
* @see LikeEscapeStep#escape(char)
*/
@Support
LikeEscapeStep likeAll(String... values);
/**
* Create a condition to pattern-check this field against all elements in an array of fields.
* <p>
* SQL: <code>(this like field0 and this like field1 and ...)</code>
*
* @see LikeEscapeStep#escape(char)
*/
@Support
@SuppressWarnings("unchecked")
LikeEscapeStep likeAll(Field<String>... fields);
/**
* Create a condition to pattern-check this field against all elements in a collection of fields or values.
* <p>
* SQL: <code>(this like field0 and this like field1 and ...)</code>
*
* @see LikeEscapeStep#escape(char)
*/
@Support
LikeEscapeStep likeAll(Collection<?> values);
/**
* Create a condition to negatively pattern-check this field against all elements in an array of values.
* <p>
* SQL: <code>(this not like value0 and this not like value1 and ...)</code>
*
* @see LikeEscapeStep#escape(char)
@ -1669,7 +1731,7 @@ extends
LikeEscapeStep notLikeAll(String... values);
/**
* Create a condition to pattern-check this field against all elements in an array of fields.
* Create a condition to negatively pattern-check this field against all elements in an array of fields.
* <p>
* SQL: <code>(this not like field0 and this not like field1 and ...)</code>
*
@ -1680,7 +1742,7 @@ extends
LikeEscapeStep notLikeAll(Field<String>... fields);
/**
* Create a condition to pattern-check this field against all elements in a collection of fields or values.
* Create a condition to negatively pattern-check this field against all elements in a collection of fields or values.
* <p>
* SQL: <code>(this not like field0 and this not like field1 and ...)</code>
*

View File

@ -868,6 +868,38 @@ abstract class AbstractField<T> extends AbstractNamed implements Field<T> {
return new CombinedCompareCondition(this, LIKE, Quantifier.ANY, Tools.fields(values, SQLDataType.VARCHAR));
}
@Override
public final LikeEscapeStep notLikeAny(String... values) {
return notLikeAny(Tools.fields(values));
}
@Override
@SuppressWarnings("unchecked")
public final LikeEscapeStep notLikeAny(Field<String>... fields) {
return notLikeAny(Arrays.asList(fields));
}
@Override
public final LikeEscapeStep notLikeAny(Collection<?> values) {
return new CombinedCompareCondition(this, NOT_LIKE, Quantifier.ANY, Tools.fields(values, SQLDataType.VARCHAR));
}
@Override
public final LikeEscapeStep likeAll(String... values) {
return likeAll(Tools.fields(values));
}
@Override
@SuppressWarnings("unchecked")
public final LikeEscapeStep likeAll(Field<String>... fields) {
return likeAll(Arrays.asList(fields));
}
@Override
public final LikeEscapeStep likeAll(Collection<?> values) {
return new CombinedCompareCondition(this, LIKE, Quantifier.ALL, Tools.fields(values, SQLDataType.VARCHAR));
}
@Override
public final LikeEscapeStep notLikeAll(String... values) {
return notLikeAll(Tools.fields(values));

View File

@ -4398,7 +4398,7 @@ final class ParserImpl implements Parser {
: ((RowN) left).between((RowN) r1, (RowN) r2);
}
else if (left instanceof Field && parseKeywordIf(ctx, "LIKE")) {
if (!not && parseKeywordIf(ctx, "ANY")) {
if (parseKeywordIf(ctx, "ANY")) {
parse(ctx, '(');
List<Field<?>> fields = null;
if (parseIf(ctx, ')'))
@ -4413,10 +4413,10 @@ final class ParserImpl implements Parser {
}
boolean escape = parseKeywordIf(ctx, "ESCAPE");
char character = escape ? parseCharacterLiteral(ctx) : ' ';
LikeEscapeStep result = ((Field) left).likeAny(fields);
LikeEscapeStep result = not ? ((Field) left).notLikeAny(fields) : ((Field) left).likeAny(fields);
return escape ? result.escape(character) : result;
}
else if (not && parseKeywordIf(ctx, "ALL")) {
else if (parseKeywordIf(ctx, "ALL")) {
parse(ctx, '(');
List<Field<?>> fields = null;
if (parseIf(ctx, ')'))
@ -4431,7 +4431,7 @@ final class ParserImpl implements Parser {
}
boolean escape = parseKeywordIf(ctx, "ESCAPE");
char character = escape ? parseCharacterLiteral(ctx) : ' ';
LikeEscapeStep result = ((Field) left).notLikeAll(fields);
LikeEscapeStep result = not ? ((Field) left).notLikeAll(fields) : ((Field) left).likeAll(fields);
return escape ? result.escape(character) : result;
}
else {