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