Пример #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;
  }
Пример #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();
  }