#782 - History Many-To-Many Lazy-Loads fail

This commit is contained in:
Robin Bygrave
2016-07-25 23:31:02 +12:00
parent b763f4c875
commit 6108ef484b
6 changed files with 47 additions and 2 deletions
@@ -222,6 +222,16 @@ public interface SpiQuery<T> extends Query<T> {
*/
Timestamp getAsOf();
/**
* Return true if the base table is using history.
*/
boolean isAsOfBaseTable();
/**
* Set when the base table is using history.
*/
void setAsOfBaseTable();
/**
* Increment the counter of tables used in 'As Of' query.
*/
@@ -1173,6 +1173,13 @@ public class BeanProperty implements ElPropertyValue, Property {
return excludedFromHistory;
}
/**
* Return true if this is a ManyToMany with history support (on the intersection table).
*/
public boolean isManyToManyWithHistory() {
return !excludedFromHistory && descriptor.isHistorySupport();
}
/**
* Return true if this property only exists on the draft table.
*/
@@ -472,8 +472,7 @@ public class CQueryBuilder {
hasWhere = true;
}
int asOfCount = query.getAsOfTableCount();
if (asOfCount > 0 && !historySupport.isStandardsBased()) {
if (query.isAsOfBaseTable() && !historySupport.isStandardsBased()) {
hasWhere = appendWhere(hasWhere, sb);
sb.append(historySupport.getAsOfPredicate(request.getBaseTableAlias()));
}
@@ -507,6 +507,9 @@ public class SqlTreeNodeBean implements SqlTreeNode {
if (desc.isHistorySupport()) {
query.incrementAsOfTableCount();
}
if (lazyLoadParent != null && lazyLoadParent.isManyToManyWithHistory()) {
query.incrementAsOfTableCount();
}
if (intersectionAsOfTableAlias) {
query.incrementAsOfTableCount();
}
@@ -33,6 +33,22 @@ public final class SqlTreeNodeRoot extends SqlTreeNodeBean {
this.includeJoin = null;
}
/**
* Set AsOf support (at root level).
*/
public void addAsOfTableAlias(SpiQuery<?> query) {
if (desc.isHistorySupport()) {
query.setAsOfBaseTable();
query.incrementAsOfTableCount();
}
if (lazyLoadParent != null && lazyLoadParent.isManyToManyWithHistory()) {
query.incrementAsOfTableCount();
}
for (int i = 0; i < children.length; i++) {
children[i].addAsOfTableAlias(query);
}
}
/**
* For the root node there is no join type or on clause etc.
*/
@@ -146,6 +146,8 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
private DefaultExpressionList<T> havingExpressions;
private boolean asOfBaseTable;
private int asOfTableCount;
/**
@@ -280,6 +282,14 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
return softDeletePredicates;
}
public boolean isAsOfBaseTable() {
return asOfBaseTable;
}
public void setAsOfBaseTable() {
this.asOfBaseTable = true;
}
@Override
public void incrementAsOfTableCount() {
asOfTableCount++;