clean up CacheModeType enum

This commit is contained in:
Gavin 2022-12-22 18:02:13 +01:00
parent 114a82d438
commit 2d66ce8b2d
1 changed files with 28 additions and 25 deletions

View File

@ -6,6 +6,7 @@
*/ */
package org.hibernate.annotations; package org.hibernate.annotations;
import org.hibernate.AssertionFailure;
import org.hibernate.CacheMode; import org.hibernate.CacheMode;
import org.hibernate.Remove; import org.hibernate.Remove;
@ -28,44 +29,51 @@ public enum CacheModeType {
* *
* @see CacheMode#GET * @see CacheMode#GET
*/ */
GET( CacheMode.GET ), GET,
/** /**
* Corresponds to {@link CacheMode#IGNORE}. * Corresponds to {@link CacheMode#IGNORE}.
* *
* @see CacheMode#IGNORE * @see CacheMode#IGNORE
*/ */
IGNORE( CacheMode.IGNORE ), IGNORE,
/** /**
* Corresponds to {@link CacheMode#NORMAL}. * Corresponds to {@link CacheMode#NORMAL}.
* *
* @see CacheMode#NORMAL * @see CacheMode#NORMAL
*/ */
NORMAL( CacheMode.NORMAL ), NORMAL,
/** /**
* Corresponds to {@link CacheMode#PUT}. * Corresponds to {@link CacheMode#PUT}.
* *
* @see CacheMode#PUT * @see CacheMode#PUT
*/ */
PUT( CacheMode.PUT ), PUT,
/** /**
* Corresponds to {@link CacheMode#REFRESH}. * Corresponds to {@link CacheMode#REFRESH}.
* *
* @see CacheMode#REFRESH * @see CacheMode#REFRESH
*/ */
REFRESH( CacheMode.REFRESH ); REFRESH;
private final CacheMode cacheMode;
CacheModeType(CacheMode cacheMode) {
this.cacheMode = cacheMode;
}
public CacheMode getCacheMode() { public CacheMode getCacheMode() {
return cacheMode; switch (this) {
case GET:
return CacheMode.GET;
case IGNORE:
return CacheMode.IGNORE;
case NORMAL:
return CacheMode.NORMAL;
case PUT:
return CacheMode.PUT;
case REFRESH:
return CacheMode.REFRESH;
default:
throw new AssertionFailure( "Unknown CacheModeType" );
}
} }
/** /**
@ -73,7 +81,8 @@ public enum CacheModeType {
* *
* @param cacheMode The cache mode to convert * @param cacheMode The cache mode to convert
* *
* @return The corresponding enum value. Will be {@code null} if the given {@code accessType} is {@code null}. * @return The corresponding enum value.
* Will be {@code null} if the given {@code accessType} is {@code null}.
*/ */
public static CacheModeType fromCacheMode(CacheMode cacheMode) { public static CacheModeType fromCacheMode(CacheMode cacheMode) {
if ( null == cacheMode ) { if ( null == cacheMode ) {
@ -81,24 +90,18 @@ public enum CacheModeType {
} }
switch ( cacheMode ) { switch ( cacheMode ) {
case NORMAL: { case NORMAL:
return NORMAL; return NORMAL;
} case GET:
case GET: {
return GET; return GET;
} case PUT:
case PUT: {
return PUT; return PUT;
} case REFRESH:
case REFRESH: {
return REFRESH; return REFRESH;
} case IGNORE:
case IGNORE: {
return IGNORE; return IGNORE;
} default:
default: {
throw new IllegalArgumentException( "Unrecognized CacheMode : " + cacheMode ); throw new IllegalArgumentException( "Unrecognized CacheMode : " + cacheMode );
}
} }
} }
} }