@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 ); } }
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 ); } } } }
@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 ( collectionDescriptor.hasCache() ) { final CollectionDataAccess cacheAccess = collectionDescriptor.getCacheAccess(); final Object ck = cacheAccess.generateCacheKey( key, collectionDescriptor, session.getFactory(), session.getTenantIdentifier() ); final SoftLock lock = cacheAccess.lockItem( session, ck, null ); // the old behavior used key as opposed to getKey() afterTransactionProcess = new CacheCleanupProcess( key, collectionDescriptor, lock ); } }
@SuppressWarnings("unchecked") private void evictCachedCollections(List<PersistentAttributeDescriptor> persistentAttributes, Object id, EventSource source) throws HibernateException { for ( PersistentAttributeDescriptor attribute : persistentAttributes ) { if ( PluralPersistentAttribute.class.isInstance( attribute ) ) { final PersistentCollectionDescriptor collectionDescriptor = ( (PluralPersistentAttribute) attribute ).getPersistentCollectionDescriptor(); if ( collectionDescriptor.hasCache() ) { final CollectionDataAccess cache = collectionDescriptor.getCacheAccess(); final Object ck = cache.generateCacheKey( id, collectionDescriptor, source.getFactory(), source.getTenantIdentifier() ); final SoftLock lock = cache.lockItem( source, ck, null ); source.getActionQueue().registerProcess( (success, session) -> cache.unlockItem( session, ck, lock ) ); cache.remove( source, ck ); } } else if ( EmbeddedValuedNavigable.class.isInstance( attribute ) ) { EmbeddedValuedNavigable composite = (EmbeddedValuedNavigable) attribute; evictCachedCollections( composite.getEmbeddedDescriptor().getPersistentAttributes(), id, source ); } } } }