initial rework for new enhancement

This commit is contained in:
Robin Bygrave committed 2013-06-19 20:36:24 +12:00
1 parent eb1eafe98c
commit 4ec62a5772
193 files changed
+2737 -5285

No files matched your search

@@ -5,6 +5,7 @@ import java.util.Iterator;
import com.avaje.ebean.ExampleExpression;
import com.avaje.ebean.LikeType;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebean.event.BeanQueryRequest;
import com.avaje.ebeaninternal.api.ManyWhereJoins;
import com.avaje.ebeaninternal.api.SpiExpression;
@@ -42,7 +43,7 @@ public class DefaultExampleExpression implements SpiExpression, ExampleExpressio
/**
* The example bean containing the properties.
*/
private final Object entity;
private final EntityBean entity;
/**
* Set to true to use case insensitive expressions.
@@ -77,7 +78,7 @@ public class DefaultExampleExpression implements SpiExpression, ExampleExpressio
* @param likeType
* the type of Like wild card used
*/
public DefaultExampleExpression(FilterExprPath pathPrefix, Object entity, boolean caseInsensitive, LikeType likeType) {
public DefaultExampleExpression(FilterExprPath pathPrefix, EntityBean entity, boolean caseInsensitive, LikeType likeType) {
this.pathPrefix = pathPrefix;
this.entity = entity;
this.caseInsensitive = caseInsensitive;
@@ -11,6 +11,7 @@ import com.avaje.ebean.ExpressionList;
import com.avaje.ebean.Junction;
import com.avaje.ebean.LikeType;
import com.avaje.ebean.Query;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.api.SpiExpressionFactory;
import com.avaje.ebeaninternal.api.SpiQuery;
@@ -135,11 +136,18 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
return new NullExpression(prefix, propertyName, true);
}
private EntityBean checkEntityBean(Object bean) {
if (bean == null || (bean instanceof EntityBean == false)) {
throw new IllegalStateException("Expecting an EntityBean");
}
return (EntityBean)bean;
}
/**
* Case insensitive {@link #exampleLike(Object)}
*/
public ExampleExpression iexampleLike(Object example) {
return new DefaultExampleExpression(prefix, example, true, LikeType.RAW);
return new DefaultExampleExpression(prefix, checkEntityBean(example), true, LikeType.RAW);
}
/**
@@ -147,14 +155,14 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
* LikeType.RAW (you need to add you own wildcards % and _).
*/
public ExampleExpression exampleLike(Object example) {
return new DefaultExampleExpression(prefix, example, false, LikeType.RAW);
return new DefaultExampleExpression(prefix, checkEntityBean(example), false, LikeType.RAW);
}
/**
* Create the query by Example expression specifying more options.
*/
public ExampleExpression exampleLike(Object example, boolean caseInsensitive, LikeType likeType) {
return new DefaultExampleExpression(prefix, example, caseInsensitive, likeType);
return new DefaultExampleExpression(prefix, checkEntityBean(example), caseInsensitive, likeType);
}
/**
@@ -2,6 +2,7 @@ package com.avaje.ebeaninternal.server.expression;
import java.util.Collection;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebean.event.BeanQueryRequest;
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
import com.avaje.ebeaninternal.server.el.ElPropertyValue;
@@ -35,7 +36,7 @@ class InExpression extends AbstractExpression {
} else {
// extract the id values from the bean
Object[] ids = prop.getAssocOneIdValues(values[i]);
Object[] ids = prop.getAssocOneIdValues((EntityBean)values[i]);
if (ids != null) {
for (int j = 0; j < ids.length; j++) {
request.addBindValue(ids[j]);
@@ -1,5 +1,6 @@
package com.avaje.ebeaninternal.server.expression;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebean.event.BeanQueryRequest;
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
import com.avaje.ebeaninternal.server.el.ElPropertyValue;
@@ -47,7 +48,7 @@ public class SimpleExpression extends AbstractExpression implements LuceneAwareE
ElPropertyValue prop = getElProp(request);
if (prop != null) {
if (prop.isAssocId()) {
Object[] ids = prop.getAssocOneIdValues(value);
Object[] ids = prop.getAssocOneIdValues((EntityBean)value);
if (ids != null) {
for (int i = 0; i < ids.length; i++) {
request.addBindValue(ids[i]);