Package org.hibernate.cache

Examples of org.hibernate.cache.Cache


  }

  public Set getAllKeysFromRegionCache( String region ) {
    Set set = null;
    if ( cacheEnabled ) {
      Cache cache = regionCache.get( region );
      if ( cacheEnabled( region ) ) {
        Map cacheMap = cache.toMap();
        if ( cacheMap != null ) {
          set = cacheMap.keySet();
        }
      }
    } else {
View Full Code Here


  }

  public Set getAllEntriesFromRegionCache( String region ) {
    Set set = null;
    if ( cacheEnabled ) {
      Cache cache = regionCache.get( region );
      if ( cacheEnabled( region ) ) {
        Map cacheMap = cache.toMap();
        if ( cacheMap != null ) {
          set = cacheMap.entrySet();
        }
      }
    } else {
View Full Code Here

    return set;
  }

  public void removeFromRegionCache( String region, Object key ) {
    if ( cacheEnabled ) {
      Cache cache = regionCache.get( region );
      if ( cacheEnabled( region ) ) {
        cache.remove( key );
      } else {
        CacheManager.logger.warn( Messages.getInstance().getString(
            "CacheManager.WARN_0003_REGION_DOES_NOT_EXIST", region ) ); //$NON-NLS-1$
      }
    } else {
View Full Code Here

      Iterator it = regionCache.entrySet().iterator();
      while ( it.hasNext() ) {
        Map.Entry entry = (Map.Entry) it.next();
        String key = ( entry.getKey() != null ) ? entry.getKey().toString() : ""; //$NON-NLS-1$
        if ( key != null ) {
          Cache cache = regionCache.get( key );
          cache.clear();
        }
      }
    }
  }
View Full Code Here

    return getFromRegionCache( SESSION, getCorrectedKey( session, key ) );
  }

  public void killSessionCache( IPentahoSession session ) {
    if ( cacheEnabled ) {
      Cache cache = regionCache.get( SESSION );
      if ( cache != null ) {
        Map cacheMap = cache.toMap();
        if ( cacheMap != null ) {
          Set set = cacheMap.keySet();
          Iterator it = set.iterator();
          while ( it.hasNext() ) {
            String key = (String) it.next();
            if ( key.indexOf( session.getId() ) >= 0 ) {
              cache.remove( key );
            }
          }
        }
      }
    }
View Full Code Here

    }
  }

  private LastModifiedCache buildCache( String key, Properties cacheProperties ) {
    if ( getCacheProvider() != null ) {
      Cache cache = getCacheProvider().buildCache( key, cacheProperties );
      LastModifiedCache lmCache = new LastModifiedCache( cache );
      if ( cacheExpirationRegistry != null ) {
        cacheExpirationRegistry.register( lmCache );
      } else {
        logger.warn( Messages.getInstance().getErrorString( "CacheManager.WARN_0003_NO_CACHE_EXPIRATION_REGISTRY" ) );
View Full Code Here

  }

  @Override
  public long getElementCountInRegionCache( String region ) {
    if ( cacheEnabled ) {
      Cache cache = regionCache.get( region );
      if ( cache != null ) {
        try {
          long memCnt = cache.getElementCountInMemory();
          long discCnt = cache.getElementCountOnDisk();
          return memCnt + discCnt;
        } catch ( Exception ignored ) {
          return -1;
        }
      } else {
View Full Code Here

    doTestCache( new HashtableCacheProvider() );
  }

  public void doTestCache(CacheProvider cacheProvider) throws Exception {

    Cache cache = cacheProvider.buildCache( String.class.getName(), System.getProperties() );

    long longBefore = cache.nextTimestamp();

    Thread.sleep(15);

    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

    doTestCache( new HashtableCacheProvider() );
  }

  public void doTestCache(CacheProvider cacheProvider) throws Exception {

    Cache cache = cacheProvider.buildCache( String.class.getName(), System.getProperties() );

    long longBefore = cache.nextTimestamp();

    Thread.sleep(15);

    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

    doTestCache( new HashtableCacheProvider() );
  }

  public void doTestCache(CacheProvider cacheProvider) throws Exception {

    Cache cache = cacheProvider.buildCache( String.class.getName(), System.getProperties() );

    long longBefore = cache.nextTimestamp();

    Thread.sleep(15);

    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

TOP

Related Classes of org.hibernate.cache.Cache

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.