Beispiel #1
0
  public int storeByteArray(final int id, final byte[] data) {
    int ret = id;

    if (id == NewPage) {
      ret = m_storageManager.storeByteArray(id, data);
      Entry e = new Entry(data);
      addEntry(ret, e);
    } else {
      if (m_bWriteThrough) {
        m_storageManager.storeByteArray(id, data);
      }

      Entry e = (Entry) m_buffer.get(new Integer(id));
      if (e != null) {
        e.m_data = new byte[data.length];
        System.arraycopy(data, 0, e.m_data, 0, data.length);

        if (m_bWriteThrough == false) {
          e.m_bDirty = true;
          m_hits++;
        } else {
          e.m_bDirty = false;
        }
      } else {
        e = new Entry(data);
        if (m_bWriteThrough == false) e.m_bDirty = true;
        addEntry(id, e);
      }
    }

    return ret;
  }
Beispiel #2
0
  public void flush() {
    Iterator it = m_buffer.entrySet().iterator();

    while (it.hasNext()) {
      Map.Entry me = (Map.Entry) it.next();
      Entry e = (Entry) me.getValue();
      int id = ((Integer) me.getKey()).intValue();
      if (e.m_bDirty) m_storageManager.storeByteArray(id, e.m_data);
    }

    m_storageManager.flush();
  }
Beispiel #3
0
  public void deleteByteArray(final int id) {
    Integer ID = new Integer(id);
    Entry e = (Entry) m_buffer.get(ID);
    if (e != null) {
      m_buffer.remove(ID);
    }

    m_storageManager.deleteByteArray(id);
  }
Beispiel #4
0
  public byte[] loadByteArray(final int id) {
    byte[] ret = null;
    Entry e = (Entry) m_buffer.get(new Integer(id));

    if (e != null) {
      m_hits++;

      ret = new byte[e.m_data.length];
      System.arraycopy(e.m_data, 0, ret, 0, e.m_data.length);
    } else {
      ret = m_storageManager.loadByteArray(id);
      e = new Entry(ret);
      addEntry(id, e);
    }

    return ret;
  }