Refactor tidy on Load context

This commit is contained in:
rob bygrave
2019-08-18 12:17:36 +12:00
parent 16f6f2ee7f
commit d7d8c3e651
5 changed files with 34 additions and 37 deletions
@@ -25,7 +25,7 @@ import java.util.List;
/**
* Helper to handle lazy loading and refreshing of beans.
*/
public class DefaultBeanLoader {
class DefaultBeanLoader {
private static final Logger logger = LoggerFactory.getLogger(DefaultBeanLoader.class);
@@ -33,7 +33,7 @@ public class DefaultBeanLoader {
private final boolean onIterateUseExtraTxn;
protected DefaultBeanLoader(DefaultServer server) {
DefaultBeanLoader(DefaultServer server) {
this.server = server;
this.onIterateUseExtraTxn = server.getDatabasePlatform().useExtraTransactionOnIterateSecondaryQueries();
}
@@ -73,11 +73,11 @@ public class DefaultBeanLoader {
return batchSize;
}
public void refreshMany(EntityBean parentBean, String propertyName) {
void refreshMany(EntityBean parentBean, String propertyName) {
refreshMany(parentBean, propertyName, null);
}
public void loadMany(LoadManyRequest loadRequest) {
void loadMany(LoadManyRequest loadRequest) {
List<BeanCollection<?>> batch = loadRequest.getBatch();
@@ -89,7 +89,7 @@ public class DefaultBeanLoader {
loadRequest.postLoad();
}
public void loadMany(BeanCollection<?> bc, boolean onlyIds) {
void loadMany(BeanCollection<?> bc, boolean onlyIds) {
EntityBean parentBean = bc.getOwnerBean();
String propertyName = bc.getPropertyName();
@@ -97,7 +97,7 @@ public class DefaultBeanLoader {
loadManyInternal(parentBean, propertyName, null, false, onlyIds);
}
public void refreshMany(EntityBean parentBean, String propertyName, Transaction t) {
void refreshMany(EntityBean parentBean, String propertyName, Transaction t) {
loadManyInternal(parentBean, propertyName, t, true, false);
}
@@ -185,7 +185,7 @@ public class DefaultBeanLoader {
/**
* Load a batch of beans for +query or +lazy loading.
*/
public void loadBean(LoadBeanRequest loadRequest) {
void loadBean(LoadBeanRequest loadRequest) {
List<EntityBeanIntercept> batch = loadRequest.getBatch();
if (batch.isEmpty()) {
@@ -228,7 +228,7 @@ public class DefaultBeanLoader {
refreshBeanInternal(bean, SpiQuery.Mode.REFRESH_BEAN, -1);
}
public void loadBean(EntityBeanIntercept ebi) {
void loadBean(EntityBeanIntercept ebi) {
refreshBeanInternal(ebi.getOwner(), SpiQuery.Mode.LAZYLOAD_BEAN, -1);
}
@@ -10,7 +10,7 @@ import io.ebeaninternal.server.querydefn.OrmQueryProperties;
/**
* Base class for Bean and BeanCollection loading (lazy loading and query join loading).
*/
public abstract class DLoadBaseContext {
abstract class DLoadBaseContext {
protected final DLoadContext parent;
@@ -18,22 +18,21 @@ public abstract class DLoadBaseContext {
protected final String fullPath;
protected final OrmQueryProperties queryProps;
protected final boolean hitCache;
protected final String serverName;
protected final int firstBatchSize;
final OrmQueryProperties queryProps;
protected final int secondaryBatchSize;
final boolean hitCache;
protected final ObjectGraphNode objectGraphNode;
final int firstBatchSize;
protected final boolean queryFetch;
final int secondaryBatchSize;
final ObjectGraphNode objectGraphNode;
public DLoadBaseContext(DLoadContext parent, BeanDescriptor<?> desc, String path, int defaultBatchSize, OrmQueryProperties queryProps) {
final boolean queryFetch;
DLoadBaseContext(DLoadContext parent, BeanDescriptor<?> desc, String path, int defaultBatchSize, OrmQueryProperties queryProps) {
this.parent = parent;
this.serverName = parent.getEbeanServer().getName();
@@ -92,7 +91,7 @@ public abstract class DLoadBaseContext {
}
}
protected PersistenceContext getPersistenceContext() {
PersistenceContext getPersistenceContext() {
return parent.getPersistenceContext();
}
@@ -16,15 +16,15 @@ import java.util.List;
import java.util.Set;
/**
* Default implementation of LoadBeanContext.
* ToOne bean load context.
*/
public class DLoadBeanContext extends DLoadBaseContext implements LoadBeanContext {
class DLoadBeanContext extends DLoadBaseContext implements LoadBeanContext {
private List<LoadBuffer> bufferList;
private LoadBuffer currentBuffer;
public DLoadBeanContext(DLoadContext parent, BeanDescriptor<?> desc, String path, int defaultBatchSize, OrmQueryProperties queryProps) {
DLoadBeanContext(DLoadContext parent, BeanDescriptor<?> desc, String path, int defaultBatchSize, OrmQueryProperties queryProps) {
super(parent, desc, path, defaultBatchSize, queryProps);
// bufferList only required when using query joins (queryFetch)
this.bufferList = (!queryFetch) ? null : new ArrayList<>();
@@ -41,7 +41,7 @@ public class DLoadBeanContext extends DLoadBaseContext implements LoadBeanContex
currentBuffer = createBuffer(secondaryBatchSize);
}
protected void configureQuery(SpiQuery<?> query, String lazyLoadProperty) {
private void configureQuery(SpiQuery<?> query, String lazyLoadProperty) {
setLabel(query);
parent.propagateQueryState(query, desc.isDocStoreMapped());
@@ -79,8 +79,7 @@ public class DLoadBeanContext extends DLoadBaseContext implements LoadBeanContex
if (bufferList != null) {
for (LoadBuffer loadBuffer : bufferList) {
if (!loadBuffer.list.isEmpty()) {
LoadBeanRequest req = new LoadBeanRequest(loadBuffer, parentRequest);
parent.getEbeanServer().loadBean(req);
parent.getEbeanServer().loadBean(new LoadBeanRequest(loadBuffer, parentRequest));
if (!queryProps.isQueryFetchAll()) {
// Stop - only fetch the first batch ... the rest will be lazy loaded
break;
@@ -97,18 +96,17 @@ public class DLoadBeanContext extends DLoadBaseContext implements LoadBeanContex
}
}
/**
* A buffer for batch loading beans on a given path.
*/
public static class LoadBuffer implements BeanLoader, LoadBeanBuffer {
static class LoadBuffer implements BeanLoader, LoadBeanBuffer {
private final DLoadBeanContext context;
private final int batchSize;
private final List<EntityBeanIntercept> list;
private PersistenceContext persistenceContext;
public LoadBuffer(DLoadBeanContext context, int batchSize) {
LoadBuffer(DLoadBeanContext context, int batchSize) {
this.context = context;
this.batchSize = batchSize;
this.list = new ArrayList<>(batchSize);
@@ -224,10 +224,7 @@ public class DLoadContext implements LoadContext {
*/
private LoadSecondaryQuery getLoadSecondaryQuery(String path) {
LoadSecondaryQuery beanLoad = beanMap.get(path);
if (beanLoad == null) {
beanLoad = manyMap.get(path);
}
return beanLoad;
return beanLoad == null ? manyMap.get(path) : beanLoad;
}
@Override
@@ -17,7 +17,10 @@ import io.ebeaninternal.server.querydefn.OrmQueryProperties;
import java.util.ArrayList;
import java.util.List;
public class DLoadManyContext extends DLoadBaseContext implements LoadManyContext {
/**
* ToMany bean load context.
*/
class DLoadManyContext extends DLoadBaseContext implements LoadManyContext {
protected final BeanPropertyAssocMany<?> property;
@@ -27,7 +30,7 @@ public class DLoadManyContext extends DLoadBaseContext implements LoadManyContex
private LoadBuffer currentBuffer;
public DLoadManyContext(DLoadContext parent, BeanPropertyAssocMany<?> property,
DLoadManyContext(DLoadContext parent, BeanPropertyAssocMany<?> property,
String path, int defaultBatchSize, OrmQueryProperties queryProps) {
super(parent, property.getBeanDescriptor(), path, defaultBatchSize, queryProps);
@@ -57,7 +60,7 @@ public class DLoadManyContext extends DLoadBaseContext implements LoadManyContex
currentBuffer = createBuffer(secondaryBatchSize);
}
public void configureQuery(SpiQuery<?> query) {
private void configureQuery(SpiQuery<?> query) {
setLabel(query);
parent.propagateQueryState(query, docStoreMapped);
@@ -122,14 +125,14 @@ public class DLoadManyContext extends DLoadBaseContext implements LoadManyContex
* A buffer for batch loading bean collections on a given path.
* Supports batch lazy loading and secondary query loading.
*/
public static class LoadBuffer implements BeanCollectionLoader, LoadManyBuffer {
static class LoadBuffer implements BeanCollectionLoader, LoadManyBuffer {
private final PersistenceContext persistenceContext;
private final DLoadManyContext context;
private final int batchSize;
private final List<BeanCollection<?>> list;
public LoadBuffer(DLoadManyContext context, int batchSize) {
LoadBuffer(DLoadManyContext context, int batchSize) {
this.context = context;
// set the persistence context as at this moment in
// case it changes as part of a findIterate etc