mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#2318 - Refactor internals - final classes in expression packages
This commit is contained in:
@@ -14,7 +14,7 @@ import io.ebeaninternal.api.NaturalKeyQueryData;
|
||||
/**
|
||||
* Base class for simple expressions.
|
||||
*/
|
||||
public abstract class AbstractExpression implements SpiExpression {
|
||||
abstract class AbstractExpression implements SpiExpression {
|
||||
|
||||
protected String propName;
|
||||
|
||||
@@ -66,7 +66,6 @@ public abstract class AbstractExpression implements SpiExpression {
|
||||
|
||||
@Override
|
||||
public void containsMany(BeanDescriptor<?> desc, ManyWhereJoins manyWhereJoin) {
|
||||
|
||||
propertyContainsMany(propName, desc, manyWhereJoin);
|
||||
}
|
||||
|
||||
@@ -103,7 +102,6 @@ public abstract class AbstractExpression implements SpiExpression {
|
||||
}
|
||||
|
||||
protected final ElPropertyValue getElProp(SpiExpressionRequest request) {
|
||||
|
||||
return request.getBeanDescriptor().getElGetValue(propName);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
* This means they can not be part of a SQL query nor do they use the built in query plan cache etc.
|
||||
* </p>
|
||||
*/
|
||||
public abstract class AbstractTextExpression extends AbstractExpression {
|
||||
abstract class AbstractTextExpression extends AbstractExpression {
|
||||
|
||||
AbstractTextExpression(String propName) {
|
||||
super(propName);
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ package io.ebeaninternal.server.expression;
|
||||
/**
|
||||
* Abstract expression that helps with named parameter use.
|
||||
*/
|
||||
public abstract class AbstractValueExpression extends AbstractExpression {
|
||||
abstract class AbstractValueExpression extends AbstractExpression {
|
||||
|
||||
protected final Object bindValue;
|
||||
|
||||
|
||||
+2
-15
@@ -13,7 +13,7 @@ import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
class AllEqualsExpression extends NonPrepareExpression {
|
||||
final class AllEqualsExpression extends NonPrepareExpression {
|
||||
|
||||
private final Map<String, Object> propMap;
|
||||
|
||||
@@ -21,7 +21,7 @@ class AllEqualsExpression extends NonPrepareExpression {
|
||||
this.propMap = propMap;
|
||||
}
|
||||
|
||||
protected String name(String propName) {
|
||||
String name(String propName) {
|
||||
return propName;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,6 @@ class AllEqualsExpression extends NonPrepareExpression {
|
||||
|
||||
@Override
|
||||
public void addBindValues(SpiExpressionRequest request) {
|
||||
|
||||
if (propMap.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
@@ -70,23 +69,17 @@ class AllEqualsExpression extends NonPrepareExpression {
|
||||
|
||||
@Override
|
||||
public void addSql(SpiExpressionRequest request) {
|
||||
|
||||
if (propMap.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
request.append("(");
|
||||
|
||||
int count = 0;
|
||||
for (Map.Entry<String, Object> entry : propMap.entrySet()) {
|
||||
|
||||
Object value = entry.getValue();
|
||||
String propName = entry.getKey();
|
||||
|
||||
if (count > 0) {
|
||||
request.append("and ");
|
||||
}
|
||||
|
||||
request.append(name(propName));
|
||||
if (value == null) {
|
||||
request.append(" is null ");
|
||||
@@ -106,7 +99,6 @@ class AllEqualsExpression extends NonPrepareExpression {
|
||||
*/
|
||||
@Override
|
||||
public void queryPlanHash(StringBuilder builder) {
|
||||
|
||||
builder.append("AllEquals[");
|
||||
for (Entry<String, Object> entry : propMap.entrySet()) {
|
||||
Object value = entry.getValue();
|
||||
@@ -135,20 +127,16 @@ class AllEqualsExpression extends NonPrepareExpression {
|
||||
if (!(other instanceof AllEqualsExpression)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AllEqualsExpression that = (AllEqualsExpression) other;
|
||||
return isSameByValue(that, true);
|
||||
}
|
||||
|
||||
private boolean isSameByValue(AllEqualsExpression that, boolean byValue) {
|
||||
|
||||
if (propMap.size() != that.propMap.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Iterator<Entry<String, Object>> thisIt = propMap.entrySet().iterator();
|
||||
Iterator<Entry<String, Object>> thatIt = that.propMap.entrySet().iterator();
|
||||
|
||||
while (thisIt.hasNext() && thatIt.hasNext()) {
|
||||
Entry<String, Object> thisNext = thisIt.next();
|
||||
Entry<String, Object> thatNext = thatIt.next();
|
||||
@@ -160,7 +148,6 @@ class AllEqualsExpression extends NonPrepareExpression {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-3
@@ -9,10 +9,9 @@ import java.io.IOException;
|
||||
/**
|
||||
* Contains expression for ARRAY type.
|
||||
*/
|
||||
public class ArrayContainsExpression extends AbstractExpression {
|
||||
final class ArrayContainsExpression extends AbstractExpression {
|
||||
|
||||
private final boolean contains;
|
||||
|
||||
private final Object[] values;
|
||||
|
||||
ArrayContainsExpression(String propName, boolean contains, Object... values) {
|
||||
@@ -26,7 +25,6 @@ public class ArrayContainsExpression extends AbstractExpression {
|
||||
|
||||
@Override
|
||||
public void writeDocQuery(DocQueryContext context) throws IOException {
|
||||
|
||||
if (values.length == 1) {
|
||||
context.writeEqualTo(propName, values[0]);
|
||||
} else {
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ import java.io.IOException;
|
||||
/**
|
||||
* IsEmpty expression for ARRAY type.
|
||||
*/
|
||||
public class ArrayIsEmptyExpression extends AbstractExpression {
|
||||
final class ArrayIsEmptyExpression extends AbstractExpression {
|
||||
|
||||
private final boolean empty;
|
||||
|
||||
|
||||
@@ -6,12 +6,11 @@ import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
class BetweenExpression extends AbstractExpression {
|
||||
final class BetweenExpression extends AbstractExpression {
|
||||
|
||||
private static final String _BETWEEN = " between ? and ?";
|
||||
|
||||
private final Object valueHigh;
|
||||
|
||||
private final Object valueLow;
|
||||
|
||||
BetweenExpression(String propertyName, Object valueLow, Object valueHigh) {
|
||||
|
||||
+2
-4
@@ -14,7 +14,7 @@ import java.io.IOException;
|
||||
/**
|
||||
* Between expression where a value is between two properties.
|
||||
*/
|
||||
class BetweenPropertyExpression extends NonPrepareExpression {
|
||||
final class BetweenPropertyExpression extends NonPrepareExpression {
|
||||
|
||||
private static final String BETWEEN = " between ";
|
||||
|
||||
@@ -34,7 +34,7 @@ class BetweenPropertyExpression extends NonPrepareExpression {
|
||||
this.highProperty = path + "." + highProperty;
|
||||
}
|
||||
|
||||
protected String name(String propName) {
|
||||
String name(String propName) {
|
||||
return propName;
|
||||
}
|
||||
|
||||
@@ -62,12 +62,10 @@ class BetweenPropertyExpression extends NonPrepareExpression {
|
||||
|
||||
@Override
|
||||
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);
|
||||
|
||||
@@ -9,14 +9,11 @@ import java.io.IOException;
|
||||
/**
|
||||
* Bitwise expression.
|
||||
*/
|
||||
class BitwiseExpression extends AbstractExpression {
|
||||
|
||||
protected final BitwiseOp operator;
|
||||
final class BitwiseExpression extends AbstractExpression {
|
||||
|
||||
private final BitwiseOp operator;
|
||||
private final String compare;
|
||||
|
||||
protected final long flags;
|
||||
|
||||
private final long flags;
|
||||
private final long match;
|
||||
|
||||
BitwiseExpression(String propertyName, BitwiseOp operator, long flags, String compare, long match) {
|
||||
|
||||
+1
-3
@@ -7,7 +7,7 @@ import io.ebeaninternal.server.el.ElPropertyValue;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
class CaseInsensitiveEqualExpression extends AbstractValueExpression {
|
||||
final class CaseInsensitiveEqualExpression extends AbstractValueExpression {
|
||||
|
||||
private final boolean not;
|
||||
|
||||
@@ -34,7 +34,6 @@ class CaseInsensitiveEqualExpression extends AbstractValueExpression {
|
||||
|
||||
@Override
|
||||
public void addBindValues(SpiExpressionRequest request) {
|
||||
|
||||
ElPropertyValue prop = getElProp(request);
|
||||
if (prop != null && prop.isDbEncrypted()) {
|
||||
// bind the key as well as the value
|
||||
@@ -47,7 +46,6 @@ class CaseInsensitiveEqualExpression extends AbstractValueExpression {
|
||||
|
||||
@Override
|
||||
public void addSql(SpiExpressionRequest request) {
|
||||
|
||||
String pname = propName;
|
||||
ElPropertyValue prop = getElProp(request);
|
||||
if (prop != null && prop.isDbEncrypted()) {
|
||||
|
||||
+2
-2
@@ -39,7 +39,7 @@ import java.util.ArrayList;
|
||||
*
|
||||
* }</pre>
|
||||
*/
|
||||
public class DefaultExampleExpression implements SpiExpression, ExampleExpression {
|
||||
final class DefaultExampleExpression implements SpiExpression, ExampleExpression {
|
||||
|
||||
/**
|
||||
* The example bean containing the properties.
|
||||
@@ -75,7 +75,7 @@ public class DefaultExampleExpression implements SpiExpression, ExampleExpressio
|
||||
* @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) {
|
||||
DefaultExampleExpression(EntityBean entity, boolean caseInsensitive, LikeType likeType) {
|
||||
this.entity = entity;
|
||||
this.caseInsensitive = caseInsensitive;
|
||||
this.likeType = likeType;
|
||||
|
||||
@@ -56,15 +56,10 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
|
||||
private static final String AND = " and ";
|
||||
|
||||
protected List<SpiExpression> list;
|
||||
|
||||
protected final Query<T> query;
|
||||
|
||||
private final ExpressionList<T> parentExprList;
|
||||
|
||||
protected final ExpressionFactory expr;
|
||||
|
||||
String allDocNestedPath;
|
||||
|
||||
/**
|
||||
* Set to true for the "Text" root expression list.
|
||||
*/
|
||||
|
||||
+1
-10
@@ -13,26 +13,17 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DefaultExpressionRequest implements SpiExpressionRequest {
|
||||
public final class DefaultExpressionRequest implements SpiExpressionRequest {
|
||||
|
||||
private final SpiOrmQueryRequest<?> queryRequest;
|
||||
|
||||
private final BeanDescriptor<?> beanDescriptor;
|
||||
|
||||
private final StringBuilder sql = new StringBuilder();
|
||||
|
||||
private final List<Object> bindValues = new ArrayList<>();
|
||||
|
||||
private final DeployParser deployParser;
|
||||
|
||||
private final Binder binder;
|
||||
|
||||
private final SpiExpressionList<?> expressionList;
|
||||
|
||||
private int paramIndex;
|
||||
|
||||
private final boolean enableBindLog;
|
||||
|
||||
private StringBuilder bindLog;
|
||||
|
||||
public DefaultExpressionRequest(SpiOrmQueryRequest<?> queryRequest, DeployParser deployParser, Binder binder, SpiExpressionList<?> expressionList) {
|
||||
|
||||
+5
-11
@@ -16,15 +16,12 @@ import io.ebeaninternal.server.query.CQuery;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
class ExistsQueryExpression implements SpiExpression, UnsupportedDocStoreExpression {
|
||||
final class ExistsQueryExpression implements SpiExpression, UnsupportedDocStoreExpression {
|
||||
|
||||
protected final boolean not;
|
||||
|
||||
protected final SpiQuery<?> subQuery;
|
||||
|
||||
protected List<Object> bindParams;
|
||||
|
||||
protected String sql;
|
||||
private final boolean not;
|
||||
private final SpiQuery<?> subQuery;
|
||||
private List<Object> bindParams;
|
||||
private String sql;
|
||||
|
||||
ExistsQueryExpression(SpiQuery<?> subQuery, boolean not) {
|
||||
this.subQuery = subQuery;
|
||||
@@ -67,7 +64,6 @@ class ExistsQueryExpression implements SpiExpression, UnsupportedDocStoreExpress
|
||||
|
||||
@Override
|
||||
public void prepareExpression(BeanQueryRequest<?> request) {
|
||||
|
||||
CQuery<?> subQuery = compileSubQuery(request);
|
||||
this.bindParams = subQuery.getPredicates().getWhereExprBindValues();
|
||||
this.sql = subQuery.getGeneratedSql().replace('\n', ' ');
|
||||
@@ -99,7 +95,6 @@ class ExistsQueryExpression implements SpiExpression, UnsupportedDocStoreExpress
|
||||
|
||||
@Override
|
||||
public void addSql(SpiExpressionRequest request) {
|
||||
|
||||
if (not) {
|
||||
request.append(" not");
|
||||
}
|
||||
@@ -110,7 +105,6 @@ class ExistsQueryExpression implements SpiExpression, UnsupportedDocStoreExpress
|
||||
|
||||
@Override
|
||||
public void addBindValues(SpiExpressionRequest request) {
|
||||
|
||||
for (Object bindParam : bindParams) {
|
||||
request.addBindValue(bindParam);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.io.Serializable;
|
||||
* query that includes the filterMany.
|
||||
* </p>
|
||||
*/
|
||||
public class FilterExprPath implements Serializable {
|
||||
public final class FilterExprPath implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -6420905565372842018L;
|
||||
|
||||
|
||||
+1
-3
@@ -18,14 +18,12 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public class FilterExpressionList<T> extends DefaultExpressionList<T> {
|
||||
public final class FilterExpressionList<T> extends DefaultExpressionList<T> {
|
||||
|
||||
private static final String notAllowedMessage = "This method is not allowed on a filter";
|
||||
|
||||
private final Query<T> rootQuery;
|
||||
|
||||
private final FilterExprPath pathPrefix;
|
||||
|
||||
private int firstRow;
|
||||
private int maxRows;
|
||||
private String orderByClause;
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.io.IOException;
|
||||
/**
|
||||
* Slightly redundant as Query.setId() ultimately also does the same job.
|
||||
*/
|
||||
class IdExpression extends NonPrepareExpression implements SpiExpression {
|
||||
final class IdExpression extends NonPrepareExpression implements SpiExpression {
|
||||
|
||||
private final Object value;
|
||||
|
||||
|
||||
@@ -20,10 +20,9 @@ import java.util.Set;
|
||||
/**
|
||||
* In a collection of Id values.
|
||||
*/
|
||||
public class IdInExpression extends NonPrepareExpression {
|
||||
public final class IdInExpression extends NonPrepareExpression {
|
||||
|
||||
private final List<Object> idCollection;
|
||||
|
||||
private boolean multiValueIdSupported;
|
||||
|
||||
public IdInExpression(Collection<?> idCollection) {
|
||||
|
||||
@@ -16,7 +16,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
class InExpression extends AbstractExpression {
|
||||
final class InExpression extends AbstractExpression {
|
||||
|
||||
private final boolean not;
|
||||
|
||||
|
||||
@@ -13,20 +13,14 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
class InPairsExpression extends AbstractExpression {
|
||||
final class InPairsExpression extends AbstractExpression {
|
||||
|
||||
private final boolean not;
|
||||
|
||||
private final String property0, property1;
|
||||
|
||||
private List<Pairs.Entry> entries;
|
||||
|
||||
private boolean multiValueSupported;
|
||||
|
||||
private final String separator;
|
||||
|
||||
private final String suffix;
|
||||
|
||||
private List<Object> concatBindValues;
|
||||
|
||||
InPairsExpression(Pairs pairs, boolean not) {
|
||||
|
||||
@@ -15,14 +15,11 @@ import java.util.List;
|
||||
/**
|
||||
* In expression using a sub query.
|
||||
*/
|
||||
class InQueryExpression extends AbstractExpression implements UnsupportedDocStoreExpression {
|
||||
final class InQueryExpression extends AbstractExpression implements UnsupportedDocStoreExpression {
|
||||
|
||||
private final boolean not;
|
||||
|
||||
private final SpiQuery<?> subQuery;
|
||||
|
||||
private List<Object> bindParams;
|
||||
|
||||
private String sql;
|
||||
|
||||
InQueryExpression(String propertyName, SpiQuery<?> subQuery, boolean not) {
|
||||
|
||||
@@ -6,10 +6,9 @@ import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
class InRangeExpression extends AbstractExpression {
|
||||
final class InRangeExpression extends AbstractExpression {
|
||||
|
||||
private final Object valueHigh;
|
||||
|
||||
private final Object valueLow;
|
||||
|
||||
InRangeExpression(String propertyName, Object valueLow, Object valueHigh) {
|
||||
|
||||
@@ -10,12 +10,10 @@ import io.ebean.util.SplitName;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
class IsEmptyExpression extends AbstractExpression {
|
||||
final class IsEmptyExpression extends AbstractExpression {
|
||||
|
||||
private final boolean empty;
|
||||
|
||||
private final String propertyPath;
|
||||
|
||||
private String nestedPath;
|
||||
|
||||
IsEmptyExpression(String propertyName, boolean empty) {
|
||||
|
||||
@@ -16,27 +16,27 @@ import java.util.Objects;
|
||||
* The value passed in is expected to be a valid JSON type so string, number, boolean.
|
||||
* </p>
|
||||
*/
|
||||
class JsonPathExpression extends AbstractExpression {
|
||||
final class JsonPathExpression extends AbstractExpression {
|
||||
|
||||
/**
|
||||
* The path in the JSON document in dot notation form.
|
||||
*/
|
||||
protected final String path;
|
||||
private final String path;
|
||||
|
||||
/**
|
||||
* The expression operator.
|
||||
*/
|
||||
protected final Op operator;
|
||||
private final Op operator;
|
||||
|
||||
/**
|
||||
* The bind value used to compare against the document path value.
|
||||
*/
|
||||
protected final Object value;
|
||||
private final Object value;
|
||||
|
||||
/**
|
||||
* For Between this is the upper bind value.
|
||||
*/
|
||||
protected final Object upperValue;
|
||||
private final Object upperValue;
|
||||
|
||||
/**
|
||||
* Construct for Operator (not BETWEEN though).
|
||||
|
||||
@@ -48,11 +48,10 @@ import java.util.function.Predicate;
|
||||
/**
|
||||
* Junction implementation.
|
||||
*/
|
||||
class JunctionExpression<T> implements SpiJunction<T>, SpiExpression, ExpressionList<T> {
|
||||
final class JunctionExpression<T> implements SpiJunction<T>, SpiExpression, ExpressionList<T> {
|
||||
|
||||
protected DefaultExpressionList<T> exprList;
|
||||
|
||||
protected Junction.Type type;
|
||||
DefaultExpressionList<T> exprList;
|
||||
Junction.Type type;
|
||||
|
||||
JunctionExpression(Junction.Type type, Query<T> query, ExpressionList<T> parent) {
|
||||
this.type = type;
|
||||
|
||||
@@ -8,10 +8,9 @@ import io.ebeaninternal.server.el.ElPropertyValue;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
class LikeExpression extends AbstractValueExpression {
|
||||
final class LikeExpression extends AbstractValueExpression {
|
||||
|
||||
private final boolean caseInsensitive;
|
||||
|
||||
private final LikeType type;
|
||||
|
||||
LikeExpression(String propertyName, Object value, boolean caseInsensitive, LikeType type) {
|
||||
@@ -27,7 +26,6 @@ class LikeExpression extends AbstractValueExpression {
|
||||
|
||||
@Override
|
||||
public void addBindValues(SpiExpressionRequest request) {
|
||||
|
||||
ElPropertyValue prop = getElProp(request);
|
||||
if (prop != null && prop.isDbEncrypted()) {
|
||||
// bind the key as well as the value
|
||||
@@ -40,7 +38,6 @@ class LikeExpression extends AbstractValueExpression {
|
||||
|
||||
@Override
|
||||
public void addSql(SpiExpressionRequest request) {
|
||||
|
||||
String pname = propName;
|
||||
ElPropertyValue prop = getElProp(request);
|
||||
if (prop != null && prop.isDbEncrypted()) {
|
||||
@@ -98,7 +95,6 @@ class LikeExpression extends AbstractValueExpression {
|
||||
return "%" + value + "%";
|
||||
case EQUAL_TO:
|
||||
return value;
|
||||
|
||||
default:
|
||||
throw new RuntimeException("LikeType " + type + " missed?");
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ abstract class LogicExpression implements SpiExpression {
|
||||
static final String AND = " and ";
|
||||
static final String OR = " or ";
|
||||
|
||||
static class And extends LogicExpression {
|
||||
static final class And extends LogicExpression {
|
||||
|
||||
And(Expression expOne, Expression expTwo) {
|
||||
super(true, expOne, expTwo);
|
||||
@@ -34,7 +34,7 @@ abstract class LogicExpression implements SpiExpression {
|
||||
|
||||
}
|
||||
|
||||
static class Or extends LogicExpression {
|
||||
static final class Or extends LogicExpression {
|
||||
|
||||
Or(Expression expOne, Expression expTwo) {
|
||||
super(false, expOne, expTwo);
|
||||
@@ -47,9 +47,7 @@ abstract class LogicExpression implements SpiExpression {
|
||||
}
|
||||
|
||||
SpiExpression expOne;
|
||||
|
||||
SpiExpression expTwo;
|
||||
|
||||
private final boolean conjunction;
|
||||
|
||||
LogicExpression(boolean conjunction, Expression expOne, Expression expTwo) {
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.List;
|
||||
/**
|
||||
* Helper for evaluating named parameters.
|
||||
*/
|
||||
class NamedParamHelp {
|
||||
final class NamedParamHelp {
|
||||
|
||||
/**
|
||||
* Return the bind value taking into account named parameters.
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ import io.ebeaninternal.server.el.ElPropertyValue;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
class NativeILikeExpression extends AbstractExpression {
|
||||
final class NativeILikeExpression extends AbstractExpression {
|
||||
|
||||
private final String val;
|
||||
|
||||
|
||||
+3
-4
@@ -14,11 +14,10 @@ import java.io.IOException;
|
||||
/**
|
||||
* Wraps a single expression with nestedPath for document queries.
|
||||
*/
|
||||
class NestedPathWrapperExpression implements SpiExpression {
|
||||
final class NestedPathWrapperExpression implements SpiExpression {
|
||||
|
||||
protected final String nestedPath;
|
||||
|
||||
protected final SpiExpression delegate;
|
||||
final String nestedPath;
|
||||
final SpiExpression delegate;
|
||||
|
||||
NestedPathWrapperExpression(String nestedPath, SpiExpression delegate) {
|
||||
this.nestedPath = nestedPath;
|
||||
|
||||
@@ -14,9 +14,9 @@ import java.io.IOException;
|
||||
/**
|
||||
* Effectively an expression that has no effect.
|
||||
*/
|
||||
class NoopExpression implements SpiExpression {
|
||||
final class NoopExpression implements SpiExpression {
|
||||
|
||||
protected static final NoopExpression INSTANCE = new NoopExpression();
|
||||
static final NoopExpression INSTANCE = new NoopExpression();
|
||||
|
||||
@Override
|
||||
public void prefixProperty(String path) {
|
||||
|
||||
@@ -17,14 +17,11 @@ import java.io.IOException;
|
||||
* Note that for OneToMany/ManyToMany this effectively gets translated into isEmpty()/isNotEmpty().
|
||||
* </p>
|
||||
*/
|
||||
class NullExpression extends AbstractExpression {
|
||||
final class NullExpression extends AbstractExpression {
|
||||
|
||||
private final boolean notNull;
|
||||
|
||||
private ElPropertyValue elProperty;
|
||||
|
||||
private boolean assocMany;
|
||||
|
||||
private String propertyPath;
|
||||
|
||||
NullExpression(String propertyName, boolean notNull) {
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.util.Map;
|
||||
/**
|
||||
* Prepare nested path expressions for
|
||||
*/
|
||||
class PrepareDocNested {
|
||||
final class PrepareDocNested {
|
||||
|
||||
/**
|
||||
* Prepare the top level expressions for nested path handling.
|
||||
|
||||
@@ -11,10 +11,9 @@ import io.ebeaninternal.server.persist.MultiValueWrapper;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
class RawExpression extends NonPrepareExpression {
|
||||
final class RawExpression extends NonPrepareExpression {
|
||||
|
||||
final String sql;
|
||||
|
||||
final Object[] values;
|
||||
|
||||
RawExpression(String sql, Object[] values) {
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
class RawExpressionBuilder {
|
||||
final class RawExpressionBuilder {
|
||||
|
||||
private static final String BP_1 = "?1";
|
||||
|
||||
|
||||
@@ -7,26 +7,26 @@ import java.util.Objects;
|
||||
/**
|
||||
* Utility to help isSame methods.
|
||||
*/
|
||||
public class Same {
|
||||
final class Same {
|
||||
|
||||
/**
|
||||
* Return true if both values are null or both an not null.
|
||||
*/
|
||||
public static boolean sameByNull(Object v1, Object v2) {
|
||||
static boolean sameByNull(Object v1, Object v2) {
|
||||
return (v1 == null) == (v2 == null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Null safe equals check.
|
||||
*/
|
||||
public static boolean sameByValue(Object v1, Object v2) {
|
||||
static boolean sameByValue(Object v1, Object v2) {
|
||||
return Objects.equals(v1, v2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if both collections are the same by value and order is taken into account.
|
||||
*/
|
||||
public static boolean sameByValue(Collection<?> v1, Collection<?> v2) {
|
||||
static boolean sameByValue(Collection<?> v1, Collection<?> v2) {
|
||||
if (v1 == null) {
|
||||
return v2 == null;
|
||||
}
|
||||
@@ -46,8 +46,7 @@ public class Same {
|
||||
/**
|
||||
* Null safe check by sameByValue or sameByNull based on byValue.
|
||||
*/
|
||||
public static boolean sameBy(boolean byValue, Object value, Object value1) {
|
||||
|
||||
static boolean sameBy(boolean byValue, Object value, Object value1) {
|
||||
if (byValue) {
|
||||
return sameByValue(value, value1);
|
||||
} else {
|
||||
|
||||
@@ -11,7 +11,7 @@ import io.ebeaninternal.api.NaturalKeyQueryData;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class SimpleExpression extends AbstractValueExpression {
|
||||
public final class SimpleExpression extends AbstractValueExpression {
|
||||
|
||||
private final Op type;
|
||||
|
||||
|
||||
+1
-2
@@ -7,10 +7,9 @@ import java.io.IOException;
|
||||
/**
|
||||
* Full text common terms expression.
|
||||
*/
|
||||
class TextCommonTermsExpression extends AbstractTextExpression {
|
||||
final class TextCommonTermsExpression extends AbstractTextExpression {
|
||||
|
||||
private final String search;
|
||||
|
||||
private final TextCommonTerms options;
|
||||
|
||||
public TextCommonTermsExpression(String search, TextCommonTerms options) {
|
||||
|
||||
+2
-3
@@ -7,13 +7,12 @@ import java.io.IOException;
|
||||
/**
|
||||
* Full text MATCH expression.
|
||||
*/
|
||||
public class TextMatchExpression extends AbstractTextExpression {
|
||||
final class TextMatchExpression extends AbstractTextExpression {
|
||||
|
||||
private final String search;
|
||||
|
||||
private final Match options;
|
||||
|
||||
public TextMatchExpression(String propertyName, String search, Match options) {
|
||||
TextMatchExpression(String propertyName, String search, Match options) {
|
||||
super(propertyName);
|
||||
this.search = search;
|
||||
this.options = options;
|
||||
|
||||
+2
-3
@@ -7,13 +7,12 @@ import java.io.IOException;
|
||||
/**
|
||||
* Full text Multi-Match expression.
|
||||
*/
|
||||
public class TextMultiMatchExpression extends AbstractTextExpression {
|
||||
final class TextMultiMatchExpression extends AbstractTextExpression {
|
||||
|
||||
private final String search;
|
||||
|
||||
private final MultiMatch options;
|
||||
|
||||
public TextMultiMatchExpression(String search, MultiMatch options) {
|
||||
TextMultiMatchExpression(String search, MultiMatch options) {
|
||||
super(null);
|
||||
this.search = search;
|
||||
this.options = options;
|
||||
|
||||
+2
-3
@@ -7,13 +7,12 @@ import java.io.IOException;
|
||||
/**
|
||||
* Full text query string expression.
|
||||
*/
|
||||
class TextQueryStringExpression extends AbstractTextExpression {
|
||||
final class TextQueryStringExpression extends AbstractTextExpression {
|
||||
|
||||
private final String search;
|
||||
|
||||
private final TextQueryString options;
|
||||
|
||||
public TextQueryStringExpression(String search, TextQueryString options) {
|
||||
TextQueryStringExpression(String search, TextQueryString options) {
|
||||
super(null);
|
||||
this.search = search;
|
||||
this.options = options;
|
||||
|
||||
+2
-3
@@ -7,13 +7,12 @@ import java.io.IOException;
|
||||
/**
|
||||
* Full text Multi-Match expression.
|
||||
*/
|
||||
class TextSimpleExpression extends AbstractTextExpression {
|
||||
final class TextSimpleExpression extends AbstractTextExpression {
|
||||
|
||||
private final String search;
|
||||
|
||||
private final TextSimple options;
|
||||
|
||||
public TextSimpleExpression(String search, TextSimple options) {
|
||||
TextSimpleExpression(String search, TextSimple options) {
|
||||
super(null);
|
||||
this.search = search;
|
||||
this.options = options;
|
||||
|
||||
-2
@@ -10,7 +10,6 @@ abstract class BaseDbExpression implements DbExpressionHandler {
|
||||
|
||||
@Override
|
||||
public void bitwise(SpiExpressionRequest request, String propName, BitwiseOp operator, long flags, String compare, long match) {
|
||||
|
||||
String bitOp = bitOp(operator);
|
||||
request.append("(").append(propName).append(" ").append(bitOp).append(" ? ").append(compare).append(" ?)");
|
||||
}
|
||||
@@ -30,7 +29,6 @@ abstract class BaseDbExpression implements DbExpressionHandler {
|
||||
* Common alternative where the bitwise operation is a function (specifically bitand is used - H2 and Oracle).
|
||||
*/
|
||||
protected void bitwiseFunction(SpiExpressionRequest request, String propName, BitwiseOp operator, String compare) {
|
||||
|
||||
String funcName = functionName(operator);
|
||||
request.append(funcName).append("(").append(propName).append(", ?) ").append(compare).append(" ?");
|
||||
}
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import io.ebeaninternal.server.expression.Op;
|
||||
/**
|
||||
* Not supported JSON or ARRAY expression handler.
|
||||
*/
|
||||
public class BasicDbExpression extends BaseDbExpression {
|
||||
class BasicDbExpression extends BaseDbExpression {
|
||||
|
||||
@Override
|
||||
public void json(SpiExpressionRequest request, String propName, String path, Op operator, Object value) {
|
||||
|
||||
+1
-2
@@ -4,13 +4,12 @@ import io.ebean.annotation.Platform;
|
||||
import io.ebean.config.dbplatform.DatabasePlatform;
|
||||
|
||||
|
||||
public class DbExpressionHandlerFactory {
|
||||
public final class DbExpressionHandlerFactory {
|
||||
|
||||
/**
|
||||
* Create and return the appropriate platform specific handing of expressions.
|
||||
*/
|
||||
public static DbExpressionHandler from(DatabasePlatform databasePlatform) {
|
||||
|
||||
Platform platform = databasePlatform.getPlatform();
|
||||
switch (platform) {
|
||||
case H2:
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import io.ebeaninternal.server.expression.BitwiseOp;
|
||||
/**
|
||||
* H2 handling of platform specific expressions.
|
||||
*/
|
||||
class H2DbExpression extends BasicDbExpression {
|
||||
final class H2DbExpression extends BasicDbExpression {
|
||||
|
||||
@Override
|
||||
public void bitwise(SpiExpressionRequest request, String propName, BitwiseOp operator, long flags, String compare, long match) {
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import io.ebeaninternal.server.expression.Op;
|
||||
/**
|
||||
* HANA handling of platform specific expressions.
|
||||
*/
|
||||
public class HanaDbExpression extends BaseDbExpression {
|
||||
final class HanaDbExpression extends BaseDbExpression {
|
||||
|
||||
@Override
|
||||
public void bitwise(SpiExpressionRequest request, String propName, BitwiseOp operator, long flags, String compare, long match) {
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import io.ebeaninternal.server.expression.Op;
|
||||
/**
|
||||
* MariaDB specific handling of platform specific expressions.
|
||||
*/
|
||||
class MariaDbExpression extends BasicDbExpression {
|
||||
final class MariaDbExpression extends BasicDbExpression {
|
||||
|
||||
@Override
|
||||
public void json(SpiExpressionRequest request, String propName, String path, Op operator, Object value) {
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import io.ebeaninternal.server.expression.Op;
|
||||
/**
|
||||
* MySql specific handling of platform specific expressions.
|
||||
*/
|
||||
class MySqlDbExpression extends BasicDbExpression {
|
||||
final class MySqlDbExpression extends BasicDbExpression {
|
||||
|
||||
@Override
|
||||
public void json(SpiExpressionRequest request, String propName, String path, Op operator, Object value) {
|
||||
|
||||
+1
-2
@@ -7,7 +7,7 @@ import io.ebeaninternal.server.expression.Op;
|
||||
/**
|
||||
* Oracle handling of platform specific expressions. ARRAY expressions not supported.
|
||||
*/
|
||||
public class OracleDbExpression extends BaseDbExpression {
|
||||
final class OracleDbExpression extends BaseDbExpression {
|
||||
|
||||
@Override
|
||||
public String concat(String property0, String separator, String property1, String suffix) {
|
||||
@@ -16,7 +16,6 @@ public class OracleDbExpression extends BaseDbExpression {
|
||||
|
||||
@Override
|
||||
public void json(SpiExpressionRequest request, String propName, String path, Op operator, Object value) {
|
||||
|
||||
if (operator == Op.EXISTS) {
|
||||
request.append("json_exists(").append(propName).append(", '$.").append(path).append("')");
|
||||
} else if (operator == Op.NOT_EXISTS) {
|
||||
|
||||
+3
-4
@@ -3,7 +3,7 @@ package io.ebeaninternal.server.expression.platform;
|
||||
/**
|
||||
* Helper for determining type casting for JSON and ARRAY expressions.
|
||||
*/
|
||||
public class PostgresCast {
|
||||
final class PostgresCast {
|
||||
|
||||
/**
|
||||
* Postgres CAST the type if necessary.
|
||||
@@ -11,15 +11,14 @@ public class PostgresCast {
|
||||
* This is generally necessary for JSON expressions as text values always returned from the json operators used.
|
||||
* </p>
|
||||
*/
|
||||
protected static String cast(Object value) {
|
||||
static String cast(Object value) {
|
||||
return cast(value, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Postgres CAST the type if necessary additionally specify if DB ARRAY is used.
|
||||
*/
|
||||
protected static String cast(Object value, boolean asArray) {
|
||||
|
||||
static String cast(Object value, boolean asArray) {
|
||||
if (value == null) {
|
||||
// for exists and not-exists expressions
|
||||
return "";
|
||||
|
||||
+1
-4
@@ -6,7 +6,7 @@ import io.ebeaninternal.server.expression.Op;
|
||||
/**
|
||||
* Postgres JSON and ARRAY expression handler
|
||||
*/
|
||||
public class PostgresDbExpression extends BaseDbExpression {
|
||||
final class PostgresDbExpression extends BaseDbExpression {
|
||||
|
||||
@Override
|
||||
public String concat(String property0, String separator, String property1, String suffix) {
|
||||
@@ -15,7 +15,6 @@ public class PostgresDbExpression extends BaseDbExpression {
|
||||
|
||||
@Override
|
||||
public void json(SpiExpressionRequest request, String propName, String path, Op operator, Object value) {
|
||||
|
||||
StringBuilder sb = new StringBuilder(50);
|
||||
String[] paths = path.split("\\.");
|
||||
if (paths.length == 1) {
|
||||
@@ -41,7 +40,6 @@ public class PostgresDbExpression extends BaseDbExpression {
|
||||
|
||||
@Override
|
||||
public void arrayContains(SpiExpressionRequest request, String propName, boolean contains, Object... values) {
|
||||
|
||||
if (!contains) {
|
||||
request.append("not (");
|
||||
}
|
||||
@@ -58,7 +56,6 @@ public class PostgresDbExpression extends BaseDbExpression {
|
||||
|
||||
@Override
|
||||
public void arrayIsEmpty(SpiExpressionRequest request, String propName, boolean empty) {
|
||||
|
||||
request.append("coalesce(cardinality(").append(propName).append("),0)");
|
||||
if (empty) {
|
||||
request.append(" = 0");
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import io.ebeaninternal.server.expression.Op;
|
||||
/**
|
||||
* Microsoft SQL Server JSON. ARRAY expressions not supported.
|
||||
*/
|
||||
public class SqlServerDbExpression extends BaseDbExpression {
|
||||
final class SqlServerDbExpression extends BaseDbExpression {
|
||||
|
||||
@Override
|
||||
public void json(final SpiExpressionRequest request, final String propName,
|
||||
|
||||
Reference in New Issue
Block a user