#2651 - @OneToOne with @History, add fix and update tests

Effectively Ebean internally needs to keep a count on the number of times AS OF predicates are added (to joins + top level table). This change moves keeping that count for all joins to DbSqlContext.
This commit is contained in:
Rob Bygrave committed 2022-04-19 15:02:50 +12:00
1 parent 67fc7cdb48
commit 756e3e4a1c
11 files changed
+98 -36

No files matched your search

@@ -391,6 +391,11 @@ public interface SpiQuery<T> extends Query<T>, SpiQueryFetch, TxnProfileEventCod
*/
void incrementAsOfTableCount();
/**
* Increment the counter of tables used in 'As Of' query.
*/
void incrementAsOfTableCount(int asOfTableCount);
/**
* Return the table alias used for the base table.
*/
@@ -119,6 +119,11 @@ public interface DbSqlContext {
*/
boolean isIncludeSoftDelete();
/**
* Return the count of history table AS OF predicates added via joins.
*/
int asOfTableCount();
/**
* Return true if the query is a 'asDraft' query.
*/
@@ -647,6 +647,7 @@ final class CQueryBuilder {
if (query.isAsOfBaseTable() && !historySupport.isStandardsBased()) {
appendAndOrWhere();
sb.append(historySupport.getAsOfPredicate(request.baseTableAlias()));
query.incrementAsOfTableCount();
}
}
@@ -30,6 +30,7 @@ final class DefaultDbSqlContext implements DbSqlContext {
private boolean useColumnAlias;
private int columnIndex;
private int asOfTableCount;
private StringBuilder sb = new StringBuilder(STRING_BUILDER_INITIAL_CAPACITY);
@@ -178,6 +179,7 @@ final class DefaultDbSqlContext implements DbSqlContext {
}
if (addAsOfOnClause) {
sb.append(" and ").append(historySupport.getAsOfPredicate(a2));
asOfTableCount++;
}
if (extraWhere != null && !extraWhere.isEmpty()) {
sb.append(" and ");
@@ -195,6 +197,11 @@ final class DefaultDbSqlContext implements DbSqlContext {
}
}
@Override
public int asOfTableCount() {
return asOfTableCount;
}
@Override
public boolean isDraftQuery() {
return draftSupport != null;
@@ -127,6 +127,7 @@ public final class SqlTreeBuilder {
groupBy = buildGroupByClause();
distinctOn = buildDistinctOn();
encryptedProps = ctx.getEncryptedProps();
query.incrementAsOfTableCount(ctx.asOfTableCount());
}
boolean includeJoins = alias != null && alias.isIncludeJoins();
@@ -302,20 +302,7 @@ class SqlTreeNodeBean implements SqlTreeNode {
@Override
public void addAsOfTableAlias(SpiQuery<?> query) {
// if history on this bean type add it's alias
// for each alias we add an effect date predicate
if (desc.isHistorySupport()) {
query.incrementAsOfTableCount();
}
if (lazyLoadParent != null && lazyLoadParent.isManyToManyWithHistory()) {
query.incrementAsOfTableCount();
}
if (intersectionAsOfTableAlias) {
query.incrementAsOfTableCount();
}
for (SqlTreeNode child : children) {
child.addAsOfTableAlias(query);
}
// do nothing for non-root, handled by DbSqlContext for joins
}
@Override
@@ -58,13 +58,6 @@ final class SqlTreeNodeRoot extends SqlTreeNodeBean {
public void addAsOfTableAlias(SpiQuery<?> query) {
if (desc.isHistorySupport()) {
query.setAsOfBaseTable();
query.incrementAsOfTableCount();
}
if (lazyLoadParent != null && lazyLoadParent.isManyToManyWithHistory()) {
query.incrementAsOfTableCount();
}
for (SqlTreeNode aChildren : children) {
aChildren.addAsOfTableAlias(query);
}
}
@@ -316,6 +316,11 @@ public final class DefaultOrmQuery<T> extends AbstractQuery implements SpiQuery<
asOfTableCount++;
}
@Override
public void incrementAsOfTableCount(int increment) {
asOfTableCount += increment;
}
@Override
public int getAsOfTableCount() {
return asOfTableCount;