/** * @deprecated No replacement - added just for support of the newly deprecated methods expecting a qualified region name */ @Deprecated default Region getRegionByLegacyName(String legacyName) { return getRegion( unqualifyRegionName( legacyName ) ); }
@Override public CacheRegionStatisticsImpl getDomainDataRegionStatistics(String regionName) { if ( sessionFactory == null ) { return null; } return l2CacheStatsMap.computeIfAbsent( regionName, s -> { final Region region = sessionFactory.getCache().getRegion( regionName ); if ( region == null ) { throw new IllegalArgumentException( "Unknown cache region : " + regionName ); } if ( region instanceof QueryResultsRegion ) { throw new IllegalArgumentException( "Region name [" + regionName + "] referred to a query result region, not a domain data region" ); } return new CacheRegionStatisticsImpl( region ); } ); }
@Override public CacheRegionStatisticsImpl getCacheRegionStatistics(String regionName) { if ( sessionFactory == null ) { return null; } if ( ! sessionFactory.getSessionFactoryOptions().isSecondLevelCacheEnabled() ) { return null; } return l2CacheStatsMap.computeIfAbsent( regionName, s -> { Region region = sessionFactory.getCache().getRegion( regionName ); if ( region == null ) { // this is the pre-5.3 behavior. and since this is a pre-5.3 method it should behave consistently // NOTE that this method is deprecated region = sessionFactory.getCache().getQueryResultsCache( regionName ).getRegion(); } return new CacheRegionStatisticsImpl( region ); } ); }
@Test public void test() { CacheImplementor cacheImplementor = sessionFactory().getCache(); EhcacheRegionFactory regionFactory = (EhcacheRegionFactory) cacheImplementor.getRegion( Event.class.getName() ).getRegionFactory(); assertEquals( TimeUnit.SECONDS.toMillis( 1 ) * SimpleTimestamper.ONE_MS, regionFactory.getTimeout() ); }
@Test public void testBasicStorageAccessUse() { TestHelper.preBuildAllCaches(); try (final SessionFactoryImplementor sessionFactory = TestHelper.buildStandardSessionFactory() ) { final Region region = sessionFactory.getCache().getRegion( TestHelper.entityRegionNames[0] ); final JCacheAccessImpl access = (JCacheAccessImpl) ( (DomainDataRegionTemplate) region ).getCacheStorageAccess(); final Cache jcache = access.getUnderlyingCache(); inSession( sessionFactory, s -> { access.putIntoCache( "key", "value", s ); assertThat( jcache.get( "key" ), equalTo( "value" ) ); assertThat( access.getFromCache( "key", s ), equalTo( "value" ) ); access.removeFromCache( "key", s ); assertThat( jcache.get( "key" ), nullValue() ); assertThat( access.getFromCache( "key", s ), nullValue() ); } ); } }
@Test public void testBasicUsage() { final Region region = sessionFactory().getCache().getRegion( TestHelper.entityRegionNames[0] ); final DomainDataRegionTemplate domainDataRegion = assertTyping( DomainDataRegionTemplate.class, region );
sessionFactory, s -> { final DomainDataRegionTemplate region = (DomainDataRegionTemplate) sessionFactory().getCache().getRegion( "item" ); final Object fromCache = region.getCacheStorageAccess().getFromCache( region.getEffectiveKeysFactory().createEntityKey(
/** * @deprecated No replacement - added just for support of the newly deprecated methods expecting a qualified region name */ @Deprecated default Region getRegionByLegacyName(String legacyName) { return getRegion( unqualifyRegionName( legacyName ) ); }
@Override public CacheRegionStatisticsImpl getDomainDataRegionStatistics(String regionName) { if ( sessionFactory == null ) { return null; } return l2CacheStatsMap.computeIfAbsent( regionName, s -> { final Region region = sessionFactory.getCache().getRegion( regionName ); if ( region == null ) { throw new IllegalArgumentException( "Unknown cache region : " + regionName ); } if ( region instanceof QueryResultsRegion ) { throw new IllegalArgumentException( "Region name [" + regionName + "] referred to a query result region, not a domain data region" ); } return new CacheRegionStatisticsImpl( region ); } ); }
@Override public CacheRegionStatisticsImpl getCacheRegionStatistics(String regionName) { if ( sessionFactory == null ) { return null; } if ( ! sessionFactory.getSessionFactoryOptions().isSecondLevelCacheEnabled() ) { return null; } return l2CacheStatsMap.computeIfAbsent( regionName, s -> { Region region = sessionFactory.getCache().getRegion( regionName ); if ( region == null ) { // this is the pre-5.3 behavior. and since this is a pre-5.3 method it should behave consistently // NOTE that this method is deprecated region = sessionFactory.getCache().getQueryResultsCache( regionName ).getRegion(); } return new CacheRegionStatisticsImpl( region ); } ); }