Package org.hibernate.cache

Examples of org.hibernate.cache.Cache


   */
  public synchronized SecondLevelCacheStatistics getSecondLevelCacheStatistics(String regionName) {
    SecondLevelCacheStatistics slcs = (SecondLevelCacheStatistics) secondLevelCacheStatistics.get(regionName);
    if (slcs==null) {
      if (sessionFactory == null) return null;
      Cache cache = sessionFactory.getSecondLevelCacheRegion(regionName);
      if (cache==null) return null;
      slcs = new SecondLevelCacheStatistics(cache);
      secondLevelCacheStatistics.put(regionName, slcs);
    }
    return slcs;
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

    if ( null != obj ) {
      if ( obj instanceof CacheProvider ) {
        this.cacheProvider = (CacheProvider) obj;
        cacheProvider.start( cacheProperties );
        regionCache = new HashMap<String, Cache>();
        Cache cache = buildCache( SESSION, cacheProperties );
        if ( cache == null ) {
          CacheManager.logger
              .error( Messages.getInstance().getString( "CacheManager.ERROR_0005_UNABLE_TO_BUILD_CACHE" ) ); //$NON-NLS-1$
        } else {
          regionCache.put( SESSION, cache );
View Full Code Here

    }
    return cacheProperties;
  }

  public boolean cacheEnabled( String region ) {
    Cache cache = regionCache.get( region );
    if ( cache == null ) {
      return false;
    }
    return true;
  }
View Full Code Here

  public boolean addCacheRegion( String region, Properties cacheProperties ) {
    boolean returnValue = false;
    if ( cacheEnabled ) {
      if ( !cacheEnabled( region ) ) {
        Cache cache = buildCache( region, cacheProperties );
        if ( cache == null ) {
          CacheManager.logger
              .error( Messages.getInstance().getString( "CacheManager.ERROR_0005_UNABLE_TO_BUILD_CACHE" ) ); //$NON-NLS-1$
        } else {
          regionCache.put( region, cache );
View Full Code Here

  public boolean addCacheRegion( String region ) {
    boolean returnValue = false;
    if ( cacheEnabled ) {
      if ( !cacheEnabled( region ) ) {
        Cache cache = buildCache( region, null );
        if ( cache == null ) {
          CacheManager.logger
              .error( Messages.getInstance().getString( "CacheManager.ERROR_0005_UNABLE_TO_BUILD_CACHE" ) ); //$NON-NLS-1$
        } else {
          regionCache.put( region, cache );
View Full Code Here

    return returnValue;
  }

  public void clearRegionCache( String region ) {
    if ( cacheEnabled ) {
      Cache cache = regionCache.get( region );
      if ( cache != null ) {
        try {
          cache.clear();
        } catch ( CacheException e ) {
          CacheManager.logger.error( Messages.getInstance().getString(
            "CacheManager.ERROR_0006_CACHE_EXCEPTION", e.getLocalizedMessage() ) ); //$NON-NLS-1$
        }
      } else {
View Full Code Here

  }

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

  }

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

  }

  public List getAllValuesFromRegionCache( String region ) {
    List list = new ArrayList<Object>();
    if ( cacheEnabled ) {
      Cache cache = regionCache.get( region );
      if ( cacheEnabled( region ) ) {
        Map cacheMap = cache.toMap();
        if ( cacheMap != null ) {
          Iterator it = cacheMap.entrySet().iterator();
          while ( it.hasNext() ) {
            Map.Entry entry = (Map.Entry) it.next();
            list.add( entry.getValue() );
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.