FileDocCategorySizeDatePackage
CacheFactory.javaAPI DocHibernate 3.2.52244Sat Feb 12 00:19:50 GMT 2005org.hibernate.cache

CacheFactory

public final class CacheFactory extends Object
author
Gavin King

Fields Summary
private static final Log
log
public static final String
READ_ONLY
public static final String
READ_WRITE
public static final String
NONSTRICT_READ_WRITE
public static final String
TRANSACTIONAL
Constructors Summary
private CacheFactory()

	
	  
Methods Summary
public static CacheConcurrencyStrategycreateCache(java.lang.String concurrencyStrategy, java.lang.String regionName, boolean mutable, org.hibernate.cfg.Settings settings, java.util.Properties properties)

	
	   
		   
		  
		   
		  
		   
	  
		
		if ( concurrencyStrategy==null || !settings.isSecondLevelCacheEnabled() ) return null; //no cache
		
		String prefix = settings.getCacheRegionPrefix();
		if ( prefix!=null ) regionName = prefix + '." + regionName;
		
		if ( log.isDebugEnabled() ) log.debug("instantiating cache region: " + regionName + " usage strategy: " + concurrencyStrategy);
		
		final CacheConcurrencyStrategy ccs;
		if ( concurrencyStrategy.equals(READ_ONLY) ) {
			if (mutable) log.warn( "read-only cache configured for mutable class: " + regionName );
			ccs = new ReadOnlyCache();
		}
		else if ( concurrencyStrategy.equals(READ_WRITE) ) {
			ccs = new ReadWriteCache();
		}
		else if ( concurrencyStrategy.equals(NONSTRICT_READ_WRITE) ) {
			ccs = new NonstrictReadWriteCache();
		}
		else if ( concurrencyStrategy.equals(TRANSACTIONAL) ) {
			ccs = new TransactionalCache();
		}
		else {
			throw new MappingException("cache usage attribute should be read-write, read-only, nonstrict-read-write or transactional");
		}
		
		final Cache impl;
		try {
			impl = settings.getCacheProvider().buildCache(regionName, properties);
		}
		catch (CacheException e) {
			throw new HibernateException( "Could not instantiate cache implementation", e );
		}
		ccs.setCache(impl);
		
		return ccs;