#616 - ElasticSearch expression - IllegalArgumentException: unhandled type class org.example.domain.Customer

This commit is contained in:
Robin Bygrave
2016-03-23 18:08:37 +13:00
parent a9d7ea0299
commit a227f8c469
4 changed files with 36 additions and 15 deletions
@@ -1,5 +1,6 @@
package com.avaje.ebean.plugin;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebean.text.StringParser;
/**
@@ -54,4 +55,22 @@ public interface ExpressionPath {
* Return the underlying JDBC type or 0 if this is not a scalar type.
*/
int getJdbcType();
/**
* Return true if this is an ManyToOne or OneToOne associated bean property.
*/
boolean isAssocId();
/**
* Return the Id expression string.
* <p>
* Typically used to produce id = ? expression strings.
* </p>
*/
String getAssocOneIdExpr(String propName, String bindOperator);
/**
* Return the Id values for the given bean value.
*/
Object[] getAssocOneIdValues(EntityBean bean);
}
@@ -1,6 +1,5 @@
package com.avaje.ebeaninternal.server.el;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebean.plugin.ExpressionPath;
/**
@@ -11,19 +10,6 @@ import com.avaje.ebean.plugin.ExpressionPath;
*/
public interface ElPropertyValue extends ElPropertyDeploy, ExpressionPath {
/**
* Return the Id values for the given bean value.
*/
Object[] getAssocOneIdValues(EntityBean bean);
/**
* Return the Id expression string.
* <p>
* Typically used to produce id = ? expression strings.
* </p>
*/
String getAssocOneIdExpr(String prefix, String operator);
/**
* Return the logical id value expression taking into account embedded id's.
*/
@@ -2,6 +2,7 @@ package com.avaje.ebeaninternal.server.expression;
import com.avaje.ebean.Junction;
import com.avaje.ebean.LikeType;
import com.avaje.ebean.plugin.ExpressionPath;
import com.avaje.ebean.search.Match;
import com.avaje.ebean.search.MultiMatch;
import com.avaje.ebean.search.TextCommonTerms;
@@ -142,4 +143,8 @@ public interface DocQueryContext {
*/
void endBoolGroup() throws IOException;
/**
* Return the expression path for the given property path.
*/
ExpressionPath getExpressionPath(String propName);
}
@@ -1,6 +1,7 @@
package com.avaje.ebeaninternal.server.expression;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebean.plugin.ExpressionPath;
import com.avaje.ebeaninternal.api.HashQueryPlanBuilder;
import com.avaje.ebeaninternal.api.SpiExpression;
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
@@ -25,7 +26,17 @@ public class SimpleExpression extends AbstractExpression {
if (type == Op.BETWEEN) {
throw new IllegalStateException("BETWEEN Not expected in SimpleExpression?");
}
context.writeSimple(type, propName, value);
ExpressionPath prop = context.getExpressionPath(propName);
if (prop != null && prop.isAssocId()) {
String idName = prop.getAssocOneIdExpr(propName, "");
Object[] ids = prop.getAssocOneIdValues((EntityBean) value);
if (ids == null || ids.length != 1) {
throw new IllegalArgumentException("Expecting 1 Id value for " + idName + " but got " + ids);
}
context.writeSimple(type, idName, ids[0]);
} else {
context.writeSimple(type, propName, value);
}
}
public final String getPropName() {