Package org.hibernate.cache.spi.access

Examples of org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy


        event.getLockOptions(),
        event.getSession()
    );
   
    if ( stats ) {
      final NaturalIdRegionAccessStrategy naturalIdCacheAccessStrategy = event.getEntityPersister().getNaturalIdCacheAccessStrategy();
      final String regionName = naturalIdCacheAccessStrategy == null ? null : naturalIdCacheAccessStrategy.getRegion().getName();
     
      factory.getStatisticsImplementor().naturalIdQueryExecuted(
          regionName,
          System.currentTimeMillis() - startTime );
    }
View Full Code Here


          entityAccessStrategies.put( cacheRegionName, accessStrategy );
          cacheAccess.addCacheRegion( cacheRegionName, entityRegion );
        }
      }
     
      NaturalIdRegionAccessStrategy naturalIdAccessStrategy = null;
      if ( model.hasNaturalId() && model.getNaturalIdCacheRegionName() != null ) {
        final String naturalIdCacheRegionName = cacheRegionPrefix + model.getNaturalIdCacheRegionName();
        naturalIdAccessStrategy = ( NaturalIdRegionAccessStrategy ) entityAccessStrategies.get( naturalIdCacheRegionName );
       
        if ( naturalIdAccessStrategy == null && settings.isSecondLevelCacheEnabled() ) {
View Full Code Here

    }
   
    // Try resolution from second-level cache
    final NaturalIdCacheKey naturalIdCacheKey = new NaturalIdCacheKey( naturalIdValues, persister, session );
   
    final NaturalIdRegionAccessStrategy naturalIdCacheAccessStrategy = persister.getNaturalIdCacheAccessStrategy();
    pk = (Serializable) naturalIdCacheAccessStrategy.get( naturalIdCacheKey, session.getTimestamp() );

    // Found in second-level cache, store in session cache
    final SessionFactoryImplementor factory = getSession().getFactory();
    if ( pk != null ) {
      if ( factory.getStatistics().isStatisticsEnabled() ) {
        factory.getStatisticsImplementor().naturalIdCacheHit(
            naturalIdCacheAccessStrategy.getRegion().getName()
        );
      }

      if ( LOG.isTraceEnabled() )
        LOG.trace(
            "Resolved natural key -> primary key resolution in second-level cache: " +
                persister.getRootEntityName() + "#[" +
                Arrays.toString( naturalIdValues ) + "]"
        );

      if ( entityNaturalIdResolutionCache == null ) {
        entityNaturalIdResolutionCache = new NaturalIdResolutionCache( persister );
        naturalIdResolutionCacheMap.put( persister, entityNaturalIdResolutionCache );
      }

      entityNaturalIdResolutionCache.pkToNaturalIdMap.put( pk, localNaturalIdCacheKey );
      entityNaturalIdResolutionCache.naturalIdToPkMap.put( localNaturalIdCacheKey, pk );
    }
    else if ( factory.getStatistics().isStatisticsEnabled() ) {
      factory.getStatisticsImplementor().naturalIdCacheMiss( naturalIdCacheAccessStrategy.getRegion().getName() );
    }

    return pk;
  }
View Full Code Here

    entityNaturalIdResolutionCache.pkToNaturalIdMap.put( pk, localNaturalIdCacheKey );
    entityNaturalIdResolutionCache.naturalIdToPkMap.put( localNaturalIdCacheKey, pk );

    //If second-level caching is enabled cache the resolution there as well
    if ( persister.hasNaturalIdCache() ) {
      final NaturalIdRegionAccessStrategy naturalIdCacheAccessStrategy = persister.getNaturalIdCacheAccessStrategy();
      final NaturalIdCacheKey naturalIdCacheKey = new NaturalIdCacheKey( naturalIdValues, persister, session );

      final SessionFactoryImplementor factory = getSession().getFactory();
     
      switch ( valueSource ) {
        case LOAD: {
          final boolean put = naturalIdCacheAccessStrategy.putFromLoad(
              naturalIdCacheKey,
              pk,
              session.getTimestamp(),
              null
          );

          if ( put && factory.getStatistics().isStatisticsEnabled() ) {
            factory.getStatisticsImplementor()
                .naturalIdCachePut( naturalIdCacheAccessStrategy.getRegion().getName() );
          }

          break;
        }
        case INSERT: {
          naturalIdCacheAccessStrategy.insert( naturalIdCacheKey, pk );

          ( (EventSource) this.session ).getActionQueue().registerProcess(
              new AfterTransactionCompletionProcess() {
                @Override
                public void doAfterTransactionCompletion(boolean success, SessionImplementor session) {
                  final boolean put = naturalIdCacheAccessStrategy.afterInsert( naturalIdCacheKey, pk );

                  if ( put && factory.getStatistics().isStatisticsEnabled() ) {
                    factory.getStatisticsImplementor().naturalIdCachePut(
                        naturalIdCacheAccessStrategy.getRegion().getName() );
                  }
                }
              }
          );

          break;
        }
        case UPDATE: {
          final SoftLock lock = naturalIdCacheAccessStrategy.lockItem( naturalIdCacheKey, null );
          naturalIdCacheAccessStrategy.update( naturalIdCacheKey, pk );

          ( (EventSource) this.session ).getActionQueue().registerProcess(
              new AfterTransactionCompletionProcess() {
                @Override
                public void doAfterTransactionCompletion(boolean success, SessionImplementor session) {
                  final boolean put = naturalIdCacheAccessStrategy.afterUpdate( naturalIdCacheKey, pk, lock );

                  if ( put && factory.getStatistics().isStatisticsEnabled() ) {
                    factory.getStatisticsImplementor().naturalIdCachePut(
                        naturalIdCacheAccessStrategy.getRegion().getName() );
                  }
                }
              }
          );
View Full Code Here

      entityNaturalIdResolutionCache.pkToNaturalIdMap.remove( pk );
      entityNaturalIdResolutionCache.naturalIdToPkMap.remove( localNaturalIdCacheKey );
    }

    if ( persister.hasNaturalIdCache() ) {
      final NaturalIdRegionAccessStrategy naturalIdCacheAccessStrategy = persister.getNaturalIdCacheAccessStrategy();
      final NaturalIdCacheKey naturalIdCacheKey = new NaturalIdCacheKey( naturalIdValues, persister, session );
      naturalIdCacheAccessStrategy.evict( naturalIdCacheKey );
    }
  }
View Full Code Here

          entityAccessStrategies.put( cacheRegionName, accessStrategy );
          allCacheRegions.put( cacheRegionName, entityRegion );
        }
      }
     
      NaturalIdRegionAccessStrategy naturalIdAccessStrategy = null;
      if ( model.hasNaturalId() && model.getNaturalIdCacheRegionName() != null ) {
        final String naturalIdCacheRegionName = cacheRegionPrefix + model.getNaturalIdCacheRegionName();
        naturalIdAccessStrategy = ( NaturalIdRegionAccessStrategy ) entityAccessStrategies.get( naturalIdCacheRegionName );
       
        if ( naturalIdAccessStrategy == null && settings.isSecondLevelCacheEnabled() ) {
View Full Code Here

        sessionCachedNaturalIdValues = cachedNaturalId.getValues();
      }
    }

    if ( persister.hasNaturalIdCache() ) {
      final NaturalIdRegionAccessStrategy naturalIdCacheAccessStrategy = persister
          .getNaturalIdCacheAccessStrategy();
      final NaturalIdCacheKey naturalIdCacheKey = new NaturalIdCacheKey( naturalIdValues, persister, session() );
      naturalIdCacheAccessStrategy.evict( naturalIdCacheKey );

      if ( sessionCachedNaturalIdValues != null
          && !Arrays.equals( sessionCachedNaturalIdValues, naturalIdValues ) ) {
        final NaturalIdCacheKey sessionNaturalIdCacheKey = new NaturalIdCacheKey( sessionCachedNaturalIdValues, persister, session() );
        naturalIdCacheAccessStrategy.evict( sessionNaturalIdCacheKey );
      }
    }

    return sessionCachedNaturalIdValues;
  }
