@Override public void removeSharedNaturalIdCrossReference(EntityPersister persister, Serializable id, Object[] naturalIdValues) { if ( !persister.hasNaturalIdentifier() ) { // nothing to do return; } if ( ! persister.hasNaturalIdCache() ) { // nothing to do return; } // todo : couple of things wrong here: // 1) should be using access strategy, not plain evict.. // 2) should prefer session-cached values if any (requires interaction from removeLocalNaturalIdCrossReference persister = locateProperPersister( persister ); final NaturalIdDataAccess naturalIdCacheAccessStrategy = persister.getNaturalIdCacheAccessStrategy(); final Object naturalIdCacheKey = naturalIdCacheAccessStrategy.generateCacheKey( naturalIdValues, persister, session ); naturalIdCacheAccessStrategy.evict( naturalIdCacheKey ); // if ( sessionCachedNaturalIdValues != null // && !Arrays.equals( sessionCachedNaturalIdValues, deletedNaturalIdValues ) ) { // final NaturalIdCacheKey sessionNaturalIdCacheKey = new NaturalIdCacheKey( sessionCachedNaturalIdValues, persister, session ); // naturalIdCacheAccessStrategy.evict( sessionNaturalIdCacheKey ); // } }
@Override public void clear() { for ( EntityDataAccess cacheAccess : entityDataAccessMap.values() ) { cacheAccess.evictAll(); } for ( NaturalIdDataAccess cacheAccess : naturalIdDataAccessMap.values() ) { cacheAccess.evictAll(); } for ( CollectionDataAccess cacheAccess : collectionDataAccessMap.values() ) { cacheAccess.evictAll(); } }
@Override public long getElementCountOnDisk() { long count = 0; HashSet<Region> processedRegions = null; for ( NaturalIdDataAccess accessStrategy : accessStrategies ) { final DomainDataRegion region = accessStrategy.getRegion(); if ( ExtendedStatisticsSupport.class.isInstance( region ) ) { } if ( region instanceof ExtendedStatisticsSupport ) { if ( processedRegions == null ) { processedRegions = new HashSet<>(); } if ( processedRegions.add( region ) ) { count += ( (ExtendedStatisticsSupport) region ).getElementCountOnDisk(); } } } if ( count == 0 ) { return NO_EXTENDED_STAT_SUPPORT_RETURN; } return count; }
public NaturalIdCleanup( NaturalIdDataAccess naturalIdCacheAccessStrategy, SharedSessionContractImplementor session) { this.naturalIdCacheAccessStrategy = naturalIdCacheAccessStrategy; this.cacheLock = naturalIdCacheAccessStrategy.lockRegion(); naturalIdCacheAccessStrategy.removeAll( session ); }
CachedNaturalIdValueSource source) { final NaturalIdDataAccess naturalIdCacheAccessStrategy = persister.getNaturalIdCacheAccessStrategy(); final Object naturalIdCacheKey = naturalIdCacheAccessStrategy.generateCacheKey( naturalIdValues, persister, session ); final boolean put = naturalIdCacheAccessStrategy.putFromLoad( session, naturalIdCacheKey, factory.getStatistics().naturalIdCachePut( StatsHelper.INSTANCE.getRootEntityRole( persister ), naturalIdCacheAccessStrategy.getRegion().getName() ); final boolean put = naturalIdCacheAccessStrategy.insert( session, naturalIdCacheKey, id ); if ( put && factory.getStatistics().isStatisticsEnabled() ) { factory.getStatistics().naturalIdCachePut( StatsHelper.INSTANCE.getRootEntityRole( persister ), naturalIdCacheAccessStrategy.getRegion().getName() ); final Object previousCacheKey = naturalIdCacheAccessStrategy.generateCacheKey( previousNaturalIdValues, persister, session ); if ( naturalIdCacheKey.equals( previousCacheKey ) ) { final SoftLock removalLock = naturalIdCacheAccessStrategy.lockItem( session, previousCacheKey, null ); naturalIdCacheAccessStrategy.remove( session, previousCacheKey); final SoftLock lock = naturalIdCacheAccessStrategy.lockItem( session, naturalIdCacheKey, null ); final boolean put = naturalIdCacheAccessStrategy.update( session, naturalIdCacheKey, id ); if ( put && factory.getStatistics().isStatisticsEnabled() ) {
Object[] previousNaturalIdValues, CachedNaturalIdValueSource source) { final Object naturalIdCacheKey = cacheAccess.generateCacheKey( naturalIdValues, descriptor.getHierarchy(), session ); final boolean put = cacheAccess.putFromLoad( session, naturalIdCacheKey, factory.getStatistics().naturalIdCachePut( descriptor.getNavigableRole(), cacheAccess.getRegion().getName() ); final boolean put = cacheAccess.insert( session, naturalIdCacheKey, id ); if ( put && factory.getStatistics().isStatisticsEnabled() ) { factory.getStatistics().naturalIdCachePut( descriptor.getNavigableRole(), cacheAccess.getRegion().getName() ); (success, session) -> { if (success) { final boolean put1 = cacheAccess.afterInsert( session, naturalIdCacheKey, id ); cacheAccess.getRegion().getName() ); cacheAccess.evict( naturalIdCacheKey );
final Object naturalIdCacheKey = naturalIdCacheAccessStrategy.generateCacheKey( naturalIdValues, persister, session() ); factory.getStatistics().naturalIdCacheHit( StatsHelper.INSTANCE.getRootEntityRole( persister ), naturalIdCacheAccessStrategy.getRegion().getName() ); factory.getStatistics().naturalIdCacheMiss( StatsHelper.INSTANCE.getRootEntityRole( persister ), naturalIdCacheAccessStrategy.getRegion().getName() );
public NaturalIdCleanup(NaturalIdDataAccess naturalIdCacheAccessStrategy, SharedSessionContractImplementor session) { this.naturalIdCacheAccessStrategy = naturalIdCacheAccessStrategy; this.cacheLock = naturalIdCacheAccessStrategy.lockRegion(); naturalIdCacheAccessStrategy.removeAll( session ); }
.getCacheAccess(); final Object naturalIdCacheKey = naturalIdCacheAccessStrategy.generateCacheKey( naturalIdValues, entityDescriptor.getHierarchy(), factory.getStatistics().naturalIdCacheHit( StatsHelper.INSTANCE.getRootEntityRole( entityDescriptor ), cacheAccess.getRegion().getName() ); factory.getStatistics().naturalIdCacheMiss( entityDescriptor.getNavigableRole(), cacheAccess.getRegion().getName() );
final NaturalIdDataAccess naturalIdCacheAccessStrategy = persister .getNaturalIdCacheAccessStrategy(); final Object naturalIdCacheKey = naturalIdCacheAccessStrategy.generateCacheKey( naturalIdValues, persister, session() ); naturalIdCacheAccessStrategy.evict( naturalIdCacheKey ); final Object sessionNaturalIdCacheKey = naturalIdCacheAccessStrategy.generateCacheKey( sessionCachedNaturalIdValues, persister, session() ); naturalIdCacheAccessStrategy.evict( sessionNaturalIdCacheKey );
@Override public long getElementCountInMemory() { long count = 0; HashSet<Region> processedRegions = null; for ( NaturalIdDataAccess accessStrategy : accessStrategies ) { final DomainDataRegion region = accessStrategy.getRegion(); if ( ExtendedStatisticsSupport.class.isInstance( region ) ) { } if ( region instanceof ExtendedStatisticsSupport ) { if ( processedRegions == null ) { processedRegions = new HashSet<>(); } if ( processedRegions.add( region ) ) { count += ( (ExtendedStatisticsSupport) region ).getElementCountInMemory(); } } } if ( count == 0 ) { return NO_EXTENDED_STAT_SUPPORT_RETURN; } return count; }
private void evictNaturalIdData(NavigableRole rootEntityRole, NaturalIdDataAccess cacheAccess) { if ( cacheAccess == null ) { return; } if ( LOG.isDebugEnabled() ) { LOG.debugf( "Evicting natural-id cache: %s", rootEntityRole.getFullPath() ); } cacheAccess.evictAll(); }
final Object naturalIdCacheKey = cacheAccess.generateCacheKey( naturalIdValues, entityDescriptor.getHierarchy(), session() ); cacheAccess.evict( naturalIdCacheKey ); final Object sessionNaturalIdCacheKey = cacheAccess.generateCacheKey( sessionCachedNaturalIdValues, entityDescriptor.getHierarchy(), session() ); cacheAccess.evict( sessionNaturalIdCacheKey );
@Override public long getSizeInMemory() { long count = 0; HashSet<Region> processedRegions = null; for ( NaturalIdDataAccess accessStrategy : accessStrategies ) { final DomainDataRegion region = accessStrategy.getRegion(); if ( ExtendedStatisticsSupport.class.isInstance( region ) ) { } if ( region instanceof ExtendedStatisticsSupport ) { if ( processedRegions == null ) { processedRegions = new HashSet<>(); } if ( processedRegions.add( region ) ) { count += ( (ExtendedStatisticsSupport) region ).getElementCountOnDisk(); } } } if ( count == 0 ) { return NO_EXTENDED_STAT_SUPPORT_RETURN; } return count; }
@Override public void clear() { for ( EntityDataAccess cacheAccess : entityDataAccessMap.values() ) { cacheAccess.evictAll(); } for ( NaturalIdDataAccess cacheAccess : naturalIdDataAccessMap.values() ) { cacheAccess.evictAll(); } for ( CollectionDataAccess cacheAccess : collectionDataAccessMap.values() ) { cacheAccess.evictAll(); } }
final Object naturalIdCacheKey = cacheAccess.generateCacheKey( naturalIdValues, descriptor.getHierarchy(), session ); cacheAccess.evict( naturalIdCacheKey );
NaturalIdStatisticsImpl(EntityPersister rootEntityDescriptor) { super( () -> rootEntityDescriptor.getNaturalIdCacheAccessStrategy() != null ? rootEntityDescriptor.getNaturalIdCacheAccessStrategy().getRegion() : null ); this.rootEntityName = rootEntityDescriptor.getRootEntityName(); final ReadWriteLock lock = new ReentrantReadWriteLock(); this.readLock = lock.readLock(); this.writeLock = lock.writeLock(); }
private void evictNaturalIdData(NavigableRole rootEntityRole, NaturalIdDataAccess cacheAccess) { if ( cacheAccess == null ) { return; } if ( LOG.isDebugEnabled() ) { LOG.debugf( "Evicting natural-id cache: %s", rootEntityRole.getFullPath() ); } cacheAccess.evictAll(); }
@Override public void naturalIdQueryExecuted(String rootEntityName, long time) { naturalIdQueryExecutionCount.increment(); boolean isLongestQuery; //noinspection StatementWithEmptyBody for ( long old = naturalIdQueryExecutionMaxTime.get(); ( isLongestQuery = time > old ) && ( !naturalIdQueryExecutionMaxTime.compareAndSet( old, time ) ); old = naturalIdQueryExecutionMaxTime.get() ) { // nothing to do here given the odd loop structure... } if ( isLongestQuery ) { naturalIdQueryExecutionMaxTimeEntity = rootEntityName; } final EntityPersister rootEntityPersister = sessionFactory.getMetamodel().entityPersister( rootEntityName ); getNaturalIdStatistics( rootEntityName ).queryExecuted( time ); if ( rootEntityPersister.hasNaturalIdCache() ) { final String naturalIdRegionName = rootEntityPersister.getNaturalIdCacheAccessStrategy() .getRegion() .getName(); getNaturalIdCacheStatistics( qualify( naturalIdRegionName ) ).queryExecuted( time ); if ( isLongestQuery ) { naturalIdQueryExecutionMaxTimeRegion = naturalIdRegionName; } } }
NaturalIdStatisticsImpl(EntityTypeDescriptor rootEntityDescriptor) { super( () -> rootEntityDescriptor.getHierarchy().getNaturalIdDescriptor().getCacheAccess() != null ? rootEntityDescriptor.getHierarchy().getNaturalIdDescriptor().getCacheAccess().getRegion() : null ); this.rootEntityName = rootEntityDescriptor.getEntityName(); final ReadWriteLock lock = new ReentrantReadWriteLock(); this.readLock = lock.readLock(); this.writeLock = lock.writeLock(); }