Пример #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;
    }
  }
Пример #2
0
 /** Update all dirty cache objects to the underlying RecordManager. */
 protected void updateCacheEntries() throws IOException {
   Iterator<CacheEntry> iter = _hash.valuesIterator();
   while (iter.hasNext()) {
     CacheEntry entry = iter.next();
     if (entry._isDirty) {
       _recman.update(entry._recid, entry._obj, entry._serializer);
       entry._isDirty = false;
     }
   }
 }
Пример #3
0
  public synchronized void close() throws IOException {
    checkIfClosed();

    updateCacheEntries();
    _recman.close();
    _recman = null;
    _hash = null;
    _softHash = null;
    if (_softCache) _softRefThread.interrupt();
  }
Пример #4
0
  /**
   * Purge least recently used object from the cache
   *
   * @return recyclable CacheEntry
   */
  protected CacheEntry purgeEntry() throws IOException {
    CacheEntry entry = _first;
    if (entry == null) return new CacheEntry(-1, null, null, false);

    if (entry._isDirty) _recman.update(entry._recid, entry._obj, entry._serializer);
    removeEntry(entry);
    _hash.remove(entry._recid);

    entry._obj = null;
    entry._serializer = null;
    entry._isDirty = false;
    return entry;
  }
Пример #5
0
  public synchronized <A> long insert(A obj, Serializer<A> serializer) throws IOException {
    checkIfClosed();

    long recid = _recman.insert(obj, serializer);

    // DONT use cache for inserts, it usually hurts performance on batch inserts
    //        if(_softCache) synchronized(_softHash) {
    //        	_softHash.put(recid, new SoftCacheEntry(recid, obj, serializer,_refQueue));
    //        }else {
    //        	cachePut(  recid , obj, serializer, false );
    //        }
    return recid;
  }
Пример #6
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();
        }
      }
  }
Пример #7
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;
  }
Пример #8
0
 public void defrag() throws IOException {
   commit();
   _recman.defrag();
 }
Пример #9
0
  public synchronized void setNamedObject(String name, long recid) throws IOException {
    checkIfClosed();

    _recman.setNamedObject(name, recid);
  }
Пример #10
0
  public synchronized long getNamedObject(String name) throws IOException {
    checkIfClosed();

    return _recman.getNamedObject(name);
  }
Пример #11
0
 public synchronized void commit() throws IOException {
   checkIfClosed();
   updateCacheEntries();
   _recman.commit();
 }
Пример #12
0
 public synchronized <A> A fetch(long recid, Serializer<A> serializer, boolean disableCache)
     throws IOException {
   if (disableCache) return _recman.fetch(recid, serializer, disableCache);
   else return fetch(recid, serializer);
 }