Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.avaje.ebeaninternal.server.expression;
import com.avaje.ebean.*;
import com.avaje.ebean.event.BeanQueryRequest;
import com.avaje.ebean.search.Match;
import com.avaje.ebean.search.MultiMatch;
import com.avaje.ebean.search.TextCommonTerms;
import com.avaje.ebean.search.TextQueryString;
import com.avaje.ebean.search.TextSimple;
import com.avaje.ebeaninternal.api.HashQueryPlanBuilder;
import com.avaje.ebeaninternal.api.ManyWhereJoins;
import com.avaje.ebeaninternal.api.SpiExpression;
import com.avaje.ebeaninternal.api.SpiExpressionList;
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
import com.avaje.ebeaninternal.api.SpiExpressionValidation;
import com.avaje.ebeaninternal.api.SpiJunction;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Default implementation of ExpressionList.
*/
public class DefaultExpressionList implements SpiExpressionList {
private static final String AND = " and ";
protected List list;
protected final Query query;
private final ExpressionList parentExprList;
protected transient ExpressionFactory expr;
protected String allDocNestedPath;
/**
* Set to true for the "Text" root expression list.
*/
private final boolean textRoot;
/**
* Construct for Text root expression list - this handles implicit Bool Should, Must etc.
*/
public DefaultExpressionList(Query query) {
this(query, query.getExpressionFactory(), null, new ArrayList(), true);
}
public DefaultExpressionList(Query query, ExpressionList parentExprList) {
this(query, query.getExpressionFactory(), parentExprList);
}
DefaultExpressionList(Query query, ExpressionFactory expr, ExpressionList parentExprList) {
this(query, expr, parentExprList, new ArrayList());
}
DefaultExpressionList(Query query, ExpressionFactory expr, ExpressionList parentExprList, List list) {
this(query, expr, parentExprList, list, false);
}
private DefaultExpressionList(Query query, ExpressionFactory expr, ExpressionList parentExprList, List list, boolean textRoot) {
this.textRoot = textRoot;
this.list = list;
this.query = query;
this.expr = expr;
this.parentExprList = parentExprList;
}
private DefaultExpressionList() {
this(null, null, null, new ArrayList());
}
/**
* Wrap the expression list as a Junction or top level DefaultExpressionList.
*
* @param list The list of expressions grouped by nested path
* @param nestedPath The doc store nested path
* @param type The junction type (or null for top level expression list).
* @return A single SpiExpression that has the nestedPath set
*/
SpiExpression wrap(List list, String nestedPath, Junction.Type type) {
DefaultExpressionList wrapper = new DefaultExpressionList(query, expr, null, list, false);
wrapper.setAllDocNested(nestedPath);
if (type != null) {
return new JunctionExpression(type, wrapper);
} else {
return wrapper;
}
}
void simplifyEntries() {
for (SpiExpression element : list) {
element.simplify();
}
}
public void simplify() {
simplifyEntries();
}
/**
* Write being aware if it is the Top level "text" expressions.
*
* If this is the Top level "text" expressions then it detects if explicit or implicit Bool Should, Must etc is required
* to wrap the expressions.
*
*
* If implicit Bool is required SHOULD is used.
*
*/
@Override
public void writeDocQuery(DocQueryContext context) throws IOException {
if (!textRoot) {
writeDocQuery(context, null);
} else {
// this is a Top level "text" expressions so we may need to wrap in Bool SHOULD etc.
if (list.isEmpty()) throw new IllegalStateException("empty expression list?");
if (allDocNestedPath!=null) context.startNested(allDocNestedPath);
int size = list.size();
SpiExpression first = list.get(0);
boolean explicitBool = first instanceof SpiJunction>;
boolean implicitBool = !explicitBool && size > 1;
if (implicitBool || explicitBool) {
context.startBoolGroup();
}
if (implicitBool) {
context.startBoolGroupList(Junction.Type.SHOULD);
}
for (int i = 0; i < size; i++) {
SpiExpression expr = list.get(i);
if (explicitBool) {
try {
((SpiJunction>)expr).writeDocQueryJunction(context);
} catch (ClassCastException e) {
throw new IllegalStateException("The top level text() expressions should be all be 'Must', 'Should' or 'Must Not' or none of them should be.", e);
}
} else {
expr.writeDocQuery(context);
}
}
if (implicitBool) {
context.endBoolGroupList();
}
if (implicitBool || explicitBool) {
context.endBoolGroup();
}
if (allDocNestedPath!=null) context.endNested();
}
}
public void writeDocQuery(DocQueryContext context, SpiExpression idEquals) throws IOException {
if (allDocNestedPath!=null) context.startNested(allDocNestedPath);
int size = list.size();
if (size == 1 && idEquals == null) {
// only 1 expression - skip bool
list.get(0).writeDocQuery(context);
} else if (size == 0 && idEquals != null) {
// only idEquals - skip bool
idEquals.writeDocQuery(context);
} else {
// bool must wrap all the children
context.startBoolMust();
if (idEquals != null) {
idEquals.writeDocQuery(context);
}
for (int i = 0; i < size; i++) {
list.get(i).writeDocQuery(context);
}
context.endBool();
}
if (allDocNestedPath!=null) context.endNested();
}
@Override
public SpiExpressionList> trimPath(int prefixTrim) {
throw new RuntimeException("Only allowed on FilterExpressionList");
}
public List internalList() {
return list;
}
/**
* Return a copy of the expression list.
*
* Each of the expressions are expected to be immutable and safe to reference.
*
*/
public DefaultExpressionList copy(Query query) {
DefaultExpressionList copy = new DefaultExpressionList(query, expr, null);
copy.list.addAll(list);
return copy;
}
public DefaultExpressionList copyForPlanKey() {
DefaultExpressionList copy = new DefaultExpressionList();
for (int i = 0; i < list.size(); i++) {
copy.list.add(list.get(i).copyForPlanKey());
}
return copy;
}
@Override
public Object getIdEqualTo(String idName) {
// always return null for this expression
return null;
}
/**
* Return true if one of the expressions is related to a Many property.
*/
@Override
public void containsMany(BeanDescriptor> desc, ManyWhereJoins whereManyJoins) {
for (int i = 0; i < list.size(); i++) {
list.get(i).containsMany(desc, whereManyJoins);
}
}
@Override
public void validate(SpiExpressionValidation validation) {
for (int i = 0; i < list.size(); i++) {
list.get(i).validate(validation);
}
}
@Override
public Query query() {
return query;
}
@Override
public Query asOf(Timestamp asOf) {
return query.asOf(asOf);
}
@Override
public Query asDraft() {
return query.asDraft();
}
@Override
public Query includeSoftDeletes() {
return setIncludeSoftDeletes();
}
@Override
public Query setIncludeSoftDeletes() {
return query.setIncludeSoftDeletes();
}
@Override
public List> findVersions() {
return query.findVersions();
}
@Override
public List> findVersionsBetween(Timestamp start, Timestamp end) {
return query.findVersionsBetween(start, end);
}
@Override
public ExpressionList where() {
return query.where();
}
@Override
public OrderBy order() {
return query.order();
}
@Override
public OrderBy orderBy() {
return query.order();
}
@Override
public Query order(String orderByClause) {
return query.order(orderByClause);
}
@Override
public Query orderBy(String orderBy) {
return query.order(orderBy);
}
@Override
public Query setOrderBy(String orderBy) {
return query.order(orderBy);
}
@Override
public Query apply(FetchPath fetchPath) {
return query.apply(fetchPath);
}
@Override
public int delete() {
return query.delete();
}
@Override
public int update() {
return query.update();
}
@Override
public FutureIds findFutureIds() {
return query.findFutureIds();
}
@Override
public FutureRowCount findFutureCount() {
return query.findFutureCount();
}
@Override
public FutureRowCount findFutureRowCount() {
return findFutureCount();
}
@Override
public FutureList findFutureList() {
return query.findFutureList();
}
@Override
public PagedList findPagedList() {
return query.findPagedList();
}
@Override
public int findCount() {
return query.findCount();
}
@Override
public int findRowCount() {
return findCount();
}
@Override
public List