mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-24 15:55:55 +00:00
#626 - ENH: Add support for where().idIn(...) using varargs
This commit is contained in:
@@ -251,6 +251,11 @@ public interface ExpressionFactory {
|
||||
*/
|
||||
Expression idEq(Object value);
|
||||
|
||||
/**
|
||||
* Id IN a list of Id values.
|
||||
*/
|
||||
Expression idIn(Object... idValues);
|
||||
|
||||
/**
|
||||
* Id IN a list of Id values.
|
||||
*/
|
||||
|
||||
@@ -758,6 +758,11 @@ public interface ExpressionList<T> {
|
||||
*/
|
||||
ExpressionList<T> notExists(Query<?> subQuery);
|
||||
|
||||
/**
|
||||
* Id IN a list of id values.
|
||||
*/
|
||||
ExpressionList<T> idIn(Object... idValues);
|
||||
|
||||
/**
|
||||
* Id IN a list of id values.
|
||||
*/
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.avaje.ebean.search.TextSimple;
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionFactory;
|
||||
import com.avaje.ebeaninternal.api.SpiQuery;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -365,6 +366,13 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
|
||||
return new IdInExpression(idList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Id IN a list of id values.
|
||||
*/
|
||||
public Expression idIn(Object... idValues) {
|
||||
return new IdInExpression(Arrays.asList(idValues));
|
||||
}
|
||||
|
||||
/**
|
||||
* All Equal - Map containing property names and their values.
|
||||
* <p>
|
||||
|
||||
@@ -33,7 +33,7 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
|
||||
|
||||
protected final Query<T> query;
|
||||
|
||||
protected final ExpressionList<T> parentExprList;
|
||||
private final ExpressionList<T> parentExprList;
|
||||
|
||||
protected transient ExpressionFactory expr;
|
||||
|
||||
@@ -57,11 +57,11 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
|
||||
this(query, query.getExpressionFactory(), parentExprList);
|
||||
}
|
||||
|
||||
public DefaultExpressionList(Query<T> query, ExpressionFactory expr, ExpressionList<T> parentExprList) {
|
||||
DefaultExpressionList(Query<T> query, ExpressionFactory expr, ExpressionList<T> parentExprList) {
|
||||
this(query, expr, parentExprList, new ArrayList<SpiExpression>());
|
||||
}
|
||||
|
||||
protected DefaultExpressionList(Query<T> query, ExpressionFactory expr, ExpressionList<T> parentExprList, List<SpiExpression> list) {
|
||||
DefaultExpressionList(Query<T> query, ExpressionFactory expr, ExpressionList<T> parentExprList, List<SpiExpression> list) {
|
||||
this(query, expr, parentExprList, list, false);
|
||||
}
|
||||
|
||||
@@ -667,6 +667,12 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionList<T> idIn(Object... idValues) {
|
||||
add(expr.idIn(idValues));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionList<T> idIn(List<?> idList) {
|
||||
add(expr.idIn(idList));
|
||||
|
||||
@@ -482,6 +482,11 @@ class JunctionExpression<T> implements SpiJunction<T>, SpiExpression, Expression
|
||||
return exprList.idEq(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionList<T> idIn(Object... idValues) {
|
||||
return exprList.idIn(idValues);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressionList<T> idIn(List<?> idValues) {
|
||||
return exprList.idIn(idValues);
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package com.avaje.tests.query;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class TestQueryInIdTypeConversion extends BaseTestCase {
|
||||
|
||||
@@ -18,13 +17,8 @@ public class TestQueryInIdTypeConversion extends BaseTestCase {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<String> idList = new ArrayList<String>();
|
||||
idList.add("1");
|
||||
idList.add("2");
|
||||
|
||||
List<Customer> list = Ebean.find(Customer.class).where().idIn(idList).findList();
|
||||
|
||||
Assert.assertNotNull(list);
|
||||
List<Customer> list = Ebean.find(Customer.class).where().idIn("1", "2").findList();
|
||||
|
||||
assertNotNull(list);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user