if ( hibernateCacheAnnotation != null ) {
final org.hibernate.cache.spi.access.AccessType accessType = hibernateCacheAnnotation.value( "usage" ) == null
? getLocalBindingContext().getMappingDefaults().getCacheAccessType()
: CacheConcurrencyStrategy.parse( hibernateCacheAnnotation.value( "usage" ).asEnum() )
.toAccessType();
return new Caching(
hibernateCacheAnnotation.value( "region" ) == null
? getName()
: hibernateCacheAnnotation.value( "region" ).asString(),
accessType,
hibernateCacheAnnotation.value( "include" ) != null
&& "all".equals( hibernateCacheAnnotation.value( "include" ).asString() )
);
}
final AnnotationInstance jpaCacheableAnnotation = JandexHelper.getSingleAnnotation(
getClassInfo(), JPADotNames.CACHEABLE
);
boolean cacheable = true; // true is the default
if ( jpaCacheableAnnotation != null && jpaCacheableAnnotation.value() != null ) {
cacheable = jpaCacheableAnnotation.value().asBoolean();
}
final boolean doCaching;
switch ( getLocalBindingContext().getMetadataImplementor().getOptions().getSharedCacheMode() ) {
case ALL: {
doCaching = true;
break;
}
case ENABLE_SELECTIVE: {
doCaching = cacheable;
break;
}
case DISABLE_SELECTIVE: {
doCaching = jpaCacheableAnnotation == null || cacheable;
break;
}
default: {
// treat both NONE and UNSPECIFIED the same
doCaching = false;
break;
}
}
if ( !doCaching ) {
return null;
}
return new Caching(
getName(),
getLocalBindingContext().getMappingDefaults().getCacheAccessType(),
true
);
}