FileDocCategorySizeDatePackage
TreeCache.javaAPI DocHibernate 3.2.54845Tue May 30 13:00:28 BST 2006org.hibernate.cache

TreeCache

public class TreeCache extends Object implements Cache
Represents a particular region within the given JBossCache TreeCache.
author
Gavin King

Fields Summary
private static final Log
log
private static final String
ITEM
private org.jboss.cache.TreeCache
cache
private final String
regionName
private final org.jboss.cache.Fqn
regionFqn
private final TransactionManager
transactionManager
Constructors Summary
public TreeCache(org.jboss.cache.TreeCache cache, String regionName, TransactionManager transactionManager)


	       
	  
		this.cache = cache;
		this.regionName = regionName;
		this.regionFqn = Fqn.fromString( regionName.replace( '.", '/" ) );
		this.transactionManager = transactionManager;
	
Methods Summary
public voidclear()

		try {
			cache.remove( regionFqn );
		}
		catch (Exception e) {
			throw new CacheException(e);
		}
	
public voiddestroy()

		try {
			// NOTE : evict() operates locally only (i.e., does not propogate
			// to any other nodes in the potential cluster).  This is
			// exactly what is needed when we destroy() here; destroy() is used
			// as part of the process of shutting down a SessionFactory; thus
			// these removals should not be propogated
			cache.evict( regionFqn );
		}
		catch( Exception e ) {
			throw new CacheException( e );
		}
	
public java.lang.Objectget(java.lang.Object key)

		Transaction tx = suspend();
		try {
			return read(key);
		}
		finally {
			resume( tx );
		}
	
public longgetElementCountInMemory()

		try {
			Set children = cache.getChildrenNames( regionFqn );
			return children == null ? 0 : children.size();
		}
		catch (Exception e) {
			throw new CacheException(e);
		}
	
public longgetElementCountOnDisk()

		return 0;
	
public java.lang.StringgetRegionName()

		return regionName;
	
public longgetSizeInMemory()

		return -1;
	
public intgetTimeout()

		return 600; //60 seconds
	
public voidlock(java.lang.Object key)

		throw new UnsupportedOperationException( "TreeCache is a fully transactional cache" + regionName );
	
public longnextTimestamp()

		return System.currentTimeMillis() / 100;
	
public voidput(java.lang.Object key, java.lang.Object value)

		Transaction tx = suspend();
		try {
			//do the failfast put outside the scope of the JTA txn
			cache.putFailFast( new Fqn( regionFqn, key ), ITEM, value, 0 );
		}
		catch (TimeoutException te) {
			//ignore!
			log.debug("ignoring write lock acquisition failure");
		}
		catch (Exception e) {
			throw new CacheException(e);
		}
		finally {
			resume( tx );
		}
	
public java.lang.Objectread(java.lang.Object key)

		try {
			return cache.get( new Fqn( regionFqn, key ), ITEM );
		}
		catch (Exception e) {
			throw new CacheException(e);
		}
	
public voidremove(java.lang.Object key)

		try {
			cache.remove( new Fqn( regionFqn, key ) );
		}
		catch (Exception e) {
			throw new CacheException(e);
		}
	
private voidresume(javax.transaction.Transaction tx)

		try {
			if (tx!=null) transactionManager.resume(tx);
		}
		catch (Exception e) {
			throw new CacheException("Could not resume transaction", e);
		}
	
private javax.transaction.Transactionsuspend()

		Transaction tx = null;
		try {
			if ( transactionManager!=null ) {
				tx = transactionManager.suspend();
			}
		}
		catch (SystemException se) {
			throw new CacheException("Could not suspend transaction", se);
		}
		return tx;
	
public java.util.MaptoMap()

		try {
			Map result = new HashMap();
			Set childrenNames = cache.getChildrenNames( regionFqn );
			if (childrenNames != null) {
				Iterator iter = childrenNames.iterator();
				while ( iter.hasNext() ) {
					Object key = iter.next();
					result.put( 
							key, 
							cache.get( new Fqn( regionFqn, key ), ITEM )
						);
				}
			}
			return result;
		}
		catch (Exception e) {
			throw new CacheException(e);
		}
	
public java.lang.StringtoString()

		return "TreeCache(" + regionName + ')";
	
public voidunlock(java.lang.Object key)

		throw new UnsupportedOperationException( "TreeCache is a fully transactional cache: " + regionName );
	
public voidupdate(java.lang.Object key, java.lang.Object value)

		try {
			cache.put( new Fqn( regionFqn, key ), ITEM, value );
		}
		catch (Exception e) {
			throw new CacheException(e);
		}