[#5621] Add FieldEscapeStep as a return type for Field.like(), such that the ESCAPE keyword can be used explicitly
This commit is contained in:
parent
40ed77af97
commit
879bd8fd3f
@ -1200,12 +1200,14 @@ public interface Field<T> extends SelectField<T>, GroupField, FieldOrRow {
|
||||
* SQL: <code>this like value</code>
|
||||
*/
|
||||
@Support
|
||||
Condition like(Field<String> value);
|
||||
LikeEscapeStep like(Field<String> value);
|
||||
|
||||
/**
|
||||
* Create a condition to pattern-check this field against a value.
|
||||
* <p>
|
||||
* SQL: <code>this like value escape 'e'</code>
|
||||
*
|
||||
* @see LikeEscapeStep#escape(char)
|
||||
*/
|
||||
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
Condition like(Field<String> value, char escape);
|
||||
@ -1216,12 +1218,14 @@ public interface Field<T> extends SelectField<T>, GroupField, FieldOrRow {
|
||||
* SQL: <code>this like value</code>
|
||||
*/
|
||||
@Support
|
||||
Condition like(String value);
|
||||
LikeEscapeStep like(String value);
|
||||
|
||||
/**
|
||||
* Create a condition to pattern-check this field against a value.
|
||||
* <p>
|
||||
* SQL: <code>this like value escape 'e'</code>
|
||||
*
|
||||
* @see LikeEscapeStep#escape(char)
|
||||
*/
|
||||
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
Condition like(String value, char escape);
|
||||
@ -1235,7 +1239,7 @@ public interface Field<T> extends SelectField<T>, GroupField, FieldOrRow {
|
||||
* <code>lower(this) like lower(field)</code> in all other dialects.
|
||||
*/
|
||||
@Support
|
||||
Condition likeIgnoreCase(Field<String> field);
|
||||
LikeEscapeStep likeIgnoreCase(Field<String> field);
|
||||
|
||||
/**
|
||||
* Create a condition to case-insensitively pattern-check this field against
|
||||
@ -1244,6 +1248,8 @@ public interface Field<T> extends SelectField<T>, GroupField, FieldOrRow {
|
||||
* This translates to <code>this ilike field</code> in
|
||||
* {@link SQLDialect#POSTGRES}, or to
|
||||
* <code>lower(this) like lower(field)</code> in all other dialects.
|
||||
*
|
||||
* @see LikeEscapeStep#escape(char)
|
||||
*/
|
||||
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
Condition likeIgnoreCase(Field<String> field, char escape);
|
||||
@ -1257,7 +1263,7 @@ public interface Field<T> extends SelectField<T>, GroupField, FieldOrRow {
|
||||
* <code>lower(this) like lower(value)</code> in all other dialects.
|
||||
*/
|
||||
@Support
|
||||
Condition likeIgnoreCase(String value);
|
||||
LikeEscapeStep likeIgnoreCase(String value);
|
||||
|
||||
/**
|
||||
* Create a condition to case-insensitively pattern-check this field against
|
||||
@ -1266,6 +1272,8 @@ public interface Field<T> extends SelectField<T>, GroupField, FieldOrRow {
|
||||
* This translates to <code>this ilike value</code> in
|
||||
* {@link SQLDialect#POSTGRES}, or to
|
||||
* <code>lower(this) like lower(value)</code> in all other dialects.
|
||||
*
|
||||
* @see LikeEscapeStep#escape(char)
|
||||
*/
|
||||
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
Condition likeIgnoreCase(String value, char escape);
|
||||
@ -1276,12 +1284,14 @@ public interface Field<T> extends SelectField<T>, GroupField, FieldOrRow {
|
||||
* SQL: <code>this not like field</code>
|
||||
*/
|
||||
@Support
|
||||
Condition notLike(Field<String> field);
|
||||
LikeEscapeStep notLike(Field<String> field);
|
||||
|
||||
/**
|
||||
* Create a condition to pattern-check this field against a field.
|
||||
* <p>
|
||||
* SQL: <code>this not like field escape 'e'</code>
|
||||
*
|
||||
* @see LikeEscapeStep#escape(char)
|
||||
*/
|
||||
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
Condition notLike(Field<String> field, char escape);
|
||||
@ -1292,12 +1302,14 @@ public interface Field<T> extends SelectField<T>, GroupField, FieldOrRow {
|
||||
* SQL: <code>this not like value</code>
|
||||
*/
|
||||
@Support
|
||||
Condition notLike(String value);
|
||||
LikeEscapeStep notLike(String value);
|
||||
|
||||
/**
|
||||
* Create a condition to pattern-check this field against a value.
|
||||
* <p>
|
||||
* SQL: <code>this not like value escape 'e'</code>
|
||||
*
|
||||
* @see LikeEscapeStep#escape(char)
|
||||
*/
|
||||
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
Condition notLike(String value, char escape);
|
||||
@ -1311,7 +1323,7 @@ public interface Field<T> extends SelectField<T>, GroupField, FieldOrRow {
|
||||
* <code>lower(this) not like lower(field)</code> in all other dialects.
|
||||
*/
|
||||
@Support
|
||||
Condition notLikeIgnoreCase(Field<String> field);
|
||||
LikeEscapeStep notLikeIgnoreCase(Field<String> field);
|
||||
|
||||
/**
|
||||
* Create a condition to case-insensitively pattern-check this field against
|
||||
@ -1320,6 +1332,8 @@ public interface Field<T> extends SelectField<T>, GroupField, FieldOrRow {
|
||||
* This translates to <code>this not ilike field</code> in
|
||||
* {@link SQLDialect#POSTGRES}, or to
|
||||
* <code>lower(this) not like lower(field)</code> in all other dialects.
|
||||
*
|
||||
* @see LikeEscapeStep#escape(char)
|
||||
*/
|
||||
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
Condition notLikeIgnoreCase(Field<String> field, char escape);
|
||||
@ -1333,7 +1347,7 @@ public interface Field<T> extends SelectField<T>, GroupField, FieldOrRow {
|
||||
* <code>lower(this) not like lower(value)</code> in all other dialects.
|
||||
*/
|
||||
@Support
|
||||
Condition notLikeIgnoreCase(String value);
|
||||
LikeEscapeStep notLikeIgnoreCase(String value);
|
||||
|
||||
/**
|
||||
* Create a condition to case-insensitively pattern-check this field against
|
||||
@ -1342,6 +1356,8 @@ public interface Field<T> extends SelectField<T>, GroupField, FieldOrRow {
|
||||
* This translates to <code>this not ilike value</code> in
|
||||
* {@link SQLDialect#POSTGRES}, or to
|
||||
* <code>lower(this) not like lower(value)</code> in all other dialects.
|
||||
*
|
||||
* @see LikeEscapeStep#escape(char)
|
||||
*/
|
||||
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, MARIADB, MYSQL, POSTGRES, SQLITE })
|
||||
Condition notLikeIgnoreCase(String value, char escape);
|
||||
|
||||
@ -92,6 +92,7 @@ import org.jooq.Converter;
|
||||
import org.jooq.DataType;
|
||||
import org.jooq.DatePart;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.LikeEscapeStep;
|
||||
import org.jooq.QuantifiedSelect;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Record1;
|
||||
@ -717,7 +718,7 @@ abstract class AbstractField<T> extends AbstractQueryPart implements Field<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Condition like(String value) {
|
||||
public final LikeEscapeStep like(String value) {
|
||||
return like(Tools.field(value, String.class));
|
||||
}
|
||||
|
||||
@ -727,17 +728,17 @@ abstract class AbstractField<T> extends AbstractQueryPart implements Field<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Condition like(Field<String> field) {
|
||||
public final LikeEscapeStep like(Field<String> field) {
|
||||
return new CompareCondition(this, nullSafe(field, getDataType()), LIKE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Condition like(Field<String> field, char escape) {
|
||||
return new CompareCondition(this, nullSafe(field, getDataType()), LIKE, escape);
|
||||
return like(field).escape(escape);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Condition likeIgnoreCase(String value) {
|
||||
public final LikeEscapeStep likeIgnoreCase(String value) {
|
||||
return likeIgnoreCase(Tools.field(value, String.class));
|
||||
}
|
||||
|
||||
@ -747,13 +748,13 @@ abstract class AbstractField<T> extends AbstractQueryPart implements Field<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Condition likeIgnoreCase(Field<String> field) {
|
||||
public final LikeEscapeStep likeIgnoreCase(Field<String> field) {
|
||||
return new CompareCondition(this, nullSafe(field, getDataType()), LIKE_IGNORE_CASE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Condition likeIgnoreCase(Field<String> field, char escape) {
|
||||
return new CompareCondition(this, nullSafe(field, getDataType()), LIKE_IGNORE_CASE, escape);
|
||||
return likeIgnoreCase(field).escape(escape);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -767,7 +768,7 @@ abstract class AbstractField<T> extends AbstractQueryPart implements Field<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Condition notLike(String value) {
|
||||
public final LikeEscapeStep notLike(String value) {
|
||||
return notLike(Tools.field(value, String.class));
|
||||
}
|
||||
|
||||
@ -777,17 +778,17 @@ abstract class AbstractField<T> extends AbstractQueryPart implements Field<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Condition notLike(Field<String> field) {
|
||||
public final LikeEscapeStep notLike(Field<String> field) {
|
||||
return new CompareCondition(this, nullSafe(field, getDataType()), NOT_LIKE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Condition notLike(Field<String> field, char escape) {
|
||||
return new CompareCondition(this, nullSafe(field, getDataType()), NOT_LIKE, escape);
|
||||
return notLike(field).escape(escape);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Condition notLikeIgnoreCase(String value) {
|
||||
public final LikeEscapeStep notLikeIgnoreCase(String value) {
|
||||
return notLikeIgnoreCase(Tools.field(value, String.class));
|
||||
}
|
||||
|
||||
@ -797,13 +798,13 @@ abstract class AbstractField<T> extends AbstractQueryPart implements Field<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Condition notLikeIgnoreCase(Field<String> field) {
|
||||
public final LikeEscapeStep notLikeIgnoreCase(Field<String> field) {
|
||||
return new CompareCondition(this, nullSafe(field, getDataType()), NOT_LIKE_IGNORE_CASE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Condition notLikeIgnoreCase(Field<String> field, char escape) {
|
||||
return new CompareCondition(this, nullSafe(field, getDataType()), NOT_LIKE_IGNORE_CASE, escape);
|
||||
return notLikeIgnoreCase(field).escape(escape);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -59,15 +59,17 @@ import static org.jooq.impl.DSL.inline;
|
||||
|
||||
import org.jooq.Clause;
|
||||
import org.jooq.Comparator;
|
||||
import org.jooq.Condition;
|
||||
import org.jooq.Context;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.LikeEscapeStep;
|
||||
import org.jooq.SQLDialect;
|
||||
import org.jooq.conf.ParamType;
|
||||
|
||||
/**
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
final class CompareCondition extends AbstractCondition {
|
||||
final class CompareCondition extends AbstractCondition implements LikeEscapeStep {
|
||||
|
||||
private static final long serialVersionUID = -747240442279619486L;
|
||||
private static final Clause[] CLAUSES = { CONDITION, CONDITION_COMPARISON };
|
||||
@ -75,17 +77,18 @@ final class CompareCondition extends AbstractCondition {
|
||||
private final Field<?> field1;
|
||||
private final Field<?> field2;
|
||||
private final Comparator comparator;
|
||||
private final Character escape;
|
||||
private Character escape;
|
||||
|
||||
CompareCondition(Field<?> field1, Field<?> field2, Comparator comparator) {
|
||||
this(field1, field2, comparator, null);
|
||||
}
|
||||
|
||||
CompareCondition(Field<?> field1, Field<?> field2, Comparator comparator, Character escape) {
|
||||
this.field1 = field1;
|
||||
this.field2 = field2;
|
||||
this.comparator = comparator;
|
||||
this.escape = escape;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Condition escape(char c) {
|
||||
this.escape = c;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
Reference in New Issue
Block a user