Package org.hibernate.cache

Examples of org.hibernate.cache.CacheConcurrencyStrategy$SoftLock


      ( ( OptimisticCache ) underlyingCache ).setSource( new OptimisticCacheSourceAdapter( metadata ) );
    }
  }

  public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
    CacheConcurrencyStrategy ccs;
    if ( AccessType.READ_ONLY.equals( accessType ) ) {
      if ( metadata.isMutable() ) {
        log.warn( "read-only cache configured for mutable entity [" + getName() + "]" );
      }
      ccs = new ReadOnlyCache();
    }
    else if ( AccessType.READ_WRITE.equals( accessType ) ) {
      ccs = new ReadWriteCache();
    }
    else if ( AccessType.NONSTRICT_READ_WRITE.equals( accessType ) ) {
      ccs = new NonstrictReadWriteCache();
    }
    else if ( AccessType.TRANSACTIONAL.equals( accessType ) ) {
      ccs = new TransactionalCache();
    }
    else {
      throw new IllegalArgumentException( "unrecognized access strategy type [" + accessType + "]" );
    }
    ccs.setCache( underlyingCache );
    return new EntityAccessStrategyAdapter( this, ccs, settings );
  }
View Full Code Here


      ( ( OptimisticCache ) underlyingCache ).setSource( new OptimisticCacheSourceAdapter( metadata ) );
    }
  }

  public CollectionRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
    CacheConcurrencyStrategy ccs;
    if ( AccessType.READ_ONLY.equals( accessType ) ) {
      if ( metadata.isMutable() ) {
        log.warn( "read-only cache configured for mutable collection [" + getName() + "]" );
      }
      ccs = new ReadOnlyCache();
    }
    else if ( AccessType.READ_WRITE.equals( accessType ) ) {
      ccs = new ReadWriteCache();
    }
    else if ( AccessType.NONSTRICT_READ_WRITE.equals( accessType ) ) {
      ccs = new NonstrictReadWriteCache();
    }
    else if ( AccessType.TRANSACTIONAL.equals( accessType ) ) {
      ccs = new TransactionalCache();
    }
    else {
      throw new IllegalArgumentException( "unrecognized access strategy type [" + accessType + "]" );
    }
    ccs.setCache( underlyingCache );
    return new CollectionAccessStrategyAdapter( this, ccs, settings );
  }
View Full Code Here

      ( ( OptimisticCache ) underlyingCache ).setSource( new OptimisticCacheSourceAdapter( metadata ) );
    }
  }

  public CollectionRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
    CacheConcurrencyStrategy ccs;
    if ( AccessType.READ_ONLY.equals( accessType ) ) {
      if ( metadata.isMutable() ) {
        log.warn( "read-only cache configured for mutable collection [" + getName() + "]" );
      }
      ccs = new ReadOnlyCache();
    }
    else if ( AccessType.READ_WRITE.equals( accessType ) ) {
      ccs = new ReadWriteCache();
    }
    else if ( AccessType.NONSTRICT_READ_WRITE.equals( accessType ) ) {
      ccs = new NonstrictReadWriteCache();
    }
    else if ( AccessType.TRANSACTIONAL.equals( accessType ) ) {
      ccs = new TransactionalCache();
    }
    else {
      throw new IllegalArgumentException( "unrecognized access strategy type [" + accessType + "]" );
    }
    ccs.setCache( underlyingCache );
    return new CollectionAccessStrategyAdapter( this, ccs, settings );
  }
View Full Code Here

      ( ( OptimisticCache ) underlyingCache ).setSource( new OptimisticCacheSourceAdapter( metadata ) );
    }
  }

  public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
    CacheConcurrencyStrategy ccs;
    if ( AccessType.READ_ONLY.equals( accessType ) ) {
      if ( metadata.isMutable() ) {
        log.warn( "read-only cache configured for mutable entity [" + getName() + "]" );
      }
      ccs = new ReadOnlyCache();
    }
    else if ( AccessType.READ_WRITE.equals( accessType ) ) {
      ccs = new ReadWriteCache();
    }
    else if ( AccessType.NONSTRICT_READ_WRITE.equals( accessType ) ) {
      ccs = new NonstrictReadWriteCache();
    }
    else if ( AccessType.TRANSACTIONAL.equals( accessType ) ) {
      ccs = new TransactionalCache();
    }
    else {
      throw new IllegalArgumentException( "unrecognized access strategy type [" + accessType + "]" );
    }
    ccs.setCache( underlyingCache );
    return new EntityAccessStrategyAdapter( this, ccs, settings );
  }
View Full Code Here

    classes = cfg.getClassMappings();
    while ( classes.hasNext() ) {
      PersistentClass model = (PersistentClass) classes.next();
      model.prepareTemporaryTables( mapping, settings.getDialect() );
      String cacheRegion = model.getRootClass().getCacheRegionName();
      CacheConcurrencyStrategy cache = (CacheConcurrencyStrategy) caches.get(cacheRegion);
      if (cache==null) {
        cache = CacheFactory.createCache(
            model.getCacheConcurrencyStrategy(),
                cacheRegion,
                model.isMutable(),
                settings,
                properties
          );
        if (cache!=null) {
          caches.put(cacheRegion, cache);
          allCacheRegions.put( cache.getRegionName(), cache.getCache() );
        }
      }
      EntityPersister cp = PersisterFactory.createClassPersister(model, cache, this, mapping);
      if ( cache != null && cache.getCache() instanceof OptimisticCache ) {
        ( ( OptimisticCache ) cache.getCache() ).setSource( cp );
      }
      entityPersisters.put( model.getEntityName(), cp );
      classMeta.put( model.getEntityName(), cp.getClassMetadata() );
    }
    classMetadata = Collections.unmodifiableMap(classMeta);

    Map tmpEntityToCollectionRoleMap = new HashMap();
    collectionPersisters = new HashMap();
    Iterator collections = cfg.getCollectionMappings();
    while ( collections.hasNext() ) {
      Collection model = (Collection) collections.next();
      CacheConcurrencyStrategy cache = CacheFactory.createCache(
          model.getCacheConcurrencyStrategy(),
            model.getCacheRegionName(),
            model.isMutable(),
            settings,
            properties
      );
      if ( cache != null ) {
        allCacheRegions.put( cache.getRegionName(), cache.getCache() );
      }
      CollectionPersister persister = PersisterFactory.createCollectionPersister(cfg, model, cache, this);
      collectionPersisters.put( model.getRole(), persister.getCollectionMetadata() );
      Type indexType = persister.getIndexType();
      if ( indexType != null && indexType.isAssociationType() && !indexType.isAnyType() ) {
View Full Code Here

      ( ( OptimisticCache ) underlyingCache ).setSource( new OptimisticCacheSourceAdapter( metadata ) );
    }
  }

  public CollectionRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
    CacheConcurrencyStrategy ccs;
    if ( AccessType.READ_ONLY.equals( accessType ) ) {
      if ( metadata.isMutable() ) {
        log.warn( "read-only cache configured for mutable collection [" + getName() + "]" );
      }
      ccs = new ReadOnlyCache();
    }
    else if ( AccessType.READ_WRITE.equals( accessType ) ) {
      ccs = new ReadWriteCache();
    }
    else if ( AccessType.NONSTRICT_READ_WRITE.equals( accessType ) ) {
      ccs = new NonstrictReadWriteCache();
    }
    else if ( AccessType.TRANSACTIONAL.equals( accessType ) ) {
      ccs = new TransactionalCache();
    }
    else {
      throw new IllegalArgumentException( "unrecognized access strategy type [" + accessType + "]" );
    }
    ccs.setCache( underlyingCache );
    return new CollectionAccessStrategyAdapter( this, ccs, settings );
  }
View Full Code Here

      ( ( OptimisticCache ) underlyingCache ).setSource( new OptimisticCacheSourceAdapter( metadata ) );
    }
  }

  public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
    CacheConcurrencyStrategy ccs;
    if ( AccessType.READ_ONLY.equals( accessType ) ) {
      if ( metadata.isMutable() ) {
        log.warn( "read-only cache configured for mutable entity [" + getName() + "]" );
      }
      ccs = new ReadOnlyCache();
    }
    else if ( AccessType.READ_WRITE.equals( accessType ) ) {
      ccs = new ReadWriteCache();
    }
    else if ( AccessType.NONSTRICT_READ_WRITE.equals( accessType ) ) {
      ccs = new NonstrictReadWriteCache();
    }
    else if ( AccessType.TRANSACTIONAL.equals( accessType ) ) {
      ccs = new TransactionalCache();
    }
    else {
      throw new IllegalArgumentException( "unrecognized access strategy type [" + accessType + "]" );
    }
    ccs.setCache( underlyingCache );
    return new EntityAccessStrategyAdapter( this, ccs, settings );
  }
View Full Code Here

    long before = cache.nextTimestamp();

    Thread.sleep(15);

    //cache.setTimeout(1000);
    CacheConcurrencyStrategy ccs = new ReadWriteCache();
    ccs.setCache(cache);

    // cache something

    assertTrue( ccs.put("foo", "foo", before, null, null, false) );

    Thread.sleep(15);

    long after = cache.nextTimestamp();

    assertTrue( ccs.get("foo", longBefore)==null );
    assertTrue( ccs.get("foo", after).equals("foo") );

    assertTrue( !ccs.put("foo", "foo", before, null, null, false) );

    // update it:

    SoftLock lock = ccs.lock("foo", null);

    assertTrue( ccs.get("foo", after)==null );
    assertTrue( ccs.get("foo", longBefore)==null );

    assertTrue( !ccs.put("foo", "foo", before, null, null, false) );

    Thread.sleep(15);

    long whileLocked = cache.nextTimestamp();

    assertTrue( !ccs.put("foo", "foo", whileLocked, null, null, false) );

    Thread.sleep(15);

    ccs.release("foo", lock);

    assertTrue( ccs.get("foo", after)==null );
    assertTrue( ccs.get("foo", longBefore)==null );

    assertTrue( !ccs.put("foo", "bar", whileLocked, null, null, false) );
    assertTrue( !ccs.put("foo", "bar", after, null, null, false) );

    Thread.sleep(15);

    long longAfter = cache.nextTimestamp();

    assertTrue( ccs.put("foo", "baz", longAfter, null, null, false) );

    assertTrue( ccs.get("foo", after)==null );
    assertTrue( ccs.get("foo", whileLocked)==null );

    Thread.sleep(15);

    long longLongAfter = cache.nextTimestamp();

    assertTrue( ccs.get("foo", longLongAfter).equals("baz") );

    // update it again, with multiple locks:

    SoftLock lock1 = ccs.lock("foo", null);
    SoftLock lock2 = ccs.lock("foo", null);

    assertTrue( ccs.get("foo", longLongAfter)==null );

    Thread.sleep(15);

    whileLocked = cache.nextTimestamp();

    assertTrue( !ccs.put("foo", "foo", whileLocked, null, null, false) );

    Thread.sleep(15);

    ccs.release("foo", lock2);

    Thread.sleep(15);

    long betweenReleases = cache.nextTimestamp();

    assertTrue( !ccs.put("foo", "bar", betweenReleases, null, null, false) );
    assertTrue( ccs.get("foo", betweenReleases)==null );

    Thread.sleep(15);

    ccs.release("foo", lock1);

    assertTrue( !ccs.put("foo", "bar", whileLocked, null, null, false) );

    Thread.sleep(15);

    longAfter = cache.nextTimestamp();

    assertTrue( ccs.put("foo", "baz", longAfter, null, null, false) );
    assertTrue( ccs.get("foo", whileLocked)==null );

    Thread.sleep(15);

    longLongAfter = cache.nextTimestamp();

    assertTrue( ccs.get("foo", longLongAfter).equals("baz") );

  }
View Full Code Here

      ( ( OptimisticCache ) underlyingCache ).setSource( new OptimisticCacheSourceAdapter( metadata ) );
    }
  }

  public CollectionRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
    CacheConcurrencyStrategy ccs;
    if ( AccessType.READ_ONLY.equals( accessType ) ) {
            if (metadata.isMutable()) LOG.readOnlyCacheConfiguredForMutableCollection(getName());
      ccs = new ReadOnlyCache();
    }
    else if ( AccessType.READ_WRITE.equals( accessType ) ) {
      ccs = new ReadWriteCache();
    }
    else if ( AccessType.NONSTRICT_READ_WRITE.equals( accessType ) ) {
      ccs = new NonstrictReadWriteCache();
    }
    else if ( AccessType.TRANSACTIONAL.equals( accessType ) ) {
      ccs = new TransactionalCache();
    }
    else {
      throw new IllegalArgumentException( "unrecognized access strategy type [" + accessType + "]" );
    }
    ccs.setCache( underlyingCache );
    return new CollectionAccessStrategyAdapter( this, ccs, settings );
  }
View Full Code Here

      ( ( OptimisticCache ) underlyingCache ).setSource( new OptimisticCacheSourceAdapter( metadata ) );
    }
  }

  public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) throws CacheException {
    CacheConcurrencyStrategy ccs;
    if ( AccessType.READ_ONLY.equals( accessType ) ) {
            if (metadata.isMutable()) LOG.readOnlyCacheConfiguredForMutableCollection(getName());
      ccs = new ReadOnlyCache();
    }
    else if ( AccessType.READ_WRITE.equals( accessType ) ) {
      ccs = new ReadWriteCache();
    }
    else if ( AccessType.NONSTRICT_READ_WRITE.equals( accessType ) ) {
      ccs = new NonstrictReadWriteCache();
    }
    else if ( AccessType.TRANSACTIONAL.equals( accessType ) ) {
      ccs = new TransactionalCache();
    }
    else {
      throw new IllegalArgumentException( "unrecognized access strategy type [" + accessType + "]" );
    }
    ccs.setCache( underlyingCache );
    return new EntityAccessStrategyAdapter( this, ccs, settings );
  }
View Full Code Here

TOP

Related Classes of org.hibernate.cache.CacheConcurrencyStrategy$SoftLock

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.