CollectionStatisticsImpl(CollectionPersister persister) { super( () -> persister.getCacheAccessStrategy() != null ? persister.getCacheAccessStrategy().getRegion() : null ); this.collectionRole = persister.getRole(); }
private void evictCollectionData(CollectionPersister collectionDescriptor) { evictCollectionData( collectionDescriptor.getNavigableRole(), collectionDescriptor.getCacheAccessStrategy() ); }
@Override public boolean containsCollection(String role, Serializable ownerIdentifier) { final CollectionPersister collectionDescriptor = sessionFactory.getMetamodel() .collectionPersister( role ); final CollectionDataAccess cacheAccess = collectionDescriptor.getCacheAccessStrategy(); if ( cacheAccess == null ) { return false; } final Object key = cacheAccess.generateCacheKey( ownerIdentifier, collectionDescriptor, sessionFactory, null ); return cacheAccess.contains( key ); }
@Override public void doAfterTransactionCompletion(boolean success, SharedSessionContractImplementor session) { final CollectionDataAccess cache = persister.getCacheAccessStrategy(); final Object ck = cache.generateCacheKey( key, persister, session.getFactory(), session.getTenantIdentifier() ); cache.unlockItem( session, ck, lock ); } }
protected final void evict() throws CacheException { if ( persister.hasCache() ) { final CollectionDataAccess cache = persister.getCacheAccessStrategy(); final Object ck = cache.generateCacheKey( key, persister, session.getFactory(), session.getTenantIdentifier() ); cache.remove( session, ck); } }
collectionCleanups.add( new CollectionCleanup( collectionPersister.getCacheAccessStrategy(), session
if ( collectionPersister.hasCache() ) { collectionCleanups.add( new CollectionCleanup( collectionPersister.getCacheAccessStrategy(), session ) );
@Override public final void beforeExecutions() throws CacheException { // we need to obtain the lock before any actions are executed, since this may be an inverse="true" // bidirectional association and it is one of the earlier entity actions which actually updates // the database (this action is responsible for second-level cache invalidation only) if ( persister.hasCache() ) { final CollectionDataAccess cache = persister.getCacheAccessStrategy(); final Object ck = cache.generateCacheKey( key, persister, session.getFactory(), session.getTenantIdentifier() ); final SoftLock lock = cache.lockItem( session, ck, null ); // the old behavior used key as opposed to getKey() afterTransactionProcess = new CacheCleanupProcess( key, persister, lock ); } }
final SoftLock softLock = collectionPersister.getCacheAccessStrategy().lockRegion(); session.getActionQueue().registerProcess( (success, session1) -> { collectionPersister.getCacheAccessStrategy().unlockRegion( softLock ); } );
@Override public void evictCollectionData(String role, Serializable ownerIdentifier) { final CollectionPersister collectionDescriptor = sessionFactory.getMetamodel() .collectionPersister( role ); final CollectionDataAccess cacheAccess = collectionDescriptor.getCacheAccessStrategy(); if ( cacheAccess == null ) { return; } if ( LOG.isDebugEnabled() ) { LOG.debugf( "Evicting second-level cache: %s", MessageHelper.collectionInfoString( collectionDescriptor, ownerIdentifier, sessionFactory ) ); } final Object key = cacheAccess.generateCacheKey( ownerIdentifier, collectionDescriptor, sessionFactory, null ); cacheAccess.evict( key ); }
private boolean isCached(Serializable collectionKey, CollectionPersister persister) { SharedSessionContractImplementor session = context.getSession(); if ( session.getCacheMode().isGetEnabled() && persister.hasCache() ) { CollectionDataAccess cache = persister.getCacheAccessStrategy(); Object cacheKey = cache.generateCacheKey( collectionKey, persister, session.getFactory(), session.getTenantIdentifier() ); return CacheHelper.fromSharedCache( session, cacheKey, cache ) != null; } return false; }
@Test public void testCachedValueAfterEviction() { CollectionPersister persister = sessionFactory().getCollectionPersister( Company.class.getName() + ".users" ); Session session = openSession(); SessionImplementor sessionImplementor = (SessionImplementor) session; CollectionDataAccess cache = persister.getCacheAccessStrategy(); Object key = cache.generateCacheKey( 1, persister, sessionFactory(), session.getTenantIdentifier() ); Object cachedValue = cache.get( sessionImplementor, key ); assertNull( cachedValue ); Company company = session.get( Company.class, 1 ); //should add in cache assertEquals( 1, company.getUsers().size() ); session.close(); session = openSession(); sessionImplementor = (SessionImplementor) session; key = cache.generateCacheKey( 1, persister, sessionFactory(), session.getTenantIdentifier() ); cachedValue = cache.get( sessionImplementor, key ); assertNotNull( "Collection wasn't cached", cachedValue ); session.close(); }
sessionFactory().getMetamodel() .collectionPersister( Event.class.getName() + ".participants" ) .getCacheAccessStrategy() .getAccessType(), equalTo( AccessType.READ_WRITE )
final CollectionDataAccess cacheAccessStrategy = persister.getCacheAccessStrategy(); final Object ck = cacheAccessStrategy.generateCacheKey( id, persister, factory, source.getTenantIdentifier() ); final Object ce = CacheHelper.fromSharedCache( source, ck, persister.getCacheAccessStrategy() );
private void evictCachedCollections(Type[] types, Serializable id, EventSource source) throws HibernateException { for ( Type type : types ) { if ( type.isCollectionType() ) { CollectionPersister collectionPersister = source.getFactory().getMetamodel().collectionPersister( ( (CollectionType) type ).getRole() ); if ( collectionPersister.hasCache() ) { final CollectionDataAccess cache = collectionPersister.getCacheAccessStrategy(); final Object ck = cache.generateCacheKey( id, collectionPersister, source.getFactory(), source.getTenantIdentifier() ); final SoftLock lock = cache.lockItem( source, ck, null ); cache.remove( source, ck ); source.getActionQueue().registerProcess( (success, session) -> cache.unlockItem( session, ck, lock ) ); } } else if ( type.isComponentType() ) { CompositeType actype = (CompositeType) type; evictCachedCollections( actype.getSubtypes(), id, source ); } } } }
final CollectionDataAccess cacheAccess = persister.getCacheAccessStrategy(); final Object cacheKey = cacheAccess.generateCacheKey( lce.getKey(), factory.getStatistics().collectionCachePut( persister.getNavigableRole(), persister.getCacheAccessStrategy().getRegion().getName() );
@Override public void doAfterTransactionCompletion(boolean success, SessionImplementor session) { final CacheKey ck = session.generateCacheKey( key, persister.getKeyType(), persister.getRole() ); persister.getCacheAccessStrategy().unlockItem( ck, lock ); } }
protected final void evict() throws CacheException { if ( persister.hasCache() ) { CacheKey ck = session.generateCacheKey( key, persister.getKeyType(), persister.getRole() ); persister.getCacheAccessStrategy().remove( ck ); } }
public boolean containsCollection(String role, Serializable ownerIdentifier) { CollectionPersister p = getCollectionPersister( role ); return p.hasCache() && p.getCacheAccessStrategy().getRegion().contains( buildCacheKey( ownerIdentifier, p ) ); }
public boolean containsCollection(String role, Serializable ownerIdentifier) { CollectionPersister p = getCollectionPersister( role ); return p.hasCache() && p.getCacheAccessStrategy().getRegion().contains( buildCacheKey( ownerIdentifier, p ) ); }