mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Merge pull request #2340 from ebean-orm/feature/2335
#2335 - L2 cache be triggered by in ?
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package io.ebeaninternal.api;
|
||||
|
||||
import io.ebean.CacheMode;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebean.bean.EntityBeanIntercept;
|
||||
import io.ebeaninternal.api.SpiQuery.Mode;
|
||||
import io.ebeaninternal.server.core.OrmQueryRequest;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
|
||||
@@ -19,30 +21,29 @@ public final class LoadBeanRequest extends LoadRequest {
|
||||
private final LoadBeanBuffer loadBuffer;
|
||||
private final String lazyLoadProperty;
|
||||
private final boolean loadCache;
|
||||
private boolean loadedFromCache;
|
||||
private final boolean alreadyLoaded;
|
||||
|
||||
/**
|
||||
* Construct for lazy load request.
|
||||
*/
|
||||
public LoadBeanRequest(LoadBeanBuffer LoadBuffer, EntityBeanIntercept ebi, boolean loadCache) {
|
||||
this(LoadBuffer, null, true, ebi.getLazyLoadProperty(), loadCache);
|
||||
this.loadedFromCache = ebi.isLoadedFromCache();
|
||||
public LoadBeanRequest(LoadBeanBuffer loadBuffer, EntityBeanIntercept ebi, boolean loadCache) {
|
||||
this(loadBuffer, null, true, ebi.getLazyLoadProperty(), ebi.isLoaded(), loadCache || ebi.isLoadedFromCache());
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct for secondary query.
|
||||
*/
|
||||
public LoadBeanRequest(LoadBeanBuffer LoadBuffer, OrmQueryRequest<?> parentRequest) {
|
||||
this(LoadBuffer, parentRequest, false, null, false);
|
||||
public LoadBeanRequest(LoadBeanBuffer loadBuffer, OrmQueryRequest<?> parentRequest) {
|
||||
this(loadBuffer, parentRequest, false, null, false, false);
|
||||
}
|
||||
|
||||
private LoadBeanRequest(LoadBeanBuffer loadBuffer, OrmQueryRequest<?> parentRequest, boolean lazy,
|
||||
String lazyLoadProperty, boolean loadCache) {
|
||||
|
||||
String lazyLoadProperty, boolean alreadyLoaded, boolean loadCache) {
|
||||
super(parentRequest, lazy);
|
||||
this.loadBuffer = loadBuffer;
|
||||
this.batch = loadBuffer.getBatch();
|
||||
this.lazyLoadProperty = lazyLoadProperty;
|
||||
this.alreadyLoaded = alreadyLoaded;
|
||||
this.loadCache = loadCache;
|
||||
}
|
||||
|
||||
@@ -51,17 +52,6 @@ public final class LoadBeanRequest extends LoadRequest {
|
||||
return loadBuffer.getBeanDescriptor().getBeanType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the beans invoking lazy loading were previously loaded from cache.
|
||||
*/
|
||||
public boolean isLoadedFromCache() {
|
||||
return loadedFromCache;
|
||||
}
|
||||
|
||||
private boolean isLoadCache() {
|
||||
return loadCache;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return "path:" + loadBuffer.getFullPath() + " batch:" + batch.size();
|
||||
}
|
||||
@@ -100,16 +90,21 @@ public final class LoadBeanRequest extends LoadRequest {
|
||||
* Configure the query for lazy loading execution.
|
||||
*/
|
||||
public void configureQuery(SpiQuery<?> query, List<Object> idList) {
|
||||
query.setMode(SpiQuery.Mode.LAZYLOAD_BEAN);
|
||||
query.setMode(Mode.LAZYLOAD_BEAN);
|
||||
query.setPersistenceContext(loadBuffer.getPersistenceContext());
|
||||
String mode = isLazy() ? "+lazy" : "+query";
|
||||
query.setLoadDescription(mode, getDescription());
|
||||
|
||||
if (isLazy()) {
|
||||
// cascade the batch size (if set) for further lazy loading
|
||||
query.setLoadDescription(lazy ? "+lazy" : "+query", getDescription());
|
||||
if (lazy) {
|
||||
query.setLazyLoadBatchSize(getBatchSize());
|
||||
if (alreadyLoaded) {
|
||||
query.setBeanCacheMode(CacheMode.OFF);
|
||||
}
|
||||
} else {
|
||||
query.setBeanCacheMode(CacheMode.OFF);
|
||||
}
|
||||
loadBuffer.configureQuery(query, lazyLoadProperty);
|
||||
if (loadCache) {
|
||||
query.setBeanCacheMode(CacheMode.PUT);
|
||||
}
|
||||
if (idList.size() == 1) {
|
||||
query.where().idEq(idList.get(0));
|
||||
} else {
|
||||
@@ -128,7 +123,7 @@ public final class LoadBeanRequest extends LoadRequest {
|
||||
EntityBean loadedBean = (EntityBean) bean;
|
||||
loadedIds.add(desc.getId(loadedBean));
|
||||
}
|
||||
if (isLoadCache()) {
|
||||
if (loadCache) {
|
||||
desc.cacheBeanPutAll(list);
|
||||
}
|
||||
if (lazyLoadProperty != null) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.ebeaninternal.api;
|
||||
|
||||
import io.ebean.CacheMode;
|
||||
import io.ebean.bean.BeanCollection;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebeaninternal.server.core.BindPadding;
|
||||
@@ -62,17 +63,6 @@ public final class LoadManyRequest extends LoadRequest {
|
||||
return batch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if lazy loading should only load the id values.
|
||||
* <p>
|
||||
* This for use when lazy loading is invoked on methods such as clear() and removeAll() where it
|
||||
* generally makes sense to only fetch the Id values as the other property information is not
|
||||
* used.
|
||||
*/
|
||||
private boolean isOnlyIds() {
|
||||
return onlyIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if we should load the Collection ids into the cache.
|
||||
*/
|
||||
@@ -111,31 +101,25 @@ public final class LoadManyRequest extends LoadRequest {
|
||||
if (orderBy != null) {
|
||||
query.order(orderBy);
|
||||
}
|
||||
|
||||
String extraWhere = many.getExtraWhere();
|
||||
if (extraWhere != null) {
|
||||
// replace special ${ta} placeholder with the base table alias
|
||||
// which is always t0 and add the extra where clause
|
||||
query.where().raw(extraWhere.replace("${ta}", "t0").replace("${mta}", "int_"));
|
||||
}
|
||||
|
||||
query.setLazyLoadForParents(many);
|
||||
many.addWhereParentIdIn(query, parentIdList(server), loadContext.isUseDocStore());
|
||||
query.setPersistenceContext(loadContext.getPersistenceContext());
|
||||
|
||||
String mode = isLazy() ? "+lazy" : "+query";
|
||||
query.setLoadDescription(mode, getDescription());
|
||||
|
||||
if (isLazy()) {
|
||||
// cascade the batch size (if set) for further lazy loading
|
||||
query.setLoadDescription(lazy ? "+lazy" : "+query", getDescription());
|
||||
if (lazy) {
|
||||
query.setLazyLoadBatchSize(getBatchSize());
|
||||
} else {
|
||||
query.setBeanCacheMode(CacheMode.OFF);
|
||||
}
|
||||
|
||||
// potentially changes the joins and selected properties
|
||||
// potentially changes the joins, selected properties, cache mode
|
||||
loadContext.configureQuery(query);
|
||||
|
||||
if (isOnlyIds()) {
|
||||
// override to just select the Id values
|
||||
if (onlyIds) {
|
||||
// lazy loading invoked via clear() and removeAll()
|
||||
query.select(many.getTargetIdProperty());
|
||||
}
|
||||
return query;
|
||||
|
||||
@@ -9,13 +9,10 @@ import io.ebeaninternal.server.core.OrmQueryRequest;
|
||||
public abstract class LoadRequest {
|
||||
|
||||
protected final OrmQueryRequest<?> parentRequest;
|
||||
|
||||
protected final Transaction transaction;
|
||||
|
||||
protected final boolean lazy;
|
||||
|
||||
public LoadRequest(OrmQueryRequest<?> parentRequest, boolean lazy) {
|
||||
|
||||
this.parentRequest = parentRequest;
|
||||
this.transaction = parentRequest == null ? null : parentRequest.getTransaction();
|
||||
this.lazy = lazy;
|
||||
|
||||
@@ -147,10 +147,6 @@ final class DefaultBeanLoader {
|
||||
|
||||
SpiQuery<?> query = server.createQuery(loadRequest.getBeanType());
|
||||
loadRequest.configureQuery(query, idList);
|
||||
if (loadRequest.isLoadedFromCache()) {
|
||||
query.setBeanCacheMode(CacheMode.PUT);
|
||||
}
|
||||
|
||||
List<?> list = executeQuery(loadRequest, query);
|
||||
loadRequest.postLoad(list);
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ public final class DefaultOrmQueryEngine implements OrmQueryEngine {
|
||||
|
||||
SpiQuery<T> query = request.getQuery();
|
||||
|
||||
if (request.isBeanCachePutMany()) {
|
||||
if (result != null && request.isBeanCachePutMany()) {
|
||||
// load the individual beans into the bean cache
|
||||
BeanDescriptor<T> descriptor = request.getBeanDescriptor();
|
||||
Collection<T> c = result.getActualDetails();
|
||||
|
||||
@@ -1232,10 +1232,8 @@ public final class DefaultOrmQuery<T> extends AbstractQuery implements SpiQuery<
|
||||
|
||||
@Override
|
||||
public void resetBeanCacheAutoMode(boolean findOne) {
|
||||
if (useBeanCache == CacheMode.AUTO) {
|
||||
if (!findOne || useQueryCache != CacheMode.OFF) {
|
||||
useBeanCache = CacheMode.OFF;
|
||||
}
|
||||
if (useBeanCache == CacheMode.AUTO && useQueryCache != CacheMode.OFF) {
|
||||
useBeanCache = CacheMode.OFF;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user