mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-13 21:01:01 +08:00
Improve SimpleExpression.in(...) signature
This commit is contained in:
parent
0cfeeb5595
commit
6bb7a28649
@ -1263,6 +1263,33 @@ public final class Expressions {
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Combine the given expressions into a list expression
|
||||
*
|
||||
* @param clazz type of list expression
|
||||
* @param exprs list elements
|
||||
* @return list expression
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> Expression<T> list(Class<T> clazz, Expression<?>... exprs) {
|
||||
Expression<T> rv = (Expression<T>) exprs[0];
|
||||
for (int i = 1; i < exprs.length; i++) {
|
||||
rv = new SimpleOperation<T>(clazz, Ops.LIST, rv, exprs[i]);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Combine the given expressions into a list expression
|
||||
*
|
||||
* @param exprs list elements
|
||||
* @return list expression
|
||||
*/
|
||||
public static Expression<Tuple> list(Expression<?>... exprs) {
|
||||
return list(Tuple.class, exprs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a null expression for the specified type
|
||||
*
|
||||
|
||||
@ -229,6 +229,16 @@ public abstract class SimpleExpression<T> extends DslExpression<T> {
|
||||
return Expressions.booleanOperation(Ops.IN, mixin, right);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@code this in right} expression
|
||||
*
|
||||
* @param right rhs of the comparison
|
||||
* @return this in right
|
||||
*/
|
||||
public BooleanExpression in(Expression<? extends T>... right) {
|
||||
return Expressions.booleanOperation(Ops.IN, mixin, Expressions.list(right));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@code this <> right} expression
|
||||
*
|
||||
|
||||
@ -890,7 +890,13 @@ public class SQLSerializer extends SerializerBase<SQLSerializer> {
|
||||
}
|
||||
}
|
||||
|
||||
if (operator == SQLOps.UNION || operator == SQLOps.UNION_ALL) {
|
||||
if (operator == Ops.LIST && args.get(0) instanceof SubQueryExpression) {
|
||||
boolean oldUnion = inUnion;
|
||||
inUnion = true;
|
||||
super.visitOperation(type, SQLOps.UNION, args);
|
||||
inUnion = oldUnion;
|
||||
|
||||
} else if (operator == SQLOps.UNION || operator == SQLOps.UNION_ALL) {
|
||||
boolean oldUnion = inUnion;
|
||||
inUnion = true;
|
||||
super.visitOperation(type, operator, args);
|
||||
|
||||
@ -895,6 +895,17 @@ public class SelectBase extends AbstractBaseTest {
|
||||
assertEquals(0, query().from(employee).where(employee.id.in(ImmutableList.<Integer>of())).fetchCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ExcludeIn({MYSQL, TERADATA})
|
||||
public void in_subqueries() {
|
||||
QEmployee e1 = new QEmployee("e1");
|
||||
QEmployee e2 = new QEmployee("e2");
|
||||
assertEquals(2, query().from(employee).where(employee.id.in(
|
||||
query().from(e1).where(e1.firstname.eq("Mike")).select(e1.id),
|
||||
query().from(e2).where(e2.firstname.eq("Mary")).select(e2.id)
|
||||
)).fetchCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notIn_empty() {
|
||||
long count = query().from(employee).fetchCount();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user