mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-19 23:02:24 +00:00
#734 - Add ServerConfig.skipCacheAfterWrite & transaction.setSkipCache(boolean) ... to control L2 Bean cache use during transaction
This commit is contained in:
1 parent
c24ee53462
commit
a64a020e36
10 files changed
+290
-17
No files matched your search
@@ -991,7 +991,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
}
|
||||
}
|
||||
|
||||
if (!query.isUseBeanCache()) {
|
||||
if (!query.isUseBeanCache() || (t != null && t.isSkipCache())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1041,26 +1041,32 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T findUnique(Query<T> query, Transaction t) {
|
||||
public <T> T findUnique(Query<T> query, Transaction transaction) {
|
||||
|
||||
Object id = query.getId();
|
||||
if (id != null) {
|
||||
// actually a find by Id query
|
||||
return findId(query, t);
|
||||
return findId(query, transaction);
|
||||
}
|
||||
|
||||
SpiQuery<T> spiQuery = (SpiQuery<T>) query;
|
||||
BeanDescriptor<T> desc = spiQuery.getBeanDescriptor();
|
||||
|
||||
id = desc.cacheNaturalKeyIdLookup(spiQuery);
|
||||
if (id != null) {
|
||||
T bean = findIdCheckPersistenceContextAndCache(t, spiQuery, id);
|
||||
if (bean != null) {
|
||||
return bean;
|
||||
SpiTransaction t = (SpiTransaction) transaction;
|
||||
if (t == null) {
|
||||
t = getCurrentServerTransaction();
|
||||
}
|
||||
if (t == null || !t.isSkipCache()) {
|
||||
id = desc.cacheNaturalKeyIdLookup(spiQuery);
|
||||
if (id != null) {
|
||||
T bean = findIdCheckPersistenceContextAndCache(t, spiQuery, id);
|
||||
if (bean != null) {
|
||||
return bean;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// a query that is expected to return either 0 or 1 rows
|
||||
// a query that is expected to return either 0 or 1 beans
|
||||
List<T> list = findList(query, t);
|
||||
return extractUnique(list);
|
||||
}
|
||||
|
||||
@@ -326,7 +326,7 @@ final class BeanDescriptorCacheHelp<T> {
|
||||
|
||||
// try to lookup the id using the natural key
|
||||
Object id = naturalKeyCache.get(keyBindParam.getValue());
|
||||
if (natLog.isTraceEnabled() && id != null) {
|
||||
if (natLog.isTraceEnabled()) {
|
||||
natLog.trace(" LOOKUP {}({}) - id:{}", cacheName, keyBindParam.getValue(), id);
|
||||
}
|
||||
return id;
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.avaje.ebean.TransactionCallback;
|
||||
import com.avaje.ebean.annotation.DocStoreMode;
|
||||
import com.avaje.ebean.bean.PersistenceContext;
|
||||
import com.avaje.ebean.config.PersistBatch;
|
||||
import com.avaje.ebean.config.ServerConfig;
|
||||
import com.avaje.ebean.config.dbplatform.DatabasePlatform.OnQueryOnly;
|
||||
import com.avaje.ebean.event.changelog.BeanChange;
|
||||
import com.avaje.ebean.event.changelog.ChangeSet;
|
||||
@@ -151,6 +152,16 @@ public class JdbcTransaction implements SpiTransaction {
|
||||
|
||||
protected int docStoreBatchSize;
|
||||
|
||||
/**
|
||||
* Explicit control over skipCache.
|
||||
*/
|
||||
protected Boolean skipCache;
|
||||
|
||||
/**
|
||||
* Default skip cache behavior from {@link ServerConfig#isSkipCacheAfterWrite()}.
|
||||
*/
|
||||
protected final boolean skipCacheAfterWrite;
|
||||
|
||||
/**
|
||||
* Create a new JdbcTransaction.
|
||||
*/
|
||||
@@ -162,11 +173,20 @@ public class JdbcTransaction implements SpiTransaction {
|
||||
this.explicit = explicit;
|
||||
this.manager = manager;
|
||||
this.connection = connection;
|
||||
this.batchMode = manager == null ? PersistBatch.NONE : manager.getPersistBatch();
|
||||
this.batchOnCascadeMode = manager == null ? PersistBatch.NONE : manager.getPersistBatchOnCascade();
|
||||
this.onQueryOnly = manager == null ? OnQueryOnly.ROLLBACK : manager.getOnQueryOnly();
|
||||
this.persistenceContext = new DefaultPersistenceContext();
|
||||
|
||||
if (manager == null) {
|
||||
this.skipCacheAfterWrite = true;
|
||||
this.batchMode = PersistBatch.NONE;
|
||||
this.batchOnCascadeMode = PersistBatch.NONE;
|
||||
this.onQueryOnly = OnQueryOnly.ROLLBACK;
|
||||
} else {
|
||||
this.skipCacheAfterWrite = manager.isSkipCacheAfterWrite();
|
||||
this.batchMode = manager.getPersistBatch();
|
||||
this.batchOnCascadeMode = manager.getPersistBatchOnCascade();
|
||||
this.onQueryOnly = manager.getOnQueryOnly();
|
||||
}
|
||||
|
||||
checkAutoCommit(connection);
|
||||
|
||||
} catch (Exception e) {
|
||||
@@ -197,6 +217,17 @@ public class JdbcTransaction implements SpiTransaction {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSkipCache() {
|
||||
if (skipCache != null) return skipCache;
|
||||
return skipCacheAfterWrite && !queryOnly;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSkipCache(boolean skipCache) {
|
||||
this.skipCache = skipCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLogPrefix() {
|
||||
return logPrefix;
|
||||
|
||||
@@ -109,12 +109,15 @@ public class TransactionManager {
|
||||
|
||||
protected final boolean viewInvalidation;
|
||||
|
||||
private final boolean skipCacheAfterWrite;
|
||||
|
||||
/**
|
||||
* Create the TransactionManager
|
||||
*/
|
||||
public TransactionManager(boolean localL2Caching, ServerConfig config, ClusterManager clusterManager, BackgroundExecutor backgroundExecutor,
|
||||
DocStoreUpdateProcessor docStoreUpdateProcessor, BeanDescriptorManager descMgr, BootupClasses bootupClasses) {
|
||||
|
||||
this.skipCacheAfterWrite = config.isSkipCacheAfterWrite();
|
||||
this.localL2Caching = localL2Caching;
|
||||
this.persistBatch = config.getPersistBatch();
|
||||
this.persistBatchOnCascade = config.appliedPersistBatchOnCascade();
|
||||
@@ -149,6 +152,10 @@ public class TransactionManager {
|
||||
return docStoreActive;
|
||||
}
|
||||
|
||||
public boolean isSkipCacheAfterWrite() {
|
||||
return skipCacheAfterWrite;
|
||||
}
|
||||
|
||||
public BeanDescriptorManager getBeanDescriptorManager() {
|
||||
return beanDescriptorManager;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user