mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1205 - ENH: Add support for raw expression array binding with Postgres - e.g. raw(" foo = any(?) ", collection)
This commit is contained in:
@@ -5,8 +5,10 @@ import io.ebeaninternal.api.SpiExpression;
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
import io.ebeaninternal.api.SpiExpressionValidation;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import io.ebeaninternal.server.persist.MultiValueWrapper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
class RawExpression extends NonPrepareExpression {
|
||||
|
||||
@@ -43,7 +45,12 @@ class RawExpression extends NonPrepareExpression {
|
||||
public void addBindValues(SpiExpressionRequest request) {
|
||||
if (values != null) {
|
||||
for (Object value : values) {
|
||||
request.addBindValue(value);
|
||||
if (value instanceof Collection<?>) {
|
||||
// support for Postgres = any(?) type raw expression
|
||||
request.addBindValue(new MultiValueWrapper((Collection<?>)value));
|
||||
} else {
|
||||
request.addBindValue(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,17 @@ import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.Expr;
|
||||
import io.ebean.Query;
|
||||
import io.ebean.annotation.ForPlatform;
|
||||
import io.ebean.annotation.Platform;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.Order;
|
||||
import org.tests.model.basic.OrderDetail;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -45,6 +50,25 @@ public class TestWhereRawClause extends BaseTestCase {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@ForPlatform(Platform.POSTGRES)
|
||||
public void testRawPostgresArray() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<String> names = new ArrayList<>();
|
||||
names.add("Rob");
|
||||
names.add("Fiona");
|
||||
|
||||
List<Customer> list = Ebean.find(Customer.class)
|
||||
.where()
|
||||
.raw("name = any(?)", names)
|
||||
.findList();
|
||||
|
||||
assertThat(list).isNotEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRawWithBindParams() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user