Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -726,45 +726,45 @@ public Expression not(Expression exp) {
*/
@Override
public <T> Junction<T> conjunction(Query<T> query) {
return new JunctionExpression<>(Junction.Type.AND, query, query.where());
return new JunctionExpression<>(Junction.Type.AND, query, this, query.where());
}

/**
* Return a list of expressions that will be joined by OR's.
*/
@Override
public <T> Junction<T> disjunction(Query<T> query) {
return new JunctionExpression<>(Junction.Type.OR, query, query.where());
return new JunctionExpression<>(Junction.Type.OR, query, this, query.where());
}

/**
* Return a list of expressions that will be joined by AND's.
*/
@Override
public <T> Junction<T> conjunction(Query<T> query, ExpressionList<T> parent) {
return new JunctionExpression<>(Junction.Type.AND, query, parent);
return new JunctionExpression<>(Junction.Type.AND, query, this, parent);
}

/**
* Return a list of expressions that will be joined by OR's.
*/
@Override
public <T> Junction<T> disjunction(Query<T> query, ExpressionList<T> parent) {
return new JunctionExpression<>(Junction.Type.OR, query, parent);
return new JunctionExpression<>(Junction.Type.OR, query, this, parent);
}

/**
* Return a list of expressions that are wrapped by NOT.
*/
public <T> Junction<T> junction(Junction.Type type, Query<T> query) {
return new JunctionExpression<>(type, query, query.where());
return new JunctionExpression<>(type, query, this, query.where());
}

/**
* Create and return a Full text junction (Must, Must Not or Should).
*/
@Override
public <T> Junction<T> junction(Junction.Type type, Query<T> query, ExpressionList<T> parent) {
return new JunctionExpression<>(type, query, parent);
return new JunctionExpression<>(type, query, this, parent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,8 @@ public static <P> ExpressionList<P> forFetchGroup(Query<P> q) {
/**
* Construct for Text root expression list - this handles implicit Bool Should, Must etc.
*/
public DefaultExpressionList(Query<T> query) {
this(query, query.getExpressionFactory(), null, new ArrayList<>(), true);
}

public DefaultExpressionList(Query<T> query, ExpressionList<T> parentExprList) {
this(query, query.getExpressionFactory(), parentExprList, new ArrayList<>());
public DefaultExpressionList(Query<T> query, boolean textRoot) {
this(query, query.getExpressionFactory(), null, new ArrayList<>(), textRoot);
}

DefaultExpressionList(Query<T> query, ExpressionFactory expr, ExpressionList<T> parentExprList, List<SpiExpression> list) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ final class JunctionExpression<T> implements SpiJunction<T>, SpiExpression, Expr
DefaultExpressionList<T> exprList;
Junction.Type type;

JunctionExpression(Junction.Type type, Query<T> query, ExpressionList<T> parent) {
JunctionExpression(Junction.Type type, Query<T> query, ExpressionFactory expr, ExpressionList<T> parent) {
this.type = type;
this.exprList = new DefaultExpressionList<>(query, parent);
this.exprList = new DefaultExpressionList<>(query, expr, parent, new ArrayList<>());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1895,15 +1895,15 @@ public final Query<T> where(Expression expression) {
public final ExpressionList<T> text() {
if (textExpressions == null) {
useDocStore = true;
textExpressions = new DefaultExpressionList<>(this);
textExpressions = new DefaultExpressionList<>(this, true);
}
return textExpressions;
}

@Override
public final ExpressionList<T> where() {
if (whereExpressions == null) {
whereExpressions = new DefaultExpressionList<>(this, null);
whereExpressions = new DefaultExpressionList<>(this, false);
}
return whereExpressions;
}
Expand All @@ -1924,7 +1924,7 @@ public final Query<T> having(Expression expression) {
@Override
public final ExpressionList<T> having() {
if (havingExpressions == null) {
havingExpressions = new DefaultExpressionList<>(this, null);
havingExpressions = new DefaultExpressionList<>(this, false);
}
return havingExpressions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected QueryBean(boolean aliasDummy) {
/** Construct for FilterMany */
protected QueryBean(ExpressionList<T> filter) {
this.query = null;
this.root = null;
this.root = (R) this;
this.whereStack = new ArrayStack<>();
whereStack.push(filter);
}
Expand Down
14 changes: 14 additions & 0 deletions ebean-querybean/src/test/java/org/querytest/QCustomerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,20 @@ void filterManySingleQuery() {
assertThat(q.getGeneratedSql()).contains(" from be_customer t0 left join be_contact t1 on t1.customer_id = t0.id where (t1.id is null or (t1.first_name like ? and t1.first_name like ? escape'|')) order by t0.id");
}

@Test
void filterManyOr() {
var q = new QCustomer()
.contacts.filterMany(c ->
c.or()
.firstName.startsWith("R")
.lastName.startsWith("R")
.endOr())
.query();

q.findList();
assertThat(q.getGeneratedSql()).contains(" from be_customer t0 left join be_contact t1 on t1.customer_id = t0.id where (t1.id is null or ((t1.first_name like ? escape'|' or t1.last_name like ? escape'|'))) order by t0.id");
}

@Test
public void testIdIn() {

Expand Down