View Full Code Here

    }

    // Try resolution from second-level cache
    final NaturalIdCacheKey naturalIdCacheKey = new NaturalIdCacheKey( naturalIdValues, persister, session() );

    final NaturalIdRegionAccessStrategy naturalIdCacheAccessStrategy = persister.getNaturalIdCacheAccessStrategy();
    pk = (Serializable) naturalIdCacheAccessStrategy.get( naturalIdCacheKey, session().getTimestamp() );

    // Found in second-level cache, store in session cache
    final SessionFactoryImplementor factory = session().getFactory();
    if ( pk != null ) {
      if ( factory.getStatistics().isStatisticsEnabled() ) {
        factory.getStatisticsImplementor().naturalIdCacheHit(
            naturalIdCacheAccessStrategy.getRegion().getName()
        );
      }

      if ( LOG.isTraceEnabled() ) {
        // protected to avoid Arrays.toString call unless needed
        LOG.tracef(
            "Found natural key [%s] -> primary key [%s] xref in second-level cache for %s",
            Arrays.toString( naturalIdValues ),
            pk,
            persister.getRootEntityName()
        );
      }

      if ( entityNaturalIdResolutionCache == null ) {
        entityNaturalIdResolutionCache = new NaturalIdResolutionCache( persister );
        naturalIdResolutionCacheMap.put( persister, entityNaturalIdResolutionCache );
      }

      entityNaturalIdResolutionCache.pkToNaturalIdMap.put( pk, cachedNaturalId );
      entityNaturalIdResolutionCache.naturalIdToPkMap.put( cachedNaturalId, pk );
    }
    else if ( factory.getStatistics().isStatisticsEnabled() ) {
      factory.getStatisticsImplementor().naturalIdCacheMiss( naturalIdCacheAccessStrategy.getRegion().getName() );
    }

    return pk;
  }
View Full Code Here

          entityAccessStrategies.put( cacheRegionName, accessStrategy );
          cacheAccess.addCacheRegion( cacheRegionName, entityRegion );
        }
      }
     
      NaturalIdRegionAccessStrategy naturalIdAccessStrategy = null;
      if ( model.hasNaturalId() && model.getNaturalIdCacheRegionName() != null ) {
        final String naturalIdCacheRegionName = cacheRegionPrefix + model.getNaturalIdCacheRegionName();
        naturalIdAccessStrategy = ( NaturalIdRegionAccessStrategy ) entityAccessStrategies.get( naturalIdCacheRegionName );
       
        if ( naturalIdAccessStrategy == null && settings.isSecondLevelCacheEnabled() ) {
View Full Code Here

          entityAccessStrategies.put( cacheRegionName, accessStrategy );
          allCacheRegions.put( cacheRegionName, entityRegion );
        }
      }
     
      NaturalIdRegionAccessStrategy naturalIdAccessStrategy = null;
      if ( model.hasNaturalId() && model.getNaturalIdCacheRegionName() != null ) {
        final String naturalIdCacheRegionName = cacheRegionPrefix + model.getNaturalIdCacheRegionName();
        naturalIdAccessStrategy = ( NaturalIdRegionAccessStrategy ) entityAccessStrategies.get( naturalIdCacheRegionName );
       
        if ( naturalIdAccessStrategy == null && settings.isSecondLevelCacheEnabled() ) {
View Full Code Here

TOP

Related Classes of org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.