[#1074] Add Field.notBetween(T, T) for convenience

This commit is contained in:
Lukas Eder 2012-01-27 15:11:07 +00:00
parent 39e1723d37
commit 15e62bbae6
5 changed files with 46 additions and 2 deletions

View File

@ -3060,6 +3060,17 @@ public abstract class jOOQAbstractTest<
.where(val(3).between(TBook_AUTHOR_ID(), TBook_ID()))
.orderBy(TBook_ID()).fetch(TBook_ID()));
// [#1074] The NOT BETWEEN clause
assertEquals(Arrays.asList(1, 4), create().select()
.from(TBook())
.where(TBook_ID().notBetween(2, 3))
.orderBy(TBook_ID()).fetch(TBook_ID()));
assertEquals(Arrays.asList(1, 2), create().select()
.from(TBook())
.where(val(3).notBetween(TBook_AUTHOR_ID(), TBook_ID()))
.orderBy(TBook_ID()).fetch(TBook_ID()));
// The IN clause
// [#502] empty set checks
assertEquals(Arrays.asList(), create().select()

View File

@ -579,6 +579,22 @@ public interface Field<T> extends NamedTypeProviderQueryPart<T>, AliasProvider<F
@Support
Condition between(Field<T> minValue, Field<T> maxValue);
/**
* Create a condition to check this field against some bounds
* <p>
* SQL: <code>this not between minValue and maxValue</code>
*/
@Support
Condition notBetween(T minValue, T maxValue);
/**
* Create a condition to check this field against some bounds
* <p>
* SQL: <code>this not between minValue and maxValue</code>
*/
@Support
Condition notBetween(Field<T> minValue, Field<T> maxValue);
/**
* <code>this = value</code>
* <p>

View File

@ -448,7 +448,17 @@ abstract class AbstractField<T> extends AbstractNamedTypeProviderQueryPart<T> im
@Override
public final Condition between(Field<T> minValue, Field<T> maxValue) {
return new BetweenCondition<T>(this, nullSafe(minValue), nullSafe(maxValue));
return new BetweenCondition<T>(this, nullSafe(minValue), nullSafe(maxValue), false);
}
@Override
public final Condition notBetween(T minValue, T maxValue) {
return notBetween(val(minValue), val(maxValue));
}
@Override
public final Condition notBetween(Field<T> minValue, Field<T> maxValue) {
return new BetweenCondition<T>(this, nullSafe(minValue), nullSafe(maxValue), true);
}
@Override

View File

@ -50,14 +50,16 @@ class BetweenCondition<T> extends AbstractCondition {
private static final long serialVersionUID = -4666251100802237878L;
private final boolean not;
private final Field<T> field;
private final Field<T> minValue;
private final Field<T> maxValue;
BetweenCondition(Field<T> field, Field<T> minValue, Field<T> maxValue) {
BetweenCondition(Field<T> field, Field<T> minValue, Field<T> maxValue, boolean not) {
this.field = field;
this.minValue = minValue;
this.maxValue = maxValue;
this.not = not;
}
@Override
@ -73,6 +75,7 @@ class BetweenCondition<T> extends AbstractCondition {
@Override
public final void toSQL(RenderContext context) {
context.sql(field)
.sql(not ? " not" : "")
.sql(" between ")
.sql(minValue)
.sql(" and ")

View File

@ -631,6 +631,10 @@ public class jOOQTest {
assertEquals("\"TABLE1\".\"ID1\" between 1 and 10", r_refI().render(c));
assertEquals("\"TABLE1\".\"ID1\" between ? and ?", r_ref().render(c));
c = FIELD_ID1.notBetween(1, 10);
assertEquals("\"TABLE1\".\"ID1\" not between 1 and 10", r_refI().render(c));
assertEquals("\"TABLE1\".\"ID1\" not between ? and ?", r_ref().render(c));
context.checking(new Expectations() {{
oneOf(statement).setInt(1, 1);
oneOf(statement).setInt(2, 10);