mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-18 14:58:47 +00:00
#593 - Refactor SPI - Move methods from ElPropertyValue to ExpressionPath
This commit is contained in:
1 parent
3ba4660bbb
commit
583fc11945
24 files changed
+447
-272
No files matched your search
@@ -2,8 +2,6 @@ package com.avaje.ebeaninternal.server.el;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
|
||||
/**
|
||||
* Comparator based on a ElGetValue.
|
||||
*/
|
||||
@@ -23,16 +21,14 @@ public final class ElComparatorProperty<T> implements Comparator<T>, ElComparato
|
||||
|
||||
public int compare(T o1, T o2) {
|
||||
|
||||
Object val1 = elGetValue.elGetValue((EntityBean) o1);
|
||||
Object val2 = elGetValue.elGetValue((EntityBean) o2);
|
||||
|
||||
Object val1 = elGetValue.pathGet(o1);
|
||||
Object val2 = elGetValue.pathGet(o2);
|
||||
return compareValues(val1, val2);
|
||||
}
|
||||
|
||||
public int compareValue(Object value, T o2) {
|
||||
|
||||
Object val2 = elGetValue.elGetValue((EntityBean) o2);
|
||||
|
||||
Object val2 = elGetValue.pathGet(o2);
|
||||
return compareValues(value, val2);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public final class ElFilter<T> implements Filter<T> {
|
||||
private Object convertValue(String propertyName, Object value) {
|
||||
// convert type of value to match expected type
|
||||
ElPropertyValue elGetValue = beanDescriptor.getElGetValue(propertyName);
|
||||
return elGetValue.elConvertType(value);
|
||||
return elGetValue.convert(value);
|
||||
}
|
||||
|
||||
private ElComparator<T> getElComparator(String propertyName) {
|
||||
@@ -87,8 +87,8 @@ public final class ElFilter<T> implements Filter<T> {
|
||||
public Filter<T> between(String propertyName, Object min, Object max) {
|
||||
|
||||
ElPropertyValue elGetValue = getElGetValue(propertyName);
|
||||
min = elGetValue.elConvertType(min);
|
||||
max = elGetValue.elConvertType(max);
|
||||
min = elGetValue.convert(min);
|
||||
max = elGetValue.convert(max);
|
||||
|
||||
ElComparator<T> elComparator = getElComparator(propertyName);
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ class ElMatchBuilder {
|
||||
}
|
||||
|
||||
public boolean isMatch(T bean) {
|
||||
String v = (String) elGetValue.elGetValue((EntityBean) bean);
|
||||
String v = (String) elGetValue.pathGet(bean);
|
||||
return pattern.matcher(v).matches();
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ class ElMatchBuilder {
|
||||
}
|
||||
|
||||
public boolean isMatch(T bean) {
|
||||
String v = (String) elGetValue.elGetValue((EntityBean) bean);
|
||||
String v = (String) elGetValue.pathGet(bean);
|
||||
return value.equalsIgnoreCase(v);
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,7 @@ class ElMatchBuilder {
|
||||
|
||||
public boolean isMatch(T bean) {
|
||||
|
||||
String v = (String) elGetValue.elGetValue((EntityBean) bean);
|
||||
String v = (String) elGetValue.pathGet(bean);
|
||||
return charMatch.startsWith(v);
|
||||
}
|
||||
}
|
||||
@@ -95,7 +95,7 @@ class ElMatchBuilder {
|
||||
|
||||
public boolean isMatch(T bean) {
|
||||
|
||||
String v = (String) elGetValue.elGetValue((EntityBean) bean);
|
||||
String v = (String) elGetValue.pathGet(bean);
|
||||
return charMatch.endsWith(v);
|
||||
}
|
||||
}
|
||||
@@ -106,7 +106,7 @@ class ElMatchBuilder {
|
||||
}
|
||||
|
||||
public boolean isMatch(T bean) {
|
||||
String v = (String) elGetValue.elGetValue((EntityBean) bean);
|
||||
String v = (String) elGetValue.pathGet(bean);
|
||||
return value.startsWith(v);
|
||||
}
|
||||
}
|
||||
@@ -117,7 +117,7 @@ class ElMatchBuilder {
|
||||
}
|
||||
|
||||
public boolean isMatch(T bean) {
|
||||
String v = (String) elGetValue.elGetValue((EntityBean) bean);
|
||||
String v = (String) elGetValue.pathGet(bean);
|
||||
return value.endsWith(v);
|
||||
}
|
||||
}
|
||||
@@ -131,7 +131,7 @@ class ElMatchBuilder {
|
||||
}
|
||||
|
||||
public boolean isMatch(T bean) {
|
||||
return (null == elGetValue.elGetValue((EntityBean) bean));
|
||||
return (null == elGetValue.pathGet(bean));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ class ElMatchBuilder {
|
||||
}
|
||||
|
||||
public boolean isMatch(T bean) {
|
||||
return (null != elGetValue.elGetValue((EntityBean) bean));
|
||||
return (null != elGetValue.pathGet(bean));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ class ElMatchBuilder {
|
||||
|
||||
public boolean isMatch(T bean) {
|
||||
|
||||
Object value = elGetValue.elGetValue((EntityBean) bean);
|
||||
Object value = elGetValue.pathGet(bean);
|
||||
return value != null && set.contains(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,20 +220,19 @@ public class ElPropertyChain implements ElPropertyValue {
|
||||
return scalarType;
|
||||
}
|
||||
|
||||
public Object elConvertType(Object value) {
|
||||
public Object convert(Object value) {
|
||||
// just convert using the last one in the chain
|
||||
return lastElPropertyValue.elConvertType(value);
|
||||
return lastElPropertyValue.convert(value);
|
||||
}
|
||||
|
||||
public Object elGetValue(EntityBean bean) {
|
||||
|
||||
@Override
|
||||
public Object pathGet(Object bean) {
|
||||
for (int i = 0; i < chain.length; i++) {
|
||||
bean = (EntityBean) chain[i].elGetValue(bean);
|
||||
bean = chain[i].pathGet(bean);
|
||||
if (bean == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return bean;
|
||||
}
|
||||
|
||||
@@ -245,39 +244,25 @@ public class ElPropertyChain implements ElPropertyValue {
|
||||
prevBean = (EntityBean) chain[i].elGetReference(prevBean);
|
||||
}
|
||||
// try the last step in the chain
|
||||
return chain[last].elGetValue(prevBean);
|
||||
return chain[last].pathGet(prevBean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(Object bean, Object value) {
|
||||
elSetValue((EntityBean)bean, value, true);
|
||||
}
|
||||
public void pathSet(Object bean, Object value) {
|
||||
|
||||
public void elSetValue(EntityBean bean, Object value, boolean populate) {
|
||||
|
||||
EntityBean prevBean = bean;
|
||||
if (populate) {
|
||||
for (int i = 0; i < last; i++) {
|
||||
// always return non null prevBean
|
||||
prevBean = (EntityBean) chain[i].elGetReference(prevBean);
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < last; i++) {
|
||||
// always return non null prevBean
|
||||
prevBean = (EntityBean) chain[i].elGetValue(prevBean);
|
||||
if (prevBean == null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
EntityBean prevBean = (EntityBean)bean;
|
||||
for (int i = 0; i < last; i++) {
|
||||
// always return non null prevBean
|
||||
prevBean = (EntityBean) chain[i].elGetReference(prevBean);
|
||||
}
|
||||
if (prevBean != null) {
|
||||
if (lastBeanProperty != null) {
|
||||
// last chain element maps to a real scalar property
|
||||
lastBeanProperty.setValueIntercept(prevBean, value);
|
||||
lastBeanProperty.pathSet(prevBean, value);
|
||||
|
||||
} else {
|
||||
// a non-scalar property of a Compound value object
|
||||
lastElPropertyValue.elSetValue(prevBean, value, populate);
|
||||
lastElPropertyValue.pathSet(prevBean, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,53 +60,10 @@ public interface ElPropertyValue extends ElPropertyDeploy, ExpressionPath {
|
||||
*/
|
||||
int getDeployOrder();
|
||||
|
||||
/**
|
||||
* Return the default StringParser for the scalar property.
|
||||
*/
|
||||
StringParser getStringParser();
|
||||
|
||||
/**
|
||||
* Return true if the last type is "DateTime capable" - can support
|
||||
* {@link #parseDateTime(long)}.
|
||||
*/
|
||||
boolean isDateTimeCapable();
|
||||
|
||||
/**
|
||||
* Return the underlying JDBC type or 0 if this is not a scalar type.
|
||||
*/
|
||||
int getJdbcType();
|
||||
|
||||
/**
|
||||
* For DateTime capable scalar types convert the long systemTimeMillis into
|
||||
* an appropriate java time (Date,Timestamp,Time,Calendar, JODA type etc).
|
||||
*/
|
||||
Object parseDateTime(long systemTimeMillis);
|
||||
|
||||
/**
|
||||
* Return the value from a given entity bean.
|
||||
*/
|
||||
Object elGetValue(EntityBean bean);
|
||||
|
||||
/**
|
||||
* Return the value ensuring objects prior to the top scalar property are
|
||||
* automatically populated.
|
||||
*/
|
||||
Object elGetReference(EntityBean bean);
|
||||
|
||||
/**
|
||||
* Set a value given a root level bean.
|
||||
* <p>
|
||||
* If populate then
|
||||
* </p>
|
||||
*/
|
||||
void elSetValue(EntityBean bean, Object value, boolean populate);
|
||||
|
||||
/**
|
||||
* Convert the value to the expected type.
|
||||
* <p>
|
||||
* Typically useful for converting strings to the appropriate number type
|
||||
* etc.
|
||||
* </p>
|
||||
*/
|
||||
Object elConvertType(Object value);
|
||||
}
|
||||
Reference in new issue
Block a user