下面列出了org.hibernate.CacheMode#GET 实例代码,或者点击链接到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 CacheRetrieveMode interpretCacheRetrieveMode(CacheMode cacheMode) {
if ( cacheMode == null ) {
cacheMode = DEFAULT_LEGACY_MODE;
}
return ( CacheMode.NORMAL == cacheMode || CacheMode.GET == cacheMode )
? CacheRetrieveMode.USE
: CacheRetrieveMode.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);
}
/**
* Return {@link SystemParameter) resource and matches with the given id.
*
* @param credentials Injected by {@link RobeAuth} annotation for authentication.
* @param id This is the oid of {@link SystemParameter}
* @return {@link SystemParameter} resource matches with the given id.
*/
@RobeService(group = "SystemParameter", description = "Return SystemParameter resource.")
@Path("{id}")
@GET
@UnitOfWork(readOnly = true, cacheMode = CacheMode.GET, flushMode = FlushMode.MANUAL)
public SystemParameter get(@RobeAuth Credentials credentials, @PathParam("id") String id) {
SystemParameter entity = systemParameterDao.findById(id);
if (entity == null) {
throw new WebApplicationException(Response.status(404).build());
}
return entity;
}
/**
* Returns all {@link User}s as a collection.
*
* @param credentials injected by {@link RobeAuth} annotation for authentication.
* @return all {@link User}s as a collection with.
*/
@RobeService(group = "User", description = "Returns all Users as a collection.")
@GET
@UnitOfWork(readOnly = true, cacheMode = CacheMode.GET, flushMode = FlushMode.MANUAL)
public List<User> getAll(@RobeAuth Credentials credentials, @SearchParam SearchModel search) {
return userDao.findAllStrict(search);
}
/**
* Returns a single User matches with the given id.
* <p>
* Status Code:
* Not Found 404
*
* @param credentials injected by {@link RobeAuth} annotation for authentication.
* @param id This is the oid of {@link User}
* @return a {@link User} resource matches with the given id.
*/
@RobeService(group = "User", description = "Returns a User resource matches with the given id.")
@Path("{id}")
@GET
@UnitOfWork(readOnly = true, cacheMode = CacheMode.GET, flushMode = FlushMode.MANUAL)
public User get(@RobeAuth Credentials credentials, @PathParam("id") String id) {
User entity = userDao.findById(id);
if (entity == null) {
throw new WebApplicationException(Response.status(404).build());
}
return entity;
}
@Override
public boolean isSecondLevelCacheCheckingEnabled() {
return cacheMode == CacheMode.NORMAL || cacheMode == CacheMode.GET;
}