/** * @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 ) ); }
public static Cache getCache(SessionFactoryImplementor sessionFactoryImplementor, String regionName) { final RegionFactory regionFactory = sessionFactoryImplementor.getCache().getRegionFactory(); final EhcacheRegionFactory ehcacheRegionFactory = (EhcacheRegionFactory) regionFactory; final CacheManager cacheManager = ehcacheRegionFactory.getCacheManager(); regionName = prefix( regionName ); return cacheManager.getCache( regionName ); }
protected void cleanupCache() { if ( sessionFactory != null ) { sessionFactory.getCache().evictAllRegions(); } }
/** * @deprecated Use {@link #getQueryResultsCache(String)} instead, but using unqualified name */ @Deprecated default QueryCache getQueryCache(String regionName) throws HibernateException { return getQueryResultsCache( unqualifyRegionName( regionName ) ); }
@Override public DeprecatedNaturalIdCacheStatisticsImpl getNaturalIdCacheStatistics(String regionName) { return deprecatedNaturalIdStatsMap.computeIfAbsent( sessionFactory.getCache().unqualifyRegionName( regionName ), unqualifiedRegionName -> new DeprecatedNaturalIdCacheStatisticsImpl( unqualifiedRegionName, sessionFactory.getCache().getNaturalIdAccessesInRegion( unqualifiedRegionName ) ) ); }
@Test public void testInsertWithRollback() { sessionFactory().getCache().evictEntityRegions(); sessionFactory().getStatistics().clear(); inTransaction( sessionFactory, s -> { CacheableItem item = new CacheableItem( "data" ); s.save( item ); s.flush(); s.getTransaction().markRollbackOnly(); } ); assertFalse( sessionFactory().getCache().containsEntity( CacheableItem.class, 1L ) ); }
@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 testInsertWithRefreshThenRollback() { sessionFactory().getCache().evictEntityRegions(); sessionFactory().getStatistics().clear(); sessionFactory, s -> { final DomainDataRegionTemplate region = (DomainDataRegionTemplate) sessionFactory().getCache().getRegion( "item" ); final Object fromCache = region.getCacheStorageAccess().getFromCache( region.getEffectiveKeysFactory().createEntityKey(
@Override public CacheRegionStatisticsImpl getSecondLevelCacheStatistics(String regionName) { if ( sessionFactory == null ) { return null; } return getCacheRegionStatistics( sessionFactory.getCache().unqualifyRegionName( regionName ) ); }
final EntityDataAccess accessStrategy = sessionFactory.getCache().getEntityRegionAccess( rootEntityRole ); final NaturalIdDataAccess naturalIdAccessStrategy = sessionFactory.getCache().getNaturalIdCacheRegionAccessStrategy( rootEntityRole ); final NavigableRole navigableRole = new NavigableRole( model.getRole() ); final CollectionDataAccess accessStrategy = sessionFactory.getCache().getCollectionRegionAccess( navigableRole );
/** * Get the default {@code QueryCache}. * * @deprecated Use {@link #getDefaultQueryResultsCache} instead. */ @Deprecated default QueryCache getDefaultQueryCache() { return getDefaultQueryResultsCache(); }
@Test @TestForIssue(jiraKey = "HHH-8794") public void testOrderByNoElement() { final Session s = openSession(); s.getTransaction().begin(); Employee employee = new Employee( 1 ); Computer computer = new Computer( 1 ); computer.setComputerName( "Bob's computer" ); computer.setEmployee( employee ); Computer computer2 = new Computer( 2 ); computer2.setComputerName( "Alice's computer" ); computer2.setEmployee( employee ); s.save( employee ); s.save( computer2 ); s.save( computer ); s.flush(); s.clear(); sessionFactory().getCache().evictEntityRegions(); employee = (Employee) s.get( Employee.class, employee.getId() ); assertEquals( 2, employee.getAssets().size() ); assertEquals( 1, employee.getAssets().get( 0 ).getIdAsset().intValue() ); assertEquals( 2, employee.getAssets().get( 1 ).getIdAsset().intValue() ); }
@Override public EntityDataAccess getEntityCacheAccess() { if ( caching == null ) { caching = rootEntityDescriptor.getFactory().getCache().getEntityRegionAccess( rootEntityDescriptor.getNavigableRole() ); } return caching; }
assertTrue( sessionFactory().getCache().containsEntity( Item.class, i.getId() ) ); assertTrue( sessionFactory().getCache().containsEntity( Item.class, i.getId() ) );
cacheAccess.close();
private static NaturalIdDescriptor interpretNaturalIdentifierDescriptor( EntityHierarchyImpl entityHierarchy, RootClass rootEntityMapping, RuntimeModelCreationContext creationContext) { if ( !rootEntityMapping.hasNaturalId() ) { return null; } return new NaturalIdDescriptorImpl( entityHierarchy, entityHierarchy.getRootEntityType() .getFactory() .getCache() .getNaturalIdCacheRegionAccessStrategy( entityHierarchy.rootEntityDescriptor.getNavigableRole() ) ); }
@Test public void testInsertThenUpdateThenRollback() { sessionFactory().getCache().evictEntityRegions(); sessionFactory().getStatistics().clear(); inTransaction( sessionFactory, s -> { CacheableItem item = new CacheableItem( "data" ); s.save( item ); s.flush(); item.setName( "new data" ); s.getTransaction().markRollbackOnly(); } ); assertFalse( sessionFactory().getCache().containsEntity( CacheableItem.class, 1L ) ); }
@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() ); }
@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 ); } ); }