mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Refactor tidy methods in LoadBeanRequest, LoadManyRequest, LoadRequest and DefaultBeanLoader
This commit is contained in:
@@ -47,7 +47,7 @@ public final class LoadBeanRequest extends LoadRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getBeanType() {
|
||||
public Class<?> beanType() {
|
||||
return loadBuffer.getBeanDescriptor().getBeanType();
|
||||
}
|
||||
|
||||
@@ -58,21 +58,10 @@ public final class LoadBeanRequest extends LoadRequest {
|
||||
/**
|
||||
* Return the batch of beans to actually load.
|
||||
*/
|
||||
public List<EntityBeanIntercept> getBatch() {
|
||||
public List<EntityBeanIntercept> batch() {
|
||||
return batch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the load context.
|
||||
*/
|
||||
private LoadBeanBuffer getLoadContext() {
|
||||
return loadBuffer;
|
||||
}
|
||||
|
||||
public int getBatchSize() {
|
||||
return getLoadContext().getBatchSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of Id values for the beans in the lazy load buffer.
|
||||
*/
|
||||
@@ -93,7 +82,7 @@ public final class LoadBeanRequest extends LoadRequest {
|
||||
query.setPersistenceContext(loadBuffer.getPersistenceContext());
|
||||
query.setLoadDescription(lazy ? "+lazy" : "+query", description());
|
||||
if (lazy) {
|
||||
query.setLazyLoadBatchSize(getBatchSize());
|
||||
query.setLazyLoadBatchSize(loadBuffer.getBatchSize());
|
||||
if (alreadyLoaded) {
|
||||
query.setBeanCacheMode(CacheMode.OFF);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public final class LoadManyRequest extends LoadRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getBeanType() {
|
||||
public Class<?> beanType() {
|
||||
return loadContext.getBeanDescriptor().getBeanType();
|
||||
}
|
||||
|
||||
@@ -56,30 +56,9 @@ public final class LoadManyRequest extends LoadRequest {
|
||||
return loadContext.getFullPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the batch of collections to actually load.
|
||||
*/
|
||||
public List<BeanCollection<?>> getBatch() {
|
||||
return batch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if we should load the Collection ids into the cache.
|
||||
*/
|
||||
private boolean isLoadCache() {
|
||||
return loadCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the batch size used for this load context.
|
||||
*/
|
||||
public int getBatchSize() {
|
||||
return loadContext.getBatchSize();
|
||||
}
|
||||
|
||||
private List<Object> parentIdList(SpiEbeanServer server) {
|
||||
List<Object> idList = new ArrayList<>();
|
||||
BeanPropertyAssocMany<?> many = getMany();
|
||||
BeanPropertyAssocMany<?> many = many();
|
||||
for (BeanCollection<?> bc : batch) {
|
||||
idList.add(many.getParentId(bc.getOwnerBean()));
|
||||
bc.setLoader(server); // don't use the load buffer again
|
||||
@@ -90,12 +69,12 @@ public final class LoadManyRequest extends LoadRequest {
|
||||
return idList;
|
||||
}
|
||||
|
||||
private BeanPropertyAssocMany<?> getMany() {
|
||||
private BeanPropertyAssocMany<?> many() {
|
||||
return loadContext.getBeanProperty();
|
||||
}
|
||||
|
||||
public SpiQuery<?> createQuery(SpiEbeanServer server) {
|
||||
BeanPropertyAssocMany<?> many = getMany();
|
||||
BeanPropertyAssocMany<?> many = many();
|
||||
SpiQuery<?> query = many.newQuery(server);
|
||||
String orderBy = many.getLazyFetchOrderBy();
|
||||
if (orderBy != null) {
|
||||
@@ -112,7 +91,7 @@ public final class LoadManyRequest extends LoadRequest {
|
||||
query.setPersistenceContext(loadContext.getPersistenceContext());
|
||||
query.setLoadDescription(lazy ? "+lazy" : "+query", description());
|
||||
if (lazy) {
|
||||
query.setLazyLoadBatchSize(getBatchSize());
|
||||
query.setLazyLoadBatchSize(loadContext.getBatchSize());
|
||||
} else {
|
||||
query.setBeanCacheMode(CacheMode.OFF);
|
||||
}
|
||||
@@ -130,7 +109,7 @@ public final class LoadManyRequest extends LoadRequest {
|
||||
*/
|
||||
public void postLoad() {
|
||||
BeanDescriptor<?> desc = loadContext.getBeanDescriptor();
|
||||
BeanPropertyAssocMany<?> many = getMany();
|
||||
BeanPropertyAssocMany<?> many = many();
|
||||
// check for BeanCollection's that where never processed
|
||||
// in the +query or +lazy load due to no rows (predicates)
|
||||
for (BeanCollection<?> bc : batch) {
|
||||
@@ -140,7 +119,7 @@ public final class LoadManyRequest extends LoadRequest {
|
||||
Object parentId = desc.getId(ownerBean);
|
||||
logger.debug("BeanCollection after lazy load was empty. type:" + ownerBean.getClass().getName() + " id:" + parentId + " owner:" + ownerBean);
|
||||
}
|
||||
} else if (isLoadCache() && many.isUseCache()) {
|
||||
} else if (loadCache && many.isUseCache()) {
|
||||
desc.cacheManyPropPut(many, bc, desc.getId(bc.getOwnerBean()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public abstract class LoadRequest {
|
||||
protected final Transaction transaction;
|
||||
protected final boolean lazy;
|
||||
|
||||
public LoadRequest(OrmQueryRequest<?> parentRequest, boolean lazy) {
|
||||
LoadRequest(OrmQueryRequest<?> parentRequest, boolean lazy) {
|
||||
this.parentRequest = parentRequest;
|
||||
this.transaction = parentRequest == null ? null : parentRequest.getTransaction();
|
||||
this.lazy = lazy;
|
||||
@@ -21,7 +21,7 @@ public abstract class LoadRequest {
|
||||
/**
|
||||
* Return the associated bean type for this load request.
|
||||
*/
|
||||
public abstract Class<?> getBeanType();
|
||||
public abstract Class<?> beanType();
|
||||
|
||||
/**
|
||||
* Return true if this is a lazy load and false if it is a secondary query.
|
||||
@@ -36,7 +36,7 @@ public abstract class LoadRequest {
|
||||
* Lazy loading queries run in their own transaction.
|
||||
* </p>
|
||||
*/
|
||||
public Transaction getTransaction() {
|
||||
public Transaction transaction() {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ final class DefaultBeanLoader {
|
||||
* Load a batch of beans for +query or +lazy loading.
|
||||
*/
|
||||
void loadBean(LoadBeanRequest loadRequest) {
|
||||
List<EntityBeanIntercept> batch = loadRequest.getBatch();
|
||||
List<EntityBeanIntercept> batch = loadRequest.batch();
|
||||
if (batch.isEmpty()) {
|
||||
throw new RuntimeException("Nothing in batch?");
|
||||
}
|
||||
@@ -140,7 +140,7 @@ final class DefaultBeanLoader {
|
||||
return;
|
||||
}
|
||||
|
||||
SpiQuery<?> query = server.createQuery(loadRequest.getBeanType());
|
||||
SpiQuery<?> query = server.createQuery(loadRequest.beanType());
|
||||
loadRequest.configureQuery(query, idList);
|
||||
List<?> list = executeQuery(loadRequest, query);
|
||||
loadRequest.postLoad(list);
|
||||
@@ -159,7 +159,7 @@ final class DefaultBeanLoader {
|
||||
extraTxn.end();
|
||||
}
|
||||
} else {
|
||||
return server.findList(query, loadRequest.getTransaction());
|
||||
return server.findList(query, loadRequest.transaction());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user