clean up CacheModeHelper

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-04-27 23:20:20 +02:00
parent 07dc9f0a68
commit 39a6f9880b
1 changed files with 19 additions and 47 deletions

View File

@ -42,22 +42,18 @@ public final class CacheModeHelper {
retrieveMode = DEFAULT_RETRIEVE_MODE;
}
final boolean get = ( CacheRetrieveMode.USE == retrieveMode );
final boolean get = CacheRetrieveMode.USE == retrieveMode;
switch ( storeMode ) {
case USE: {
case USE:
return get ? CacheMode.NORMAL : CacheMode.PUT;
}
case REFRESH: {
case BYPASS:
return get ? CacheMode.GET : CacheMode.IGNORE;
case REFRESH:
// really (get == true) here is a bit of an invalid combo...
return CacheMode.REFRESH;
}
case BYPASS: {
return get ? CacheMode.GET : CacheMode.IGNORE;
}
default: {
throw new IllegalStateException( "huh? :)" );
}
default:
throw new IllegalStateException( "Unrecognized CacheStoreMode: " + storeMode );
}
}
@ -68,37 +64,11 @@ public final class CacheModeHelper {
* @param storeMode The JPA shared-cache store mode.
* @param retrieveMode The JPA shared-cache retrieve mode.
*
* @return Corresponding {@link CacheMode}.
* @return Corresponding {@link CacheMode}, or null if both arguments are null.
*/
public static CacheMode effectiveCacheMode(CacheStoreMode storeMode, CacheRetrieveMode retrieveMode) {
if ( storeMode == null && retrieveMode == null ) {
return null;
}
if ( storeMode == null ) {
storeMode = DEFAULT_STORE_MODE;
}
if ( retrieveMode == null ) {
retrieveMode = DEFAULT_RETRIEVE_MODE;
}
final boolean get = ( CacheRetrieveMode.USE == retrieveMode );
switch ( storeMode ) {
case USE: {
return get ? CacheMode.NORMAL : CacheMode.PUT;
}
case REFRESH: {
// really (get == true) here is a bit of an invalid combo...
return CacheMode.REFRESH;
}
case BYPASS: {
return get ? CacheMode.GET : CacheMode.IGNORE;
}
default: {
throw new IllegalStateException( "huh? :)" );
}
}
return storeMode == null && retrieveMode == null ? null
: interpretCacheMode( storeMode, retrieveMode );
}
public static CacheStoreMode interpretCacheStoreMode(CacheMode cacheMode) {
@ -106,13 +76,15 @@ public final class CacheModeHelper {
cacheMode = DEFAULT_LEGACY_MODE;
}
if ( CacheMode.REFRESH == cacheMode ) {
return CacheStoreMode.REFRESH;
switch (cacheMode) {
case NORMAL:
case PUT:
return CacheStoreMode.USE;
case REFRESH:
return CacheStoreMode.REFRESH;
default:
return CacheStoreMode.BYPASS;
}
if ( CacheMode.NORMAL == cacheMode || CacheMode.PUT == cacheMode ) {
return CacheStoreMode.USE;
}
return CacheStoreMode.BYPASS;
}
public static CacheRetrieveMode interpretCacheRetrieveMode(CacheMode cacheMode) {
@ -120,7 +92,7 @@ public final class CacheModeHelper {
cacheMode = DEFAULT_LEGACY_MODE;
}
return ( CacheMode.NORMAL == cacheMode || CacheMode.GET == cacheMode )
return CacheMode.NORMAL == cacheMode || CacheMode.GET == cacheMode
? CacheRetrieveMode.USE
: CacheRetrieveMode.BYPASS;
}