#1837 (#1740 and #1744) - Inheritance on both sides of @ManyToOne

This change also relates back to #1740 and #1744 and changes the way that issue was fixed (by SqlTreeNodeBean on partially populated non-id inheritance bean).
This commit is contained in:
rob bygrave
2019-10-13 11:46:11 +13:00
parent a474880735
commit f24b4dba71
10 changed files with 21 additions and 42 deletions
@@ -21,9 +21,7 @@ class AssocOneHelpRefInherit extends AssocOneHelp {
@Override
void loadIgnore(DbReadContext ctx) {
property.targetIdBinder.loadIgnore(ctx);
if (inherit.hasChildren()) {
ctx.getDataReader().incrementPos(1);
}
ctx.getDataReader().incrementPos(1);
}
/**
@@ -75,7 +73,7 @@ class AssocOneHelpRefInherit extends AssocOneHelp {
@Override
void appendSelect(DbSqlContext ctx, boolean subQuery) {
if (!subQuery && inherit.hasChildren()) {
if (!subQuery) {
// add discriminator column
String relativePrefix = ctx.getRelativePrefix(property.getName());
String tableAlias = ctx.getTableAlias(relativePrefix);
@@ -10,7 +10,7 @@ public interface DbSqlContext {
/**
* Add a join to the sql query.
*/
void addJoin(String type, String table, TableJoinColumn[] cols, String a1, String a2, String inheritance);
void addJoin(String type, String table, TableJoinColumn[] cols, String a1, String a2);
/**
* Push the current table alias onto the stack.
@@ -219,9 +219,6 @@ public class InheritInfo {
* Return the associated InheritInfo for this DB row read.
*/
public InheritInfo readType(DbReadContext ctx) throws SQLException {
if (!hasChildren()) {
return this;
}
return readType(ctx.getDataReader().getString());
}
@@ -154,11 +154,8 @@ public final class TableJoin {
public SqlJoinType addJoin(SqlJoinType joinType, String a1, String a2, DbSqlContext ctx) {
String inheritance = inheritInfo != null ? inheritInfo.getWhere() : null;
String joinLiteral = joinType.getLiteral(type);
ctx.addJoin(joinLiteral, table, columns(), a1, a2, inheritance);
ctx.addJoin(joinLiteral, table, columns(), a1, a2);
return joinType.autoToOuter(type);
}
@@ -112,7 +112,7 @@ class DefaultDbSqlContext implements DbSqlContext {
}
@Override
public void addJoin(String type, String table, TableJoinColumn[] cols, String a1, String a2, String inheritance) {
public void addJoin(String type, String table, TableJoinColumn[] cols, String a1, String a2) {
if (tableJoins == null) {
tableJoins = new HashSet<>();
@@ -166,11 +166,6 @@ class DefaultDbSqlContext implements DbSqlContext {
}
}
// add on any inheritance where clause
if (inheritance != null && !inheritance.isEmpty()) {
sb.append(" and ").append(a2).append(".").append(inheritance);
}
if (addAsOfOnClause) {
sb.append(" and ").append(historySupport.getAsOfPredicate(a2));
}
@@ -227,7 +227,7 @@ class SqlTreeNodeBean implements SqlTreeNode {
@Override
void initBeanType() throws SQLException {
InheritInfo localInfo = inheritInfo.readType(ctx);
InheritInfo localInfo = readId ? inheritInfo.readType(ctx) : desc.getInheritInfo();
if (localInfo == null) {
// the bean must be null
localIdBinder = idBinder;
@@ -539,7 +539,7 @@ class SqlTreeNodeBean implements SqlTreeNode {
}
if (readId) {
if (!subQuery && inheritInfo != null && inheritInfo.hasChildren()) {
if (!subQuery && inheritInfo != null) {
ctx.appendColumn(inheritInfo.getDiscriminatorColumn());
}
appendSelectId(ctx, idBinder.getBeanProperty());