#1837 - Inheritance on both sides of @ManyToOne confuses columns (#1843)

* #1837 - Inheritance on both sides of @ManyToOne confuses columns

* #1837 - Inheritance on both sides of @ManyToOne confuses columns

Tidy up whitespace in SQL
This commit is contained in:
Rob Bygrave
2019-10-12 00:25:53 +13:00
committed by GitHub
parent 4cfab3a2de
commit a474880735
16 changed files with 313 additions and 8 deletions
@@ -5,6 +5,7 @@ import io.ebean.bean.EntityBeanIntercept;
import io.ebean.bean.ObjectGraphNode;
import io.ebean.bean.PersistenceContext;
import io.ebeaninternal.server.core.OrmQueryRequest;
import io.ebeaninternal.server.deploy.BeanPropertyAssocOne;
/**
* Controls the loading of reference objects for a query instance.
@@ -47,6 +48,11 @@ public interface LoadContext {
*/
void register(String path, EntityBeanIntercept ebi);
/**
* Register a Bean with inheritance.
*/
void register(String path, EntityBeanIntercept ebi, BeanPropertyAssocOne<?> property);
/**
* Register a collection for lazy loading.
*/
@@ -57,14 +57,13 @@ class AssocOneHelpRefInherit extends AssocOneHelp {
boolean disableLazyLoading = ctx.isDisableLazyLoading();
Object ref = desc.contextRef(pc, ctx.isReadOnly(), disableLazyLoading, id);
if (!disableLazyLoading) {
ctx.register(property.name, ((EntityBean) ref)._ebean_getIntercept());
ctx.registerBeanInherit(property, ((EntityBean) ref)._ebean_getIntercept());
}
return ref;
}
@Override
void appendFrom(DbSqlContext ctx, SqlJoinType joinType) {
// add join to support the discriminator column
String relativePrefix = ctx.getRelativePrefix(property.name);
property.tableJoin.addJoin(joinType, relativePrefix, ctx);
@@ -60,6 +60,11 @@ public interface DbReadContext {
*/
void register(String path, EntityBeanIntercept ebi);
/**
* Register a reference with inheritance for lazy loading.
*/
void registerBeanInherit(BeanPropertyAssocOne<?> property, EntityBeanIntercept ebi);
/**
* Register a collection for lazy loading.
*/
@@ -33,7 +33,6 @@ abstract class DLoadBaseContext {
final boolean queryFetch;
DLoadBaseContext(DLoadContext parent, BeanDescriptor<?> desc, String path, int defaultBatchSize, OrmQueryProperties queryProps) {
this.parent = parent;
this.serverName = parent.getEbeanServer().getName();
this.desc = desc;
@@ -41,7 +40,6 @@ abstract class DLoadBaseContext {
this.fullPath = parent.getFullPath(path);
this.hitCache = parent.isBeanCacheGet() && desc.isBeanCaching();
this.objectGraphNode = parent.getObjectGraphNode(path);
this.queryFetch = queryProps != null && queryProps.isQueryFetch();
this.firstBatchSize = initFirstBatchSize(defaultBatchSize, queryProps);
this.secondaryBatchSize = initSecondaryBatchSize(defaultBatchSize, firstBatchSize, queryProps);
@@ -19,6 +19,7 @@ import io.ebeaninternal.server.deploy.BeanDescriptor;
import io.ebeaninternal.server.deploy.BeanProperty;
import io.ebeaninternal.server.deploy.BeanPropertyAssoc;
import io.ebeaninternal.server.deploy.BeanPropertyAssocMany;
import io.ebeaninternal.server.deploy.BeanPropertyAssocOne;
import io.ebeaninternal.server.el.ElPropertyValue;
import io.ebeaninternal.server.querydefn.OrmQueryProperties;
@@ -287,6 +288,11 @@ public class DLoadContext implements LoadContext {
getBeanContext(path).register(ebi);
}
@Override
public void register(String path, EntityBeanIntercept ebi, BeanPropertyAssocOne<?> property) {
getBeanContextWithInherit(path, property).register(ebi);
}
@Override
public void register(String path, BeanCollection<?> bc) {
getManyContext(path).register(bc);
@@ -299,6 +305,11 @@ public class DLoadContext implements LoadContext {
return beanMap.computeIfAbsent(path, p -> createBeanContext(p, defaultBatchSize, null));
}
DLoadBeanContext getBeanContextWithInherit(String path, BeanPropertyAssocOne<?> property) {
String key = path + ":" + property.getTargetDescriptor().getName();
return beanMap.computeIfAbsent(key, p -> createBeanContext(property, path, defaultBatchSize, null));
}
private void registerSecondaryNode(boolean many, OrmQueryProperties props) {
int batchSize;
@@ -331,11 +342,14 @@ public class DLoadContext implements LoadContext {
}
private DLoadBeanContext createBeanContext(String path, int batchSize, OrmQueryProperties queryProps) {
BeanPropertyAssoc<?> p = (BeanPropertyAssoc<?>) getBeanProperty(rootDescriptor, path);
return new DLoadBeanContext(this, p.getTargetDescriptor(), path, batchSize, queryProps);
}
private DLoadBeanContext createBeanContext(BeanPropertyAssoc<?> property, String path, int batchSize, OrmQueryProperties queryProps) {
return new DLoadBeanContext(this, property.getTargetDescriptor(), path, batchSize, queryProps);
}
private BeanProperty getBeanProperty(BeanDescriptor<?> desc, String path) {
return desc.findPropertyFromPath(path);
}
@@ -21,6 +21,7 @@ import io.ebeaninternal.server.core.SpiOrmQueryRequest;
import io.ebeaninternal.server.deploy.BeanCollectionHelpFactory;
import io.ebeaninternal.server.deploy.BeanDescriptor;
import io.ebeaninternal.server.deploy.BeanPropertyAssocMany;
import io.ebeaninternal.server.deploy.BeanPropertyAssocOne;
import io.ebeaninternal.server.deploy.DbReadContext;
import io.ebeaninternal.server.type.DataBind;
import io.ebeaninternal.server.type.DataReader;
@@ -635,8 +636,13 @@ public class CQuery<T> implements DbReadContext, CancelableQuery, SpiProfileTran
}
@Override
public void register(String path, EntityBeanIntercept ebi) {
public void registerBeanInherit(BeanPropertyAssocOne<?> property, EntityBeanIntercept ebi) {
String path = getPath(property.getName());
request.getGraphContext().register(path, ebi, property);
}
@Override
public void register(String path, EntityBeanIntercept ebi) {
path = getPath(path);
request.getGraphContext().register(path, ebi);
}
@@ -595,7 +595,7 @@ class SqlTreeNodeBean implements SqlTreeNode {
ctx.append(" and");
}
ctx.append(" ").append(ctx.getTableAlias(prefix)).append(".");
ctx.append(inheritInfo.getWhere()).append(" ");
ctx.append(inheritInfo.getWhere());
}
}