下面列出了org.hibernate.CacheMode#PUT 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static CacheMode getCacheMode(CacheModeType cacheModeType) {
switch ( cacheModeType ) {
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: " + cacheModeType );
}
}
/**
* Given a JPA {@link CacheStoreMode} and {@link CacheRetrieveMode}, determine the corresponding
* legacy Hibernate {@link CacheMode}.
*
* @param storeMode The JPA shared-cache store mode.
* @param retrieveMode The JPA shared-cache retrieve mode.
*
* @return Corresponding {@link CacheMode}.
*/
public static CacheMode interpretCacheMode(CacheStoreMode storeMode, CacheRetrieveMode 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? :)" );
}
}
}
/**
* Given a JPA {@link CacheStoreMode} and {@link CacheRetrieveMode}, determine the corresponding
* legacy Hibernate {@link CacheMode}.
*
* @param storeMode The JPA shared-cache store mode.
* @param retrieveMode The JPA shared-cache retrieve mode.
*
* @return Corresponding {@link CacheMode}.
*/
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? :)" );
}
}
}
public static CacheStoreMode interpretCacheStoreMode(CacheMode cacheMode) {
if ( cacheMode == null ) {
cacheMode = DEFAULT_LEGACY_MODE;
}
if ( CacheMode.REFRESH == cacheMode ) {
return CacheStoreMode.REFRESH;
}
if ( CacheMode.NORMAL == cacheMode || CacheMode.PUT == cacheMode ) {
return CacheStoreMode.USE;
}
return CacheStoreMode.BYPASS;
}
public static CacheMode getCacheMode(String cacheMode) {
if (cacheMode == null) return null;
if ( "get".equals( cacheMode ) ) return CacheMode.GET;
if ( "ignore".equals( cacheMode ) ) return CacheMode.IGNORE;
if ( "normal".equals( cacheMode ) ) return CacheMode.NORMAL;
if ( "put".equals( cacheMode ) ) return CacheMode.PUT;
if ( "refresh".equals( cacheMode ) ) return CacheMode.REFRESH;
throw new MappingException("Unknown Cache Mode: " + cacheMode);
}