Module lmdbjava
Package org.lmdbjava

Class BufferProxy<T>

java.lang.Object
org.lmdbjava.BufferProxy<T>
Type Parameters:
T - buffer type
Direct Known Subclasses:
ByteArrayProxy, ByteBufferProxy.AbstractByteBufferProxy, ByteBufProxy, DirectBufferProxy

public abstract class BufferProxy<T> extends Object
The strategy for mapping memory address to a given buffer type.

The proxy is passed to the Env.create(org.lmdbjava.BufferProxy) method and is subsequently used by every Txn, Dbi and Cursor associated with the Env.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Size of a MDB_val pointer in bytes.
    protected static final int
    Offset from a pointer of the MDB_val.mv_data field.
    protected static final int
    Offset from a pointer of the MDB_val.mv_size field.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract T
    Allocate a new buffer suitable for passing to out(java.lang.Object, jnr.ffi.Pointer, long).
    abstract int
    compare(T o1, T o2)
    Compare the two buffers.
    abstract void
    deallocate(T buff)
    Deallocate a buffer that was previously provided by allocate().
    protected abstract byte[]
    getBytes(T buffer)
    Obtain a copy of the bytes contained within the passed buffer.
    protected abstract void
    in(T buffer, int size, jnr.ffi.Pointer ptr, long ptrAddr)
    Called when the MDB_val should be set to reflect the passed buffer.
    abstract void
    in(T buffer, jnr.ffi.Pointer ptr, long ptrAddr)
    Called when the MDB_val should be set to reflect the passed buffer.
    abstract T
    out(T buffer, jnr.ffi.Pointer ptr, long ptrAddr)
    Called when the MDB_val may have changed and the passed buffer should be modified to reflect the new MDB_val.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MDB_VAL_STRUCT_SIZE

      public static final int MDB_VAL_STRUCT_SIZE
      Size of a MDB_val pointer in bytes.
      See Also:
    • STRUCT_FIELD_OFFSET_DATA

      protected static final int STRUCT_FIELD_OFFSET_DATA
      Offset from a pointer of the MDB_val.mv_data field.
      See Also:
    • STRUCT_FIELD_OFFSET_SIZE

      protected static final int STRUCT_FIELD_OFFSET_SIZE
      Offset from a pointer of the MDB_val.mv_size field.
      See Also:
  • Constructor Details

    • BufferProxy

      public BufferProxy()
  • Method Details

    • allocate

      public abstract T allocate()
      Allocate a new buffer suitable for passing to out(java.lang.Object, jnr.ffi.Pointer, long).
      Returns:
      a buffer for passing to the out method
    • compare

      public abstract int compare(T o1, T o2)
      Compare the two buffers.

      Implemented as a protected method to discourage use of the buffer proxy in collections etc (given by design it wraps a temporary value only).

      Parameters:
      o1 - left operand
      o2 - right operand
      Returns:
      as per Comparable
    • deallocate

      public abstract void deallocate(T buff)
      Deallocate a buffer that was previously provided by allocate().
      Parameters:
      buff - the buffer to deallocate (required)
    • getBytes

      protected abstract byte[] getBytes(T buffer)
      Obtain a copy of the bytes contained within the passed buffer.
      Parameters:
      buffer - a non-null buffer created by this proxy instance
      Returns:
      a copy of the bytes this buffer is currently representing
    • in

      public abstract void in(T buffer, jnr.ffi.Pointer ptr, long ptrAddr)
      Called when the MDB_val should be set to reflect the passed buffer. This buffer will have been created by end users, not allocate().
      Parameters:
      buffer - the buffer to write to MDB_val
      ptr - the pointer to the MDB_val
      ptrAddr - the address of the MDB_val pointer
    • in

      protected abstract void in(T buffer, int size, jnr.ffi.Pointer ptr, long ptrAddr)
      Called when the MDB_val should be set to reflect the passed buffer.
      Parameters:
      buffer - the buffer to write to MDB_val
      size - the buffer size to write to MDB_val
      ptr - the pointer to the MDB_val
      ptrAddr - the address of the MDB_val pointer
    • out

      public abstract T out(T buffer, jnr.ffi.Pointer ptr, long ptrAddr)
      Called when the MDB_val may have changed and the passed buffer should be modified to reflect the new MDB_val.
      Parameters:
      buffer - the buffer to write to MDB_val
      ptr - the pointer to the MDB_val
      ptrAddr - the address of the MDB_val pointer
      Returns:
      the buffer for MDB_val