mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#745 - ElasticSearch - internally translate where().id.eq(42) ... to where().setId(42)
This commit is contained in:
+26
-25
@@ -1,8 +1,5 @@
|
||||
package com.avaje.ebeaninternal.server.expression;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.avaje.ebean.ExampleExpression;
|
||||
import com.avaje.ebean.LikeType;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
@@ -12,33 +9,34 @@ import com.avaje.ebeaninternal.api.ManyWhereJoins;
|
||||
import com.avaje.ebeaninternal.api.SpiExpression;
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionValidation;
|
||||
import com.avaje.ebeaninternal.server.core.OrmQueryRequest;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
|
||||
import com.avaje.ebeaninternal.server.query.SplitName;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* A "Query By Example" type of expression.
|
||||
* <p>
|
||||
* Pass in an example entity and for each non-null scalar properties an
|
||||
* expression is added.
|
||||
* </p>
|
||||
*
|
||||
* <pre class="code">
|
||||
* <p>
|
||||
* <pre>{@code
|
||||
* // create an example bean and set the properties
|
||||
* // with the query parameters you want
|
||||
* Customer example = new Customer();
|
||||
* example.setName("Rob%");
|
||||
* example.setNotes("%something%");
|
||||
*
|
||||
* List<Customer> list = Ebean.find(Customer.class).where()
|
||||
* // pass the bean into the where() clause
|
||||
* .exampleLike(example)
|
||||
* // you can add other expressions to the same query
|
||||
* .gt("id", 2).findList();
|
||||
*
|
||||
* </pre>
|
||||
* example.setName("Rob%");
|
||||
* example.setNotes("%something%");
|
||||
*
|
||||
* List<Customer> list = Ebean.find(Customer.class)
|
||||
* .where()
|
||||
* .exampleLike(example)
|
||||
* .findList();
|
||||
*
|
||||
* }</pre>
|
||||
*/
|
||||
public class DefaultExampleExpression implements SpiExpression, ExampleExpression {
|
||||
|
||||
@@ -71,13 +69,10 @@ public class DefaultExampleExpression implements SpiExpression, ExampleExpressio
|
||||
|
||||
/**
|
||||
* Construct the query by example expression.
|
||||
*
|
||||
* @param entity
|
||||
* the example entity with non null property values
|
||||
* @param caseInsensitive
|
||||
* if true use case insensitive expressions
|
||||
* @param likeType
|
||||
* the type of Like wild card used
|
||||
*
|
||||
* @param entity the example entity with non null property values
|
||||
* @param caseInsensitive if true use case insensitive expressions
|
||||
* @param likeType the type of Like wild card used
|
||||
*/
|
||||
public DefaultExampleExpression(EntityBean entity, boolean caseInsensitive, LikeType likeType) {
|
||||
this.entity = entity;
|
||||
@@ -104,6 +99,12 @@ public class DefaultExampleExpression implements SpiExpression, ExampleExpressio
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getIdEqualTo(String idName) {
|
||||
// always return null for this expression
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpiExpression copyForPlanKey() {
|
||||
return new DefaultExampleExpression(list);
|
||||
@@ -295,9 +296,9 @@ public class DefaultExampleExpression implements SpiExpression, ExampleExpressio
|
||||
}
|
||||
|
||||
} else if ((beanProperty instanceof BeanPropertyAssocOne) && (value instanceof EntityBean)) {
|
||||
BeanPropertyAssocOne assocOne = (BeanPropertyAssocOne)beanProperty;
|
||||
BeanPropertyAssocOne assocOne = (BeanPropertyAssocOne) beanProperty;
|
||||
BeanDescriptor targetDescriptor = assocOne.getTargetDescriptor();
|
||||
addExpressions(list, targetDescriptor, (EntityBean)value, propName);
|
||||
addExpressions(list, targetDescriptor, (EntityBean) value, propName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user