Java Code Examples for org.hibernate.mapping.Collection#setCacheConcurrencyStrategy()

The following examples show how to use org.hibernate.mapping.Collection#setCacheConcurrencyStrategy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InFlightMetadataCollectorImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void processCachingOverrides() {
	if ( bootstrapContext.getCacheRegionDefinitions() == null ) {
		return;
	}

	for ( CacheRegionDefinition cacheRegionDefinition : bootstrapContext.getCacheRegionDefinitions() ) {
		if ( cacheRegionDefinition.getRegionType() == CacheRegionDefinition.CacheRegionType.ENTITY ) {
			final PersistentClass entityBinding = getEntityBinding( cacheRegionDefinition.getRole() );
			if ( entityBinding == null ) {
				throw new HibernateException(
						"Cache override referenced an unknown entity : " + cacheRegionDefinition.getRole()
				);
			}
			if ( !RootClass.class.isInstance( entityBinding ) ) {
				throw new HibernateException(
						"Cache override referenced a non-root entity : " + cacheRegionDefinition.getRole()
				);
			}
			entityBinding.setCached( true );
			( (RootClass) entityBinding ).setCacheRegionName( cacheRegionDefinition.getRegion() );
			( (RootClass) entityBinding ).setCacheConcurrencyStrategy( cacheRegionDefinition.getUsage() );
			( (RootClass) entityBinding ).setLazyPropertiesCacheable( cacheRegionDefinition.isCacheLazy() );
		}
		else if ( cacheRegionDefinition.getRegionType() == CacheRegionDefinition.CacheRegionType.COLLECTION ) {
			final Collection collectionBinding = getCollectionBinding( cacheRegionDefinition.getRole() );
			if ( collectionBinding == null ) {
				throw new HibernateException(
						"Cache override referenced an unknown collection role : " + cacheRegionDefinition.getRole()
				);
			}
			collectionBinding.setCacheRegionName( cacheRegionDefinition.getRegion() );
			collectionBinding.setCacheConcurrencyStrategy( cacheRegionDefinition.getUsage() );
		}
	}
}
 
Example 2
Source File: Configuration.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void setCollectionCacheConcurrencyStrategy(String collectionRole, String concurrencyStrategy, String region)
		throws MappingException {
	Collection collection = getCollectionMapping( collectionRole );
	if ( collection == null ) {
		throw new MappingException( "Cannot cache an unknown collection: " + collectionRole );
	}
	collection.setCacheConcurrencyStrategy( concurrencyStrategy );
	collection.setCacheRegionName( region );
}
 
Example 3
Source File: ModelBinder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private void applyCaching(MappingDocument mappingDocument, Caching caching, Collection collection) {
		if ( caching == null || caching.getRequested() == TruthValue.UNKNOWN ) {
			// see if JPA's SharedCacheMode indicates we should implicitly apply caching
			switch ( mappingDocument.getBuildingOptions().getSharedCacheMode() ) {
				case ALL: {
					caching = new Caching(
							null,
							mappingDocument.getBuildingOptions().getImplicitCacheAccessType(),
							false,
							TruthValue.UNKNOWN
					);
					break;
				}
				case NONE: {
					// Ideally we'd disable all caching...
					break;
				}
				case ENABLE_SELECTIVE: {
					// this is default behavior for hbm.xml
					break;
				}
				case DISABLE_SELECTIVE: {
					// really makes no sense for hbm.xml
					break;
				}
				default: {
					// null or UNSPECIFIED, nothing to do.  IMO for hbm.xml this is equivalent
					// to ENABLE_SELECTIVE
					break;
				}
			}
		}

		if ( caching == null || caching.getRequested() == TruthValue.FALSE ) {
			return;
		}

		if ( caching.getAccessType() != null ) {
			collection.setCacheConcurrencyStrategy( caching.getAccessType().getExternalName() );
		}
		else {
			collection.setCacheConcurrencyStrategy( mappingDocument.getBuildingOptions().getImplicitCacheAccessType().getExternalName() );
		}
		collection.setCacheRegionName( caching.getRegion() );
//		collection.setCachingExplicitlyRequested( caching.getRequested() != TruthValue.UNKNOWN );
	}