Example #1
0
  public synchronized <A> A fetch(long recid, Serializer<A> serializer) throws IOException {
    checkIfClosed();
    if (_softCache)
      synchronized (_softHash) {
        SoftCacheEntry e = _softHash.get(recid);
        if (e != null) {
          Object a = e.get();
          if (a != null) {
            return (A) a;
          }
        }
      }

    CacheEntry entry = (CacheEntry) cacheGet(recid);
    if (entry == null) {
      A value = _recman.fetch(recid, serializer);
      if (!_softCache) cachePut(recid, value, serializer, false);
      else { // put record into soft cache
        synchronized (_softHash) {
          _softHash.put(recid, new SoftCacheEntry(recid, value, _refQueue));
        }
      }
      return value;
    } else {
      return (A) entry._obj;
    }
  }
Example #2
0
  public void clearCache() throws IOException {
    // discard all cache entries since we don't know which entries
    // where part of the transaction
    while (_hash.size() > 0) purgeEntry();

    if (_softCache)
      synchronized (_softHash) {
        Iterator<SoftCacheEntry> iter = _softHash.valuesIterator();
        while (iter.hasNext()) {
          SoftCacheEntry e = iter.next();
          e.clear();
        }
        _softHash.clear();
      }
    _first = null;
    _last = null;
  }
Example #3
0
  public synchronized void delete(long recid) throws IOException {
    checkIfClosed();

    _recman.delete(recid);
    CacheEntry entry = _hash.get(recid);
    if (entry != null) {
      removeEntry(entry);
      _hash.remove(entry._recid);
    }
    if (_softCache)
      synchronized (_softHash) {
        SoftCacheEntry e = _softHash.remove(recid);
        if (e != null) {
          e.clear();
        }
      }
  }
Example #4
0
  public synchronized void rollback() throws IOException {
    checkIfClosed();

    _recman.rollback();

    // discard all cache entries since we don't know which entries
    // where part of the transaction
    _hash.clear();
    if (_softCache)
      synchronized (_softHash) {
        Iterator<SoftCacheEntry> iter = _softHash.valuesIterator();
        while (iter.hasNext()) {
          SoftCacheEntry e = iter.next();
          e.clear();
        }
        _softHash.clear();
      }
    _first = null;
    _last = null;
  }
Example #5
0
 public synchronized <A> void update(long recid, A obj, Serializer<A> serializer)
     throws IOException {
   checkIfClosed();
   if (_softCache)
     synchronized (_softHash) {
       // soft cache can not contain dirty objects
       SoftCacheEntry e = _softHash.remove(recid);
       if (e != null) {
         e.clear();
       }
     }
   CacheEntry entry = cacheGet(recid);
   if (entry != null) {
     // reuse existing cache entry
     entry._obj = obj;
     entry._serializer = serializer;
     entry._isDirty = true;
   } else {
     cachePut(recid, obj, serializer, true);
   }
 }