diff --git a/src/main/java/com/avaje/ebeaninternal/server/el/CharMatch.java b/src/main/java/com/avaje/ebeaninternal/server/el/CharMatch.java index 48848b5ee..0fb7a43da 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/el/CharMatch.java +++ b/src/main/java/com/avaje/ebeaninternal/server/el/CharMatch.java @@ -1,59 +1,59 @@ -package com.avaje.ebeaninternal.server.el; - -/** - * Case insensitive string matching. - *
- * Provides an alternative to using regular expressions. - *
- */ -public final class CharMatch { - - private final char[] upperChars; - - private final int maxLength; - - public CharMatch(String s) { - this.upperChars = s.toUpperCase().toCharArray(); - this.maxLength = upperChars.length; - } - - public boolean startsWith(String other) { - - if (other == null || other.length() < maxLength){ - return false; - } - - char ta[] = other.toCharArray(); - - int pos = -1; - while (++pos < maxLength) { - char c1 = upperChars[pos]; - char c2 = Character.toUpperCase(ta[pos]); - if (c1 != c2) { - return false; - } - } - return true; - } - - public boolean endsWith(String other) { - - if (other == null || other.length() < maxLength){ - return false; - } - - char ta[] = other.toCharArray(); - - int offset = ta.length - maxLength; - int pos = maxLength; - while (--pos >= 0) { - char c1 = upperChars[pos]; - char c2 = Character.toUpperCase(ta[offset+pos]); - if (c1 != c2) { - return false; - } - } - return true; - } - -} +package com.avaje.ebeaninternal.server.el; + +/** + * Case insensitive string matching. + *+ * Provides an alternative to using regular expressions. + *
+ */ +public final class CharMatch { + + private final char[] upperChars; + + private final int maxLength; + + public CharMatch(String s) { + this.upperChars = s.toUpperCase().toCharArray(); + this.maxLength = upperChars.length; + } + + public boolean startsWith(String other) { + + if (other == null || other.length() < maxLength){ + return false; + } + + char ta[] = other.toCharArray(); + + int pos = -1; + while (++pos < maxLength) { + char c1 = upperChars[pos]; + char c2 = Character.toUpperCase(ta[pos]); + if (c1 != c2) { + return false; + } + } + return true; + } + + public boolean endsWith(String other) { + + if (other == null || other.length() < maxLength){ + return false; + } + + char ta[] = other.toCharArray(); + + int offset = ta.length - maxLength; + int pos = maxLength; + while (--pos >= 0) { + char c1 = upperChars[pos]; + char c2 = Character.toUpperCase(ta[offset+pos]); + if (c1 != c2) { + return false; + } + } + return true; + } + +} diff --git a/src/main/java/com/avaje/ebeaninternal/server/el/ElComparator.java b/src/main/java/com/avaje/ebeaninternal/server/el/ElComparator.java index 13edc5d76..ead232da8 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/el/ElComparator.java +++ b/src/main/java/com/avaje/ebeaninternal/server/el/ElComparator.java @@ -1,20 +1,20 @@ -package com.avaje.ebeaninternal.server.el; - -import java.util.Comparator; - -/** - * Comparator for use with the expression objects. - */ -public interface ElComparator- * eg. "name, orderDate desc, id" - *
- */ -public final class ElComparatorCompound+ * eg. "name, orderDate desc, id" + *
+ */ +public final class ElComparatorCompound- * Used to get the value for an compound expression like customer.name or - * customer.shippingAddress.city etc. - *
- *- * Note that if any element in the chain returns null, then null is returned and - * no further processing of the chain occurs. - *
- */ -public class ElPropertyChain implements ElPropertyValue { - - private final String prefix; - - private final String placeHolder; - private final String placeHolderEncrypted; - - private final String name; - - private final String expression; - - private final boolean containsMany; - - private final ElPropertyValue[] chain; - - private final boolean assocId; - private final int last; - private final BeanProperty lastBeanProperty; - private final ScalarType> scalarType; - - private final ElPropertyValue lastElPropertyValue; - - public ElPropertyChain(boolean containsMany, boolean embedded, String expression, ElPropertyValue[] chain) { - - this.containsMany = containsMany; - this.chain = chain; - this.expression = expression; - int dotPos = expression.lastIndexOf('.'); - if (dotPos > -1){ - this.name = expression.substring(dotPos+1); - if (embedded){ - int embPos = expression.lastIndexOf('.',dotPos-1); - this.prefix = embPos == -1 ? null : expression.substring(0, embPos); - - } else { - this.prefix = expression.substring(0, dotPos); - } - } else { - this.prefix = null; - this.name = expression; - } - - this.assocId = chain[chain.length-1].isAssocId(); - - this.last = chain.length-1; - this.lastBeanProperty = chain[chain.length-1].getBeanProperty(); - if (lastBeanProperty != null){ - this.scalarType = lastBeanProperty.getScalarType(); - } else { - // case for nested compound type (non-scalar) - this.scalarType = null; - } - this.lastElPropertyValue = chain[chain.length-1]; - this.placeHolder = getElPlaceHolder(prefix, lastElPropertyValue, false); - this.placeHolderEncrypted = getElPlaceHolder(prefix, lastElPropertyValue, true); - } - - public String toString() { - return "expr:"+expression+" chain:"+ Arrays.toString(chain); - } - - private String getElPlaceHolder(String prefix, ElPropertyValue lastElPropertyValue, boolean encrypted) { - if (prefix == null){ - return lastElPropertyValue.getElPlaceholder(encrypted); - } - - String el = lastElPropertyValue.getElPlaceholder(encrypted); - - if (!el.contains("${}")){ - // typically a secondary table property - return StringHelper.replaceString(el, "${", "${"+prefix+"."); - } else { - return StringHelper.replaceString(el, ROOT_ELPREFIX, "${"+prefix+"}"); - } - } - - /** - * Full ElGetValue support. - */ - public boolean isDeployOnly() { - return false; - } - - /** - * Return true if there is a many property from sinceProperty to - * the end of this chain. - */ - public boolean containsManySince(String sinceProperty) { - if (sinceProperty == null){ - return containsMany; - } - if (!expression.startsWith(sinceProperty)){ - return containsMany; - } - - int i = 1 + SplitName.count('.', sinceProperty); - - for (; i < chain.length; i++) { - if (chain[i].getBeanProperty().containsMany()) { - return true; - } - } - - return false; - } - - @Override - public boolean containsFormulaWithJoin() { - // Not cascading the check at this stage - return false; - } - - public boolean containsMany() { - return containsMany; - } - - public String getElPrefix() { - return prefix; - } - - public String getName() { - return name; - } - - public String getElName() { - return expression; - } - - public String getElPlaceholder(boolean encrypted) { - return encrypted ? placeHolderEncrypted : placeHolder; - } - - public boolean isDbEncrypted() { - return lastElPropertyValue.isDbEncrypted(); - } - - public boolean isLocalEncrypted() { - return lastElPropertyValue.isLocalEncrypted(); - } - - public Object[] getAssocOneIdValues(EntityBean bean) { - // Don't navigate the object graph as bean - // is assumed to be the appropriate type - return lastElPropertyValue.getAssocOneIdValues(bean); - } - - public String getAssocOneIdExpr(String prefix, String operator) { - return lastElPropertyValue.getAssocOneIdExpr(expression, operator); - } - - public String getAssocIdInExpr(String prefix) { - return lastElPropertyValue.getAssocIdInExpr(prefix); - } - - public String getAssocIdInValueExpr(int size) { - return lastElPropertyValue.getAssocIdInValueExpr(size); - } - - public int getDeployOrder() { - int i = lastBeanProperty.getDeployOrder(); - int max = chain.length-1; - for (int j = 0; j < max; j++) { - int xtra = ((max-j)*1000) * chain[j].getDeployOrder(); - i += xtra; - } - return i; - } - - public boolean isAssocId() { - return assocId; - } - - public boolean isAssocProperty() { - for (int i = 0; i < chain.length; i++) { - if (chain[i].isAssocProperty()){ - return true; - } - } - return false; - } - - public String getDbColumn() { - return lastElPropertyValue.getDbColumn(); - } - - public BeanProperty getBeanProperty() { - return lastBeanProperty; - } - - - public boolean isDateTimeCapable() { - return scalarType != null && scalarType.isDateTimeCapable(); - } - - public int getJdbcType() { - return scalarType == null ? 0 : scalarType.getJdbcType(); - } - - public Object parseDateTime(long systemTimeMillis) { - return scalarType.convertFromMillis(systemTimeMillis); - } - - public StringParser getStringParser() { - return scalarType; - } - - public StringFormatter getStringFormatter() { - return scalarType; - } - - public Object elConvertType(Object value){ - // just convert using the last one in the chain - return lastElPropertyValue.elConvertType(value); - } - - public Object elGetValue(EntityBean bean) { - - for (int i = 0; i < chain.length; i++) { - bean = (EntityBean)chain[i].elGetValue(bean); - if (bean == null) { - return null; - } - } - - return bean; - } - - public Object elGetReference(EntityBean bean) { - - EntityBean prevBean = bean; - for (int i = 0; i < last; i++) { - // always return non null prevBean - prevBean = (EntityBean)chain[i].elGetReference(prevBean); - } - // try the last step in the chain - return chain[last].elGetValue(prevBean); - } - - - public void elSetLoaded(EntityBean bean) { - - for (int i = 0; i < last; i++) { - bean = (EntityBean)chain[i].elGetValue(bean); - if (bean == null){ - break; - } - } - if (bean != null){ - ((EntityBean)bean)._ebean_getIntercept().setLoaded(); - } - } - - 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; - } - } - } - if (prevBean != null){ - if (lastBeanProperty != null){ - // last chain element maps to a real scalar property - lastBeanProperty.setValueIntercept(prevBean, value); - - } else { - // a non-scalar property of a Compound value object - lastElPropertyValue.elSetValue(prevBean, value, populate); - } - } - } - - -} +package com.avaje.ebeaninternal.server.el; + +import com.avaje.ebean.bean.EntityBean; +import com.avaje.ebean.text.StringFormatter; +import com.avaje.ebean.text.StringParser; +import com.avaje.ebeaninternal.server.deploy.BeanProperty; +import com.avaje.ebeaninternal.server.lib.util.StringHelper; +import com.avaje.ebeaninternal.server.query.SplitName; +import com.avaje.ebeaninternal.server.type.ScalarType; + +import java.util.Arrays; + + +/** + * A ElGetValue based on a chain of properties. + *+ * Used to get the value for an compound expression like customer.name or + * customer.shippingAddress.city etc. + *
+ *+ * Note that if any element in the chain returns null, then null is returned and + * no further processing of the chain occurs. + *
+ */ +public class ElPropertyChain implements ElPropertyValue { + + private final String prefix; + + private final String placeHolder; + private final String placeHolderEncrypted; + + private final String name; + + private final String expression; + + private final boolean containsMany; + + private final ElPropertyValue[] chain; + + private final boolean assocId; + private final int last; + private final BeanProperty lastBeanProperty; + private final ScalarType> scalarType; + + private final ElPropertyValue lastElPropertyValue; + + public ElPropertyChain(boolean containsMany, boolean embedded, String expression, ElPropertyValue[] chain) { + + this.containsMany = containsMany; + this.chain = chain; + this.expression = expression; + int dotPos = expression.lastIndexOf('.'); + if (dotPos > -1){ + this.name = expression.substring(dotPos+1); + if (embedded){ + int embPos = expression.lastIndexOf('.',dotPos-1); + this.prefix = embPos == -1 ? null : expression.substring(0, embPos); + + } else { + this.prefix = expression.substring(0, dotPos); + } + } else { + this.prefix = null; + this.name = expression; + } + + this.assocId = chain[chain.length-1].isAssocId(); + + this.last = chain.length-1; + this.lastBeanProperty = chain[chain.length-1].getBeanProperty(); + if (lastBeanProperty != null){ + this.scalarType = lastBeanProperty.getScalarType(); + } else { + // case for nested compound type (non-scalar) + this.scalarType = null; + } + this.lastElPropertyValue = chain[chain.length-1]; + this.placeHolder = getElPlaceHolder(prefix, lastElPropertyValue, false); + this.placeHolderEncrypted = getElPlaceHolder(prefix, lastElPropertyValue, true); + } + + public String toString() { + return "expr:"+expression+" chain:"+ Arrays.toString(chain); + } + + private String getElPlaceHolder(String prefix, ElPropertyValue lastElPropertyValue, boolean encrypted) { + if (prefix == null){ + return lastElPropertyValue.getElPlaceholder(encrypted); + } + + String el = lastElPropertyValue.getElPlaceholder(encrypted); + + if (!el.contains("${}")){ + // typically a secondary table property + return StringHelper.replaceString(el, "${", "${"+prefix+"."); + } else { + return StringHelper.replaceString(el, ROOT_ELPREFIX, "${"+prefix+"}"); + } + } + + /** + * Full ElGetValue support. + */ + public boolean isDeployOnly() { + return false; + } + + /** + * Return true if there is a many property from sinceProperty to + * the end of this chain. + */ + public boolean containsManySince(String sinceProperty) { + if (sinceProperty == null){ + return containsMany; + } + if (!expression.startsWith(sinceProperty)){ + return containsMany; + } + + int i = 1 + SplitName.count('.', sinceProperty); + + for (; i < chain.length; i++) { + if (chain[i].getBeanProperty().containsMany()) { + return true; + } + } + + return false; + } + + @Override + public boolean containsFormulaWithJoin() { + // Not cascading the check at this stage + return false; + } + + public boolean containsMany() { + return containsMany; + } + + public String getElPrefix() { + return prefix; + } + + public String getName() { + return name; + } + + public String getElName() { + return expression; + } + + public String getElPlaceholder(boolean encrypted) { + return encrypted ? placeHolderEncrypted : placeHolder; + } + + public boolean isDbEncrypted() { + return lastElPropertyValue.isDbEncrypted(); + } + + public boolean isLocalEncrypted() { + return lastElPropertyValue.isLocalEncrypted(); + } + + public Object[] getAssocOneIdValues(EntityBean bean) { + // Don't navigate the object graph as bean + // is assumed to be the appropriate type + return lastElPropertyValue.getAssocOneIdValues(bean); + } + + public String getAssocOneIdExpr(String prefix, String operator) { + return lastElPropertyValue.getAssocOneIdExpr(expression, operator); + } + + public String getAssocIdInExpr(String prefix) { + return lastElPropertyValue.getAssocIdInExpr(prefix); + } + + public String getAssocIdInValueExpr(int size) { + return lastElPropertyValue.getAssocIdInValueExpr(size); + } + + public int getDeployOrder() { + int i = lastBeanProperty.getDeployOrder(); + int max = chain.length-1; + for (int j = 0; j < max; j++) { + int xtra = ((max-j)*1000) * chain[j].getDeployOrder(); + i += xtra; + } + return i; + } + + public boolean isAssocId() { + return assocId; + } + + public boolean isAssocProperty() { + for (int i = 0; i < chain.length; i++) { + if (chain[i].isAssocProperty()){ + return true; + } + } + return false; + } + + public String getDbColumn() { + return lastElPropertyValue.getDbColumn(); + } + + public BeanProperty getBeanProperty() { + return lastBeanProperty; + } + + + public boolean isDateTimeCapable() { + return scalarType != null && scalarType.isDateTimeCapable(); + } + + public int getJdbcType() { + return scalarType == null ? 0 : scalarType.getJdbcType(); + } + + public Object parseDateTime(long systemTimeMillis) { + return scalarType.convertFromMillis(systemTimeMillis); + } + + public StringParser getStringParser() { + return scalarType; + } + + public StringFormatter getStringFormatter() { + return scalarType; + } + + public Object elConvertType(Object value){ + // just convert using the last one in the chain + return lastElPropertyValue.elConvertType(value); + } + + public Object elGetValue(EntityBean bean) { + + for (int i = 0; i < chain.length; i++) { + bean = (EntityBean)chain[i].elGetValue(bean); + if (bean == null) { + return null; + } + } + + return bean; + } + + public Object elGetReference(EntityBean bean) { + + EntityBean prevBean = bean; + for (int i = 0; i < last; i++) { + // always return non null prevBean + prevBean = (EntityBean)chain[i].elGetReference(prevBean); + } + // try the last step in the chain + return chain[last].elGetValue(prevBean); + } + + + public void elSetLoaded(EntityBean bean) { + + for (int i = 0; i < last; i++) { + bean = (EntityBean)chain[i].elGetValue(bean); + if (bean == null){ + break; + } + } + if (bean != null){ + ((EntityBean)bean)._ebean_getIntercept().setLoaded(); + } + } + + 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; + } + } + } + if (prevBean != null){ + if (lastBeanProperty != null){ + // last chain element maps to a real scalar property + lastBeanProperty.setValueIntercept(prevBean, value); + + } else { + // a non-scalar property of a Compound value object + lastElPropertyValue.elSetValue(prevBean, value, populate); + } + } + } + + +} diff --git a/src/main/java/com/avaje/ebeaninternal/server/el/ElPropertyChainBuilder.java b/src/main/java/com/avaje/ebeaninternal/server/el/ElPropertyChainBuilder.java index 49387b63b..60e5e252c 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/el/ElPropertyChainBuilder.java +++ b/src/main/java/com/avaje/ebeaninternal/server/el/ElPropertyChainBuilder.java @@ -1,64 +1,64 @@ -package com.avaje.ebeaninternal.server.el; - -import java.util.ArrayList; -import java.util.List; - -/** - * Utility object used to build a ElPropertyChain. - *- * Builds a ElPropertyChain based on a chain of properties with dot separators. - *
- *- * This can navigate an object graph based on dot notation such as - * order.customer.name. - *
- */ -public class ElPropertyChainBuilder { - - private final String expression; - - private final List+ * Builds a ElPropertyChain based on a chain of properties with dot separators. + *
+ *+ * This can navigate an object graph based on dot notation such as + * order.customer.name. + *
+ */ +public class ElPropertyChainBuilder { + + private final String expression; + + private final List- * This can be used for local sorting and filtering. - *
- */ -public interface ElPropertyValue extends ElPropertyDeploy { - - /** - * Return the Id values for the given bean value. - */ - public Object[] getAssocOneIdValues(EntityBean bean); - - /** - * Return the Id expression string. - *- * Typically used to produce id = ? expression strings. - *
- */ - public String getAssocOneIdExpr(String prefix, String operator); - - /** - * Return the logical id value expression taking into account embedded id's. - */ - public String getAssocIdInValueExpr(int size); - - /** - * Return the logical id in expression taking into account embedded id's. - */ - public String getAssocIdInExpr(String prefix); - - /** - * Return true if this is an ManyToOne or OneToOne associated bean property. - */ - public boolean isAssocId(); - - /** - * Return true if any path of this path contains a Associated One or Many. - */ - public boolean isAssocProperty(); - - /** - * Return true if the property is encrypted via Java. - */ - public boolean isLocalEncrypted(); - - /** - * Return true if the property is encrypted in the DB. - */ - public boolean isDbEncrypted(); - - /** - * Return the deploy order for the property. - */ - public int getDeployOrder(); - - /** - * Return the default StringParser for the scalar property. - */ - public StringParser getStringParser(); - - /** - * Return the default StringFormatter for the scalar property. - */ - public StringFormatter getStringFormatter(); - - /** - * Return true if the last type is "DateTime capable" - can support - * {@link #parseDateTime(long)}. - */ - public boolean isDateTimeCapable(); - - /** - * Return the underlying JDBC type or 0 if this is not a scalar type. - */ - public int getJdbcType(); - - /** - * For DateTime capable scalar types convert the long systemTimeMillis into - * an appropriate java time (Date,Timestamp,Time,Calendar, JODA type etc). - */ - public Object parseDateTime(long systemTimeMillis); - - /** - * Return the value from a given entity bean. - */ - public Object elGetValue(EntityBean bean); - - /** - * Return the value ensuring objects prior to the top scalar property are - * automatically populated. - */ - public Object elGetReference(EntityBean bean); - - /** - * Set a value given a root level bean. - *- * If populate then - *
- */ - public void elSetValue(EntityBean bean, Object value, boolean populate); - - /** - * Convert the value to the expected type. - *- * Typically useful for converting strings to the appropriate number type - * etc. - *
- */ - public Object elConvertType(Object value); -} +package com.avaje.ebeaninternal.server.el; + +import com.avaje.ebean.bean.EntityBean; +import com.avaje.ebean.text.StringFormatter; +import com.avaje.ebean.text.StringParser; + +/** + * The expression language object that can get values. + *+ * This can be used for local sorting and filtering. + *
+ */ +public interface ElPropertyValue extends ElPropertyDeploy { + + /** + * Return the Id values for the given bean value. + */ + public Object[] getAssocOneIdValues(EntityBean bean); + + /** + * Return the Id expression string. + *+ * Typically used to produce id = ? expression strings. + *
+ */ + public String getAssocOneIdExpr(String prefix, String operator); + + /** + * Return the logical id value expression taking into account embedded id's. + */ + public String getAssocIdInValueExpr(int size); + + /** + * Return the logical id in expression taking into account embedded id's. + */ + public String getAssocIdInExpr(String prefix); + + /** + * Return true if this is an ManyToOne or OneToOne associated bean property. + */ + public boolean isAssocId(); + + /** + * Return true if any path of this path contains a Associated One or Many. + */ + public boolean isAssocProperty(); + + /** + * Return true if the property is encrypted via Java. + */ + public boolean isLocalEncrypted(); + + /** + * Return true if the property is encrypted in the DB. + */ + public boolean isDbEncrypted(); + + /** + * Return the deploy order for the property. + */ + public int getDeployOrder(); + + /** + * Return the default StringParser for the scalar property. + */ + public StringParser getStringParser(); + + /** + * Return the default StringFormatter for the scalar property. + */ + public StringFormatter getStringFormatter(); + + /** + * Return true if the last type is "DateTime capable" - can support + * {@link #parseDateTime(long)}. + */ + public boolean isDateTimeCapable(); + + /** + * Return the underlying JDBC type or 0 if this is not a scalar type. + */ + public int getJdbcType(); + + /** + * For DateTime capable scalar types convert the long systemTimeMillis into + * an appropriate java time (Date,Timestamp,Time,Calendar, JODA type etc). + */ + public Object parseDateTime(long systemTimeMillis); + + /** + * Return the value from a given entity bean. + */ + public Object elGetValue(EntityBean bean); + + /** + * Return the value ensuring objects prior to the top scalar property are + * automatically populated. + */ + public Object elGetReference(EntityBean bean); + + /** + * Set a value given a root level bean. + *+ * If populate then + *
+ */ + public void elSetValue(EntityBean bean, Object value, boolean populate); + + /** + * Convert the value to the expected type. + *+ * Typically useful for converting strings to the appropriate number type + * etc. + *
+ */ + public Object elConvertType(Object value); +} diff --git a/src/main/java/com/avaje/ebeaninternal/server/el/ElSetValue.java b/src/main/java/com/avaje/ebeaninternal/server/el/ElSetValue.java index 0a14caabc..d1f7a79b6 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/el/ElSetValue.java +++ b/src/main/java/com/avaje/ebeaninternal/server/el/ElSetValue.java @@ -1,10 +1,10 @@ -package com.avaje.ebeaninternal.server.el; - -public interface ElSetValue { - - /** - * Set the value to the bean. - */ - public void elSetValue(Object bean, Object value); - -} +package com.avaje.ebeaninternal.server.el; + +public interface ElSetValue { + + /** + * Set the value to the bean. + */ + public void elSetValue(Object bean, Object value); + +} diff --git a/src/main/java/com/avaje/ebeaninternal/server/expression/AbstractExpression.java b/src/main/java/com/avaje/ebeaninternal/server/expression/AbstractExpression.java index 2642d4282..530390cf8 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/expression/AbstractExpression.java +++ b/src/main/java/com/avaje/ebeaninternal/server/expression/AbstractExpression.java @@ -1,52 +1,52 @@ -package com.avaje.ebeaninternal.server.expression; - -import com.avaje.ebeaninternal.api.ManyWhereJoins; -import com.avaje.ebeaninternal.api.SpiExpression; -import com.avaje.ebeaninternal.api.SpiExpressionRequest; -import com.avaje.ebeaninternal.server.deploy.BeanDescriptor; -import com.avaje.ebeaninternal.server.el.ElPropertyDeploy; -import com.avaje.ebeaninternal.server.el.ElPropertyValue; - -/** - * Base class for simple expressions. - * - * @author rbygrave - */ -public abstract class AbstractExpression implements SpiExpression { - - private static final long serialVersionUID = 4072786211853856174L; - - protected final String propName; - - protected AbstractExpression(String propName) { - this.propName = propName; - } - - public String getPropertyName() { - return propName; - } - - public void containsMany(BeanDescriptor> desc, ManyWhereJoins manyWhereJoin) { - - String propertyName = getPropertyName(); - if (propertyName != null) { - ElPropertyDeploy elProp = desc.getElPropertyDeploy(propertyName); - if (elProp != null) { - if (elProp.containsFormulaWithJoin()) { - // for findRowCount query select clause - manyWhereJoin.addFormulaWithJoin(propertyName); - } - if (elProp.containsMany()) { - // for findRowCount we join to a many property - manyWhereJoin.add(elProp); - } - } - } - } - - protected ElPropertyValue getElProp(SpiExpressionRequest request) { - - String propertyName = getPropertyName(); - return request.getBeanDescriptor().getElGetValue(propertyName); - } -} +package com.avaje.ebeaninternal.server.expression; + +import com.avaje.ebeaninternal.api.ManyWhereJoins; +import com.avaje.ebeaninternal.api.SpiExpression; +import com.avaje.ebeaninternal.api.SpiExpressionRequest; +import com.avaje.ebeaninternal.server.deploy.BeanDescriptor; +import com.avaje.ebeaninternal.server.el.ElPropertyDeploy; +import com.avaje.ebeaninternal.server.el.ElPropertyValue; + +/** + * Base class for simple expressions. + * + * @author rbygrave + */ +public abstract class AbstractExpression implements SpiExpression { + + private static final long serialVersionUID = 4072786211853856174L; + + protected final String propName; + + protected AbstractExpression(String propName) { + this.propName = propName; + } + + public String getPropertyName() { + return propName; + } + + public void containsMany(BeanDescriptor> desc, ManyWhereJoins manyWhereJoin) { + + String propertyName = getPropertyName(); + if (propertyName != null) { + ElPropertyDeploy elProp = desc.getElPropertyDeploy(propertyName); + if (elProp != null) { + if (elProp.containsFormulaWithJoin()) { + // for findRowCount query select clause + manyWhereJoin.addFormulaWithJoin(propertyName); + } + if (elProp.containsMany()) { + // for findRowCount we join to a many property + manyWhereJoin.add(elProp); + } + } + } + } + + protected ElPropertyValue getElProp(SpiExpressionRequest request) { + + String propertyName = getPropertyName(); + return request.getBeanDescriptor().getElGetValue(propertyName); + } +} diff --git a/src/main/java/com/avaje/ebeaninternal/server/expression/BetweenPropertyExpression.java b/src/main/java/com/avaje/ebeaninternal/server/expression/BetweenPropertyExpression.java index 232ac64c9..b4562bc51 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/expression/BetweenPropertyExpression.java +++ b/src/main/java/com/avaje/ebeaninternal/server/expression/BetweenPropertyExpression.java @@ -1,68 +1,68 @@ -package com.avaje.ebeaninternal.server.expression; - -import com.avaje.ebean.event.BeanQueryRequest; -import com.avaje.ebeaninternal.api.HashQueryPlanBuilder; -import com.avaje.ebeaninternal.api.ManyWhereJoins; -import com.avaje.ebeaninternal.api.SpiExpression; -import com.avaje.ebeaninternal.api.SpiExpressionRequest; -import com.avaje.ebeaninternal.server.deploy.BeanDescriptor; -import com.avaje.ebeaninternal.server.el.ElPropertyDeploy; - -/** - * Between expression where a value is between two properties. - */ -class BetweenPropertyExpression implements SpiExpression { - - private static final long serialVersionUID = 2078918165221454910L; - - private static final String BETWEEN = " between "; - - private final String lowProperty; - private final String highProperty; - private final Object value; - - BetweenPropertyExpression(String lowProperty, String highProperty, Object value) { - this.lowProperty = lowProperty; - this.highProperty = highProperty; - this.value = value; - } - - protected String name(String propName) { - return propName; - } - - public void containsMany(BeanDescriptor> desc, ManyWhereJoins manyWhereJoin) { - - ElPropertyDeploy elProp = desc.getElPropertyDeploy(name(lowProperty)); - if (elProp != null && elProp.containsMany()) { - manyWhereJoin.add(elProp); - } - - elProp = desc.getElPropertyDeploy(name(highProperty)); - if (elProp != null && elProp.containsMany()) { - manyWhereJoin.add(elProp); - } - } - - public void addBindValues(SpiExpressionRequest request) { - request.addBindValue(value); - } - - public void addSql(SpiExpressionRequest request) { - - request.append(" ? ").append(BETWEEN).append(name(lowProperty)).append(" and ").append(name(highProperty)); - } - - public void queryAutoFetchHash(HashQueryPlanBuilder builder) { - builder.add(BetweenPropertyExpression.class).add(lowProperty).add(highProperty); - builder.bind(1); - } - - public void queryPlanHash(BeanQueryRequest> request, HashQueryPlanBuilder builder) { - queryAutoFetchHash(builder); - } - - public int queryBindHash() { - return value.hashCode(); - } -} +package com.avaje.ebeaninternal.server.expression; + +import com.avaje.ebean.event.BeanQueryRequest; +import com.avaje.ebeaninternal.api.HashQueryPlanBuilder; +import com.avaje.ebeaninternal.api.ManyWhereJoins; +import com.avaje.ebeaninternal.api.SpiExpression; +import com.avaje.ebeaninternal.api.SpiExpressionRequest; +import com.avaje.ebeaninternal.server.deploy.BeanDescriptor; +import com.avaje.ebeaninternal.server.el.ElPropertyDeploy; + +/** + * Between expression where a value is between two properties. + */ +class BetweenPropertyExpression implements SpiExpression { + + private static final long serialVersionUID = 2078918165221454910L; + + private static final String BETWEEN = " between "; + + private final String lowProperty; + private final String highProperty; + private final Object value; + + BetweenPropertyExpression(String lowProperty, String highProperty, Object value) { + this.lowProperty = lowProperty; + this.highProperty = highProperty; + this.value = value; + } + + protected String name(String propName) { + return propName; + } + + public void containsMany(BeanDescriptor> desc, ManyWhereJoins manyWhereJoin) { + + ElPropertyDeploy elProp = desc.getElPropertyDeploy(name(lowProperty)); + if (elProp != null && elProp.containsMany()) { + manyWhereJoin.add(elProp); + } + + elProp = desc.getElPropertyDeploy(name(highProperty)); + if (elProp != null && elProp.containsMany()) { + manyWhereJoin.add(elProp); + } + } + + public void addBindValues(SpiExpressionRequest request) { + request.addBindValue(value); + } + + public void addSql(SpiExpressionRequest request) { + + request.append(" ? ").append(BETWEEN).append(name(lowProperty)).append(" and ").append(name(highProperty)); + } + + public void queryAutoFetchHash(HashQueryPlanBuilder builder) { + builder.add(BetweenPropertyExpression.class).add(lowProperty).add(highProperty); + builder.bind(1); + } + + public void queryPlanHash(BeanQueryRequest> request, HashQueryPlanBuilder builder) { + queryAutoFetchHash(builder); + } + + public int queryBindHash() { + return value.hashCode(); + } +} diff --git a/src/main/java/com/avaje/ebeaninternal/server/expression/FilterExprPath.java b/src/main/java/com/avaje/ebeaninternal/server/expression/FilterExprPath.java index 89b06f168..a60d6e031 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/expression/FilterExprPath.java +++ b/src/main/java/com/avaje/ebeaninternal/server/expression/FilterExprPath.java @@ -1,43 +1,43 @@ -package com.avaje.ebeaninternal.server.expression; - -import java.io.Serializable; - -/** - * This is the path prefix for filterMany. - *- * The actual path can change due to FetchConfig query joins that proceed the - * query that includes the filterMany. - *
- */ -public class FilterExprPath implements Serializable { - - private static final long serialVersionUID = -6420905565372842018L; - - /** - * The path of the filterMany. - */ - private String path; - - public FilterExprPath(String path) { - this.path = path; - } - - /** - * Return a copy of the FilterExprPath trimming off leading part of the path - * due to a proceeding (earlier) query join etc. - */ - public FilterExprPath trimPath(int prefixTrim) { - if (prefixTrim >= path.length()) { - return new FilterExprPath(null); - } - return new FilterExprPath(path.substring(prefixTrim)); - } - - /** - * Return the path. This is a prefix used in the filterMany expressions. - */ - public String getPath() { - return path; - } - -} +package com.avaje.ebeaninternal.server.expression; + +import java.io.Serializable; + +/** + * This is the path prefix for filterMany. + *+ * The actual path can change due to FetchConfig query joins that proceed the + * query that includes the filterMany. + *
+ */ +public class FilterExprPath implements Serializable { + + private static final long serialVersionUID = -6420905565372842018L; + + /** + * The path of the filterMany. + */ + private String path; + + public FilterExprPath(String path) { + this.path = path; + } + + /** + * Return a copy of the FilterExprPath trimming off leading part of the path + * due to a proceeding (earlier) query join etc. + */ + public FilterExprPath trimPath(int prefixTrim) { + if (prefixTrim >= path.length()) { + return new FilterExprPath(null); + } + return new FilterExprPath(path.substring(prefixTrim)); + } + + /** + * Return the path. This is a prefix used in the filterMany expressions. + */ + public String getPath() { + return path; + } + +}