git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@661800 13f79535-47bb-0310-9956-ffa450edef68

This commit is contained in:
Pinaki Poddar 2008-05-30 18:10:50 +00:00
parent 89b296fd54
commit 794305c2f1
4 changed files with 94 additions and 18 deletions

View File

@ -29,6 +29,7 @@ import org.apache.openjpa.event.RemoteCommitEventManager;
import org.apache.openjpa.event.RemoteCommitProvider; import org.apache.openjpa.event.RemoteCommitProvider;
import org.apache.openjpa.kernel.AutoClear; import org.apache.openjpa.kernel.AutoClear;
import org.apache.openjpa.kernel.AutoDetach; import org.apache.openjpa.kernel.AutoDetach;
import org.apache.openjpa.kernel.Broker;
import org.apache.openjpa.kernel.BrokerFactory; import org.apache.openjpa.kernel.BrokerFactory;
import org.apache.openjpa.kernel.BrokerImpl; import org.apache.openjpa.kernel.BrokerImpl;
import org.apache.openjpa.kernel.ConnectionRetainModes; import org.apache.openjpa.kernel.ConnectionRetainModes;
@ -331,6 +332,36 @@ public interface OpenJPAConfiguration
*/ */
public void setDataCacheTimeout(Integer timeout); public void setDataCacheTimeout(Integer timeout);
/**
* Gets whether entity state is to be refreshed from {@link DataCache}.
* The entities are never refreshed from DataCache if lock is being applied
* (e.g. in a pessimistic transaction) and hence this setting only refers
* to behavior when not locking.
*
* @since 1.1.1
*/
public boolean getRefreshFromDataCache();
/**
* Sets whether entity state is to be refreshed from {@link DataCache}.
* The entities are never refreshed from DataCache if lock is being applied
* (e.g. in a pessimistic transaction) and hence this setting only refers
* to behavior when not locking.
*
* @since 1.1.
*/
public void setRefreshFromDataCache(boolean refreshFromDataCache);
/**
* Sets whether entity state is to be refreshed from {@link DataCache}.
* The entities are never refreshed from DataCache if lock is being applied
* (e.g. in a pessimistic transaction) and hence this setting only refers
* to behavior when not locking.
*
* @since 1.1.1
*/
public void setRefreshFromDataCache(Boolean refreshFromDataCache);
/** /**
* The plugin to use for level-2 data store query caching. * The plugin to use for level-2 data store query caching.
* *

View File

@ -122,6 +122,7 @@ public class OpenJPAConfigurationImpl
public BooleanValue ignoreChanges; public BooleanValue ignoreChanges;
public BooleanValue nontransactionalRead; public BooleanValue nontransactionalRead;
public BooleanValue nontransactionalWrite; public BooleanValue nontransactionalWrite;
public BooleanValue refreshFromDataCache;
public BooleanValue multithreaded; public BooleanValue multithreaded;
public StringValue mapping; public StringValue mapping;
public PluginValue metaFactoryPlugin; public PluginValue metaFactoryPlugin;
@ -223,6 +224,11 @@ public class OpenJPAConfigurationImpl
queryCachePlugin.setDefault(aliases[0]); queryCachePlugin.setDefault(aliases[0]);
queryCachePlugin.setString(aliases[0]); queryCachePlugin.setString(aliases[0]);
refreshFromDataCache = addBoolean("RefreshFromDataCache");
refreshFromDataCache.setDefault("false");
refreshFromDataCache.set(false);
refreshFromDataCache.setDynamic(true);
dynamicDataStructs = addBoolean("DynamicDataStructs"); dynamicDataStructs = addBoolean("DynamicDataStructs");
dynamicDataStructs.setDefault("false"); dynamicDataStructs.setDefault("false");
dynamicDataStructs.set(false); dynamicDataStructs.set(false);
@ -645,6 +651,20 @@ public class OpenJPAConfigurationImpl
return queryCachePlugin.getString(); return queryCachePlugin.getString();
} }
public boolean getRefreshFromDataCache() {
return refreshFromDataCache.get();
}
public void setRefreshFromDataCache(boolean flag) {
refreshFromDataCache.set(flag);
}
public void setRefreshFromDataCache(Boolean flag) {
if (flag != null) {
refreshFromDataCache.set(flag.booleanValue());
}
}
public boolean getDynamicDataStructs() { public boolean getDynamicDataStructs() {
return dynamicDataStructs.get(); return dynamicDataStructs.get();
} }

View File

@ -423,8 +423,12 @@ public class DataCacheStoreManager
public Collection loadAll(Collection sms, PCState state, int load, public Collection loadAll(Collection sms, PCState state, int load,
FetchConfiguration fetch, Object edata) { FetchConfiguration fetch, Object edata) {
if (load == StoreManager.FORCE_LOAD_REFRESH || isLocking(fetch)) if (isLocking(fetch) ||
(!isLocking(fetch) &&
(load == StoreManager.FORCE_LOAD_REFRESH)
&& !_ctx.getConfiguration().getRefreshFromDataCache())) {
return super.loadAll(sms, state, load, fetch, edata); return super.loadAll(sms, state, load, fetch, edata);
}
Map unloaded = null; Map unloaded = null;
List smList = null; List smList = null;

View File

@ -286,10 +286,11 @@ public class TestDataCacheBehavesIdentical extends AbstractTestCase {
*/ */
public void verifyRefresh(boolean useDataCache, LockModeType lock, public void verifyRefresh(boolean useDataCache, LockModeType lock,
boolean makeDirtyBeforeRefresh, String expected) { boolean makeDirtyBeforeRefresh, boolean refreshFromDataCache,
String expected) {
OpenJPAEntityManagerFactorySPI emf = (useDataCache) OpenJPAEntityManagerFactorySPI emf = (useDataCache)
? emfWithDataCache : emfWithoutDataCache; ? emfWithDataCache : emfWithoutDataCache;
emf.getConfiguration().setRefreshFromDataCache(refreshFromDataCache);
OpenJPAEntityManagerSPI em = emf.createEntityManager(); OpenJPAEntityManagerSPI em = emf.createEntityManager();
em.getTransaction().begin(); em.getTransaction().begin();
@ -364,39 +365,59 @@ public class TestDataCacheBehavesIdentical extends AbstractTestCase {
} }
public void testDirtyRefreshWithNoLockHitsDatabase() { public void testDirtyRefreshWithNoLockHitsDatabase() {
verifyRefresh(WITH_DATACACHE, NOLOCK, DIRTY, MARKER_DATABASE); verifyRefresh(WITH_DATACACHE, NOLOCK, DIRTY, false, MARKER_DATABASE);
}
public void testDirtyRefreshWithNoLockHitsDataCache() {
verifyRefresh(WITH_DATACACHE, NOLOCK, DIRTY, true, MARKER_DATACACHE);
} }
public void testCleanRefreshWithNoLockHitsDatabase() { public void testCleanRefreshWithNoLockHitsDatabase() {
verifyRefresh(WITH_DATACACHE, NOLOCK, !DIRTY, MARKER_DATABASE); verifyRefresh(WITH_DATACACHE, NOLOCK, !DIRTY, false, MARKER_DATABASE);
}
public void testCleanRefreshWithNoLockHitsDataCache() {
verifyRefresh(WITH_DATACACHE, NOLOCK, !DIRTY, true, MARKER_DATACACHE);
} }
public void testDirtyRefreshWithReadLockHitsDatabase() { public void testDirtyRefreshWithReadLockHitsDatabase() {
verifyRefresh(WITH_DATACACHE, LockModeType.READ, DIRTY, MARKER_DATABASE); verifyRefresh(WITH_DATACACHE, LockModeType.READ, DIRTY, true, MARKER_DATABASE);
verifyRefresh(WITH_DATACACHE, LockModeType.READ, DIRTY, false, MARKER_DATABASE);
} }
public void testCleanRefreshWithReadLockHitsDatabase() { public void testCleanRefreshWithReadLockHitsDatabase() {
verifyRefresh(WITH_DATACACHE, LockModeType.READ, !DIRTY, MARKER_DATABASE); verifyRefresh(WITH_DATACACHE, LockModeType.READ, !DIRTY, true, MARKER_DATABASE);
verifyRefresh(WITH_DATACACHE, LockModeType.READ, !DIRTY, false, MARKER_DATABASE);
} }
public void testDirtyRefreshWithWriteLockHitsDatabase() { public void testDirtyRefreshWithWriteLockHitsDatabase() {
verifyRefresh(WITH_DATACACHE, LockModeType.WRITE, DIRTY, MARKER_DATABASE); verifyRefresh(WITH_DATACACHE, LockModeType.WRITE, DIRTY, true, MARKER_DATABASE);
verifyRefresh(WITH_DATACACHE, LockModeType.WRITE, DIRTY, false, MARKER_DATABASE);
} }
public void testCleanRefreshWithWriteLockHitsDatabase() { public void testCleanRefreshWithWriteLockHitsDatabase() {
verifyRefresh(WITH_DATACACHE, LockModeType.WRITE, !DIRTY, MARKER_DATABASE); verifyRefresh(WITH_DATACACHE, LockModeType.WRITE, !DIRTY, true, MARKER_DATABASE);
verifyRefresh(WITH_DATACACHE, LockModeType.WRITE, !DIRTY, false, MARKER_DATABASE);
} }
public void testDirtyRefreshWithoutDataCacheAlwaysHitsDatabase() { public void testDirtyRefreshWithoutDataCacheAlwaysHitsDatabase() {
verifyRefresh(!WITH_DATACACHE, NOLOCK, DIRTY, MARKER_DATABASE); verifyRefresh(!WITH_DATACACHE, NOLOCK, DIRTY, true, MARKER_DATABASE);
verifyRefresh(!WITH_DATACACHE, LockModeType.READ, DIRTY, MARKER_DATABASE); verifyRefresh(!WITH_DATACACHE, LockModeType.READ, DIRTY, true, MARKER_DATABASE);
verifyRefresh(!WITH_DATACACHE, LockModeType.WRITE, DIRTY, MARKER_DATABASE); verifyRefresh(!WITH_DATACACHE, LockModeType.WRITE, DIRTY, true, MARKER_DATABASE);
verifyRefresh(!WITH_DATACACHE, NOLOCK, DIRTY, false, MARKER_DATABASE);
verifyRefresh(!WITH_DATACACHE, LockModeType.READ, DIRTY, false, MARKER_DATABASE);
verifyRefresh(!WITH_DATACACHE, LockModeType.WRITE, DIRTY, false, MARKER_DATABASE);
} }
public void testCleanRefreshWithoutDataCacheAlwaysHitsDatabase() { public void testCleanRefreshWithoutDataCacheAlwaysHitsDatabase() {
verifyRefresh(!WITH_DATACACHE, NOLOCK, !DIRTY, MARKER_DATABASE); verifyRefresh(!WITH_DATACACHE, NOLOCK, !DIRTY, true, MARKER_DATABASE);
verifyRefresh(!WITH_DATACACHE, LockModeType.READ, !DIRTY, MARKER_DATABASE); verifyRefresh(!WITH_DATACACHE, LockModeType.READ, !DIRTY, true, MARKER_DATABASE);
verifyRefresh(!WITH_DATACACHE, LockModeType.WRITE, !DIRTY, MARKER_DATABASE); verifyRefresh(!WITH_DATACACHE, LockModeType.WRITE, !DIRTY, true, MARKER_DATABASE);
verifyRefresh(!WITH_DATACACHE, NOLOCK, !DIRTY, false, MARKER_DATABASE);
verifyRefresh(!WITH_DATACACHE, LockModeType.READ, !DIRTY, false, MARKER_DATABASE);
verifyRefresh(!WITH_DATACACHE, LockModeType.WRITE, !DIRTY, false, MARKER_DATABASE);
} }
/** /**