1 19 package org.fjank.jcache; 20 21 import javax.util.jcache.Attributes; 22 import javax.util.jcache.Cache; 23 import javax.util.jcache.CacheAccessFactory; 24 import javax.util.jcache.CacheException; 25 import javax.util.jcache.CacheMap; 26 import javax.util.jcache.CacheNotAvailableException; 27 import javax.util.jcache.NullObjectNameException; 28 import javax.util.jcache.ObjectExistsException; 29 import org.fjank.jcache.collection.MapAdapter; 30 31 36 public final class CacheAccessFactoryImpl extends CacheAccessFactory { 37 40 public CacheAccessFactoryImpl() { 41 } 42 43 56 public void defineRegion(final String name) 57 throws ObjectExistsException, NullObjectNameException, 58 CacheNotAvailableException { 59 Attributes att = CacheAccessFactory.getInstance().getDefaultAttributes(); 60 defineRegion(name, att); 61 } 62 63 77 public void defineRegion(final String name, final Attributes attributes) 78 throws ObjectExistsException, NullObjectNameException, 79 CacheNotAvailableException { 80 CacheImpl cache = CacheImpl.getCache(true); 81 Attributes lAttribs=attributes; 82 if(lAttribs==null) lAttribs=CacheAccessFactory.getInstance().getDefaultAttributes(); 83 cache.addRegion(name, lAttribs); 84 } 85 86 91 public CacheMap getMapAccess() { 92 return new MapAdapter(getNewAccessImpl(null)); 93 } 94 99 public CacheMap getMapAccess(final String region) { 100 return new MapAdapter(getNewAccessImpl(region)); 101 } 102 CacheAccessImpl2 getNewAccessImpl(final String region) { 103 CacheImpl cache = CacheImpl.getCache(true); 104 CacheRegion reg = region!=null?cache.getRegion(region):cache.getRegion(); 105 if (reg == null) { 106 throw new IllegalStateException ("The region " + region 107 + " does not exist in this cache."); 108 } 109 return new CacheAccessImpl2(reg); 110 } 111 116 public Cache getCache() throws CacheException { 117 return CacheImpl.getCache(true); 118 } 119 120 126 public Cache getCache(final boolean init) throws CacheException { 127 return CacheImpl.getCache(init); 128 } 129 } 130 | Popular Tags |