Merge pull request #3007 from ebean-orm/refactor/rename-loadContext-methods

Refactor rename methods in LoadContext
This commit is contained in:
Rob Bygrave
2023-03-25 15:39:40 +13:00
committed by GitHub
12 changed files with 61 additions and 78 deletions
@@ -13,7 +13,7 @@ public interface BeanLoader {
/**
* Return the name of the associated Database.
*/
String getName();
String name();
/**
* Invoke the lazy loading for this bean.
@@ -192,13 +192,13 @@ public final class InterceptReadWrite implements EntityBeanIntercept {
public void setBeanLoader(BeanLoader beanLoader, PersistenceContext ctx) {
this.beanLoader = beanLoader;
this.persistenceContext = ctx;
this.ebeanServerName = beanLoader.getName();
this.ebeanServerName = beanLoader.name();
}
@Override
public void setBeanLoader(BeanLoader beanLoader) {
this.beanLoader = beanLoader;
this.ebeanServerName = beanLoader.getName();
this.ebeanServerName = beanLoader.name();
}
@Override
@@ -19,7 +19,7 @@ public abstract class SingleBeanLoader implements BeanLoader {
}
@Override
public String getName() {
public String name() {
return database.name();
}
@@ -16,7 +16,7 @@ public interface LoadContext {
/**
* Return the minimum batch size when using QueryIterator with query joins.
*/
int getSecondaryQueriesMinBatchSize();
int secondaryQueriesMinBatchSize();
/**
* Execute any secondary (+query) queries if there are any defined.
@@ -29,12 +29,12 @@ public interface LoadContext {
/**
* Return the node for a given path which is used by AutoTune profiling.
*/
ObjectGraphNode getObjectGraphNode(String path);
ObjectGraphNode objectGraphNode(String path);
/**
* Return the persistence context used by this query and future lazy loading.
*/
PersistenceContext getPersistenceContext();
PersistenceContext persistenceContext();
/**
* Register a Bean for lazy loading.
@@ -31,15 +31,15 @@ public interface LoadManyBuffer {
*/
boolean removeFromBuffer(BeanCollection<?> collection);
BeanPropertyAssocMany<?> getBeanProperty();
BeanPropertyAssocMany<?> beanProperty();
ObjectGraphNode getObjectGraphNode();
ObjectGraphNode objectGraphNode();
BeanDescriptor<?> getBeanDescriptor();
BeanDescriptor<?> descriptor();
PersistenceContext getPersistenceContext();
PersistenceContext persistenceContext();
String getFullPath();
String fullPath();
void configureQuery(SpiQuery<?> query);
@@ -50,11 +50,11 @@ public final class LoadManyRequest extends LoadRequest {
@Override
public Class<?> beanType() {
return loadContext.getBeanDescriptor().type();
return loadContext.descriptor().type();
}
public String description() {
return loadContext.getFullPath();
return loadContext.fullPath();
}
private List<Object> parentIdList(SpiEbeanServer server) {
@@ -82,7 +82,7 @@ public final class LoadManyRequest extends LoadRequest {
}
private BeanPropertyAssocMany<?> many() {
return loadContext.getBeanProperty();
return loadContext.beanProperty();
}
public SpiQuery<?> createQuery(SpiEbeanServer server) {
@@ -100,7 +100,7 @@ public final class LoadManyRequest extends LoadRequest {
}
query.setLazyLoadForParents(many);
many.addWhereParentIdIn(query, parentIdList(server), loadContext.isUseDocStore());
query.setPersistenceContext(loadContext.getPersistenceContext());
query.setPersistenceContext(loadContext.persistenceContext());
query.setLoadDescription(lazy ? "+lazy" : "+query", description());
if (lazy) {
query.setLazyLoadBatchSize(loadContext.batchSize());
@@ -120,7 +120,7 @@ public final class LoadManyRequest extends LoadRequest {
* After the query execution check for empty collections and load L2 cache if desired.
*/
public void postLoad() {
BeanDescriptor<?> desc = loadContext.getBeanDescriptor();
BeanDescriptor<?> desc = loadContext.descriptor();
BeanPropertyAssocMany<?> many = many();
// check for BeanCollection's that where never processed
// in the +query or +lazy load due to no rows (predicates)
@@ -127,7 +127,7 @@ public final class OrmQueryRequest<T> extends BeanRequest implements SpiOrmQuery
* iteration is fine.
*/
public int secondaryQueriesMinBatchSize() {
return loadContext.getSecondaryQueriesMinBatchSize();
return loadContext.secondaryQueriesMinBatchSize();
}
/**
@@ -35,12 +35,12 @@ abstract class DLoadBaseContext {
DLoadBaseContext(DLoadContext parent, BeanDescriptor<?> desc, String path, OrmQueryProperties queryProps) {
this.parent = parent;
this.serverName = parent.getEbeanServer().name();
this.serverName = parent.server().name();
this.desc = desc;
this.queryProps = queryProps;
this.fullPath = parent.getFullPath(path);
this.fullPath = parent.fullPath(path);
this.hitCache = parent.isBeanCacheGet() && desc.isBeanCaching();
this.objectGraphNode = parent.getObjectGraphNode(path);
this.objectGraphNode = parent.objectGraphNode(path);
this.queryFetch = queryProps != null && queryProps.isQueryFetch();
this.batchSize = parent.batchSize(queryProps);
}
@@ -50,14 +50,14 @@ abstract class DLoadBaseContext {
* set onto the secondary query.
*/
void setLabel(SpiQuery<?> query) {
String label = parent.getPlanLabel();
String label = parent.planLabel();
if (label != null) {
query.setProfilePath(label, fullPath, parent.getProfileLocation());
query.setProfilePath(label, fullPath, parent.profileLocation());
}
}
PersistenceContext getPersistenceContext() {
return parent.getPersistenceContext();
PersistenceContext persistenceContext() {
return parent.persistenceContext();
}
}
@@ -71,7 +71,7 @@ final class DLoadBeanContext extends DLoadBaseContext implements LoadBeanContext
if (currentBuffer.isFull()) {
currentBuffer = createBuffer(batchSize);
}
ebi.setBeanLoader(currentBuffer, getPersistenceContext());
ebi.setBeanLoader(currentBuffer, persistenceContext());
currentBuffer.add(ebi);
}
@@ -93,7 +93,7 @@ final class DLoadBeanContext extends DLoadBaseContext implements LoadBeanContext
if (bufferList != null) {
for (LoadBuffer loadBuffer : bufferList) {
if (!loadBuffer.batch.isEmpty()) {
parent.getEbeanServer().loadBean(new LoadBeanRequest(loadBuffer, parentRequest));
parent.server().loadBean(new LoadBeanRequest(loadBuffer, parentRequest));
}
if (forEach) {
clear();
@@ -165,7 +165,7 @@ final class DLoadBeanContext extends DLoadBaseContext implements LoadBeanContext
}
@Override
public String getName() {
public String name() {
return context.serverName;
}
@@ -2,24 +2,11 @@ package io.ebeaninternal.server.loadcontext;
import io.ebean.CacheMode;
import io.ebean.ProfileLocation;
import io.ebean.bean.BeanCollection;
import io.ebean.bean.CallOrigin;
import io.ebean.bean.EntityBeanIntercept;
import io.ebean.bean.ObjectGraphNode;
import io.ebean.bean.ObjectGraphOrigin;
import io.ebean.bean.PersistenceContext;
import io.ebeaninternal.api.LoadContext;
import io.ebeaninternal.api.LoadSecondaryQuery;
import io.ebeaninternal.api.SpiEbeanServer;
import io.ebeaninternal.api.SpiQuery;
import io.ebeaninternal.api.SpiQuerySecondary;
import io.ebean.bean.*;
import io.ebeaninternal.api.*;
import io.ebeaninternal.server.autotune.ProfilingListener;
import io.ebeaninternal.server.core.OrmQueryRequest;
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.deploy.*;
import io.ebeaninternal.server.el.ElPropertyValue;
import io.ebeaninternal.server.querydefn.OrmQueryProperties;
@@ -127,14 +114,14 @@ public final class DLoadContext implements LoadContext {
/**
* Return the query plan label of the origin query.
*/
String getPlanLabel() {
String planLabel() {
return planLabel;
}
/**
* Return the profile location of the origin query.
*/
public ProfileLocation getProfileLocation() {
public ProfileLocation profileLocation() {
return profileLocation;
}
@@ -179,7 +166,7 @@ public final class DLoadContext implements LoadContext {
* Return the minimum batch size when using QueryIterator with query joins.
*/
@Override
public int getSecondaryQueriesMinBatchSize() {
public int secondaryQueriesMinBatchSize() {
if (secQuery == null) {
return -1;
}
@@ -201,7 +188,7 @@ public final class DLoadContext implements LoadContext {
public void executeSecondaryQueries(OrmQueryRequest<?> parentRequest, boolean forEach) {
if (secQuery != null) {
for (OrmQueryProperties aSecQuery : secQuery) {
LoadSecondaryQuery load = getLoadSecondaryQuery(aSecQuery.getPath());
LoadSecondaryQuery load = loadSecondaryQuery(aSecQuery.getPath());
load.loadSecondaryQuery(parentRequest, forEach);
}
}
@@ -210,13 +197,13 @@ public final class DLoadContext implements LoadContext {
/**
* Return the LoadBeanContext or LoadManyContext for the given path.
*/
private LoadSecondaryQuery getLoadSecondaryQuery(String path) {
private LoadSecondaryQuery loadSecondaryQuery(String path) {
LoadSecondaryQuery beanLoad = beanMap.get(path);
return beanLoad == null ? manyMap.get(path) : beanLoad;
}
@Override
public ObjectGraphNode getObjectGraphNode(String path) {
public ObjectGraphNode objectGraphNode(String path) {
return nodePathMap.computeIfAbsent(path, this::createObjectGraphNode);
}
@@ -231,7 +218,7 @@ public final class DLoadContext implements LoadContext {
return new ObjectGraphNode(origin, path);
}
String getFullPath(String path) {
String fullPath(String path) {
if (relativePath == null) {
return path;
} else {
@@ -239,7 +226,7 @@ public final class DLoadContext implements LoadContext {
}
}
SpiEbeanServer getEbeanServer() {
SpiEbeanServer server() {
return ebeanServer;
}
@@ -252,23 +239,23 @@ public final class DLoadContext implements LoadContext {
}
@Override
public PersistenceContext getPersistenceContext() {
public PersistenceContext persistenceContext() {
return persistenceContext;
}
@Override
public void register(String path, EntityBeanIntercept ebi) {
getBeanContext(path).register(ebi);
beanContext(path).register(ebi);
}
@Override
public void register(String path, EntityBeanIntercept ebi, BeanPropertyAssocOne<?> property) {
getBeanContextWithInherit(path, property).register(ebi);
beanContextWithInherit(path, property).register(ebi);
}
@Override
public void register(String path, BeanPropertyAssocMany<?> many, BeanCollection<?> bc) {
getManyContext(path, many).register(bc);
manyContext(path, many).register(bc);
}
int batchSize(OrmQueryProperties props) {
@@ -279,14 +266,14 @@ public final class DLoadContext implements LoadContext {
return batchSize == 0 ? defaultBatchSize : batchSize;
}
DLoadBeanContext getBeanContext(String path) {
DLoadBeanContext beanContext(String path) {
if (path == null) {
return rootBeanContext;
}
return beanMap.computeIfAbsent(path, p -> createBeanContext(p, null));
}
DLoadBeanContext getBeanContextWithInherit(String path, BeanPropertyAssocOne<?> property) {
DLoadBeanContext beanContextWithInherit(String path, BeanPropertyAssocOne<?> property) {
String key = path + ":" + property.targetDescriptor().name();
return beanMap.computeIfAbsent(key, p -> createBeanContext(property, path));
}
@@ -300,7 +287,7 @@ public final class DLoadContext implements LoadContext {
}
}
DLoadManyContext getManyContext(String path, BeanPropertyAssocMany<?> many) {
DLoadManyContext manyContext(String path, BeanPropertyAssocMany<?> many) {
return manyMap.computeIfAbsent(path, p -> createManyContext(p, many));
}
@@ -309,12 +296,12 @@ public final class DLoadContext implements LoadContext {
}
private DLoadManyContext createManyContext(String path, OrmQueryProperties queryProps) {
BeanPropertyAssocMany<?> p = (BeanPropertyAssocMany<?>) getBeanProperty(rootDescriptor, path);
BeanPropertyAssocMany<?> p = (BeanPropertyAssocMany<?>) beanProperty(rootDescriptor, path);
return new DLoadManyContext(this, p, path, queryProps);
}
private DLoadBeanContext createBeanContext(String path, OrmQueryProperties queryProps) {
BeanPropertyAssoc<?> p = (BeanPropertyAssoc<?>) getBeanProperty(rootDescriptor, path);
BeanPropertyAssoc<?> p = (BeanPropertyAssoc<?>) beanProperty(rootDescriptor, path);
return new DLoadBeanContext(this, p.targetDescriptor(), path, queryProps);
}
@@ -322,7 +309,7 @@ public final class DLoadContext implements LoadContext {
return new DLoadBeanContext(this, property.targetDescriptor(), path, null);
}
private BeanProperty getBeanProperty(BeanDescriptor<?> desc, String path) {
private BeanProperty beanProperty(BeanDescriptor<?> desc, String path) {
return desc.findPropertyFromPath(path);
}
@@ -1,10 +1,6 @@
package io.ebeaninternal.server.loadcontext;
import io.ebean.bean.BeanCollection;
import io.ebean.bean.BeanCollectionLoader;
import io.ebean.bean.EntityBean;
import io.ebean.bean.ObjectGraphNode;
import io.ebean.bean.PersistenceContext;
import io.ebean.bean.*;
import io.ebeaninternal.api.LoadManyBuffer;
import io.ebeaninternal.api.LoadManyContext;
import io.ebeaninternal.api.LoadManyRequest;
@@ -77,7 +73,7 @@ final class DLoadManyContext extends DLoadBaseContext implements LoadManyContext
public String getName() {
return parent.getEbeanServer().name();
return parent.server().name();
}
public void register(BeanCollection<?> bc) {
@@ -99,7 +95,7 @@ final class DLoadManyContext extends DLoadBaseContext implements LoadManyContext
for (LoadBuffer loadBuffer : bufferList) {
if (loadBuffer.size() > 0) {
LoadManyRequest req = new LoadManyRequest(loadBuffer, parentRequest);
parent.getEbeanServer().loadMany(req);
parent.server().loadMany(req);
}
}
if (forEach) {
@@ -129,7 +125,7 @@ final class DLoadManyContext extends DLoadBaseContext implements LoadManyContext
this.context = context;
// set the persistence context as at this moment in
// case it changes as part of a findIterate etc
this.persistenceContext = context.getPersistenceContext();
this.persistenceContext = context.persistenceContext();
this.batchSize = batchSize;
}
@@ -158,12 +154,12 @@ final class DLoadManyContext extends DLoadBaseContext implements LoadManyContext
abstract void clear();
@Override
public BeanPropertyAssocMany<?> getBeanProperty() {
public BeanPropertyAssocMany<?> beanProperty() {
return context.property;
}
@Override
public ObjectGraphNode getObjectGraphNode() {
public ObjectGraphNode objectGraphNode() {
return context.objectGraphNode;
}
@@ -178,17 +174,17 @@ final class DLoadManyContext extends DLoadBaseContext implements LoadManyContext
}
@Override
public BeanDescriptor<?> getBeanDescriptor() {
public BeanDescriptor<?> descriptor() {
return context.desc;
}
@Override
public PersistenceContext getPersistenceContext() {
public PersistenceContext persistenceContext() {
return persistenceContext;
}
@Override
public String getFullPath() {
public String fullPath() {
return context.fullPath;
}
@@ -205,14 +201,14 @@ final class DLoadManyContext extends DLoadBaseContext implements LoadManyContext
if (parentDesc.cacheManyPropLoad(context.property, bc, parentKey, context.parent.isReadOnly())) {
// we loaded the bean collection from cache so remove it from the buffer
if (removeFromBuffer(bc)) {
bc.setLoader(context.parent.getEbeanServer());
bc.setLoader(context.parent.server());
}
// find it using instance equality - avoiding equals() and potential deadlock issue
return;
}
}
context.parent.getEbeanServer().loadMany(new LoadManyRequest(this, onlyIds, useCache, bc));
context.parent.server().loadMany(new LoadManyRequest(this, onlyIds, useCache, bc));
// clear the buffer as all entries have been loaded
clear();
} finally {
@@ -661,7 +661,7 @@ public final class CQuery<T> implements DbReadContext, CancelableQuery, SpiProfi
@Override
public void profileBean(EntityBeanIntercept ebi, String prefix) {
ObjectGraphNode node = request.loadContext().getObjectGraphNode(prefix);
ObjectGraphNode node = request.loadContext().objectGraphNode(prefix);
ebi.setNodeUsageCollector(new NodeUsageCollector(node, profilingListener));
}