コード例 #1
0
        //TODO: tests
        /// <summary>
        /// Renew a cursor handle.
        /// Cursors are associated with a specific transaction and database and may not span threads.
        /// Cursors that are only used in read-only transactions may be re-used, to avoid unnecessary malloc/free overhead.
        /// The cursor may be associated with a new read-only transaction, and referencing the same database handle as it was created with.
        /// </summary>
        /// <param name="txn">Transaction to renew in.</param>
        public void Renew(LMDBTransaction txn)
        {
            if (txn == null)
            {
                throw new ArgumentNullException(nameof(txn));
            }

            if (!txn.IsReadOnly)
            {
                throw new InvalidOperationException("Can't renew cursor on non-readonly transaction");
            }

            Lmdb.mdb_cursor_renew(txn.Handle(), _handle);
        }
コード例 #2
0
        /// <summary>
        /// Creates new instance of LMDBCursor
        /// </summary>
        /// <param name="db">Database</param>
        /// <param name="txn">Transaction</param>
        internal LMDBCursor(LMDBDatabase db, LMDBTransaction txn)
        {
            if (db == null)
            {
                throw new ArgumentNullException(nameof(db));
            }

            if (txn == null)
            {
                throw new ArgumentNullException(nameof(txn));
            }

            Lmdb.mdb_cursor_open(txn.Handle(), db.Handle(), out _handle);

            Transaction            = txn;
            Transaction.Disposing += Dispose;
        }
コード例 #3
0
        /// <summary>
        /// Creates a LMDBDatabase instance.
        /// </summary>
        /// <param name="name">Database name.</param>
        /// <param name="transaction">Active transaction.</param>
        /// <param name="configuration">Options for the database, like encoding, option flags, and comparison logic.</param>
        internal LMDBDatabase(string name, LMDBTransaction transaction, DatabaseConfiguration configuration)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException(nameof(transaction));
            }

            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            Name                   = name;
            _configuration         = configuration;
            Environment            = transaction.Environment;
            Environment.Disposing += Dispose;
            Lmdb.mdb_dbi_open(transaction.Handle(), name, _configuration.Flags, out _handle);
            _pinnedConfig = _configuration.ConfigureDatabase(transaction, this);
            IsOpened      = true;
        }
コード例 #4
0
        /// <summary>
        /// Created new instance of LMDBTransaction
        /// </summary>
        /// <param name="environment">Environment.</param>
        /// <param name="parent">Parent transaction or null.</param>
        /// <param name="flags">Transaction open options.</param>
        internal LMDBTransaction(LMDBEnvironment environment, LMDBTransaction parent, TransactionBeginFlags flags)
        {
            if (environment == null)
            {
                throw new ArgumentNullException(nameof(environment));
            }

            Environment            = environment;
            ParentTransaction      = parent;
            IsReadOnly             = (flags & TransactionBeginFlags.ReadOnly) == TransactionBeginFlags.ReadOnly;
            State                  = TransactionState.Active;
            Environment.Disposing += Dispose;
            if (parent != null)
            {
                parent.Disposing     += Dispose;
                parent.StateChanging += OnParentStateChanging;
            }

            var parentHandle = parent?.Handle() ?? IntPtr.Zero;

            Lmdb.mdb_txn_begin(environment.Handle(), parentHandle, flags, out _handle);
            _originalHandle = _handle;
        }
コード例 #5
0
 /// <summary>
 /// Truncates all data from the database.
 /// </summary>
 public void Truncate(LMDBTransaction transaction)
 {
     Lmdb.mdb_drop(transaction.Handle(), _handle, false);
 }
コード例 #6
0
 /// <summary>
 /// Drops the database.
 /// </summary>
 public void Drop(LMDBTransaction transaction)
 {
     Lmdb.mdb_drop(transaction.Handle(), _handle, true);
     IsOpened = false;
     _handle  = default(uint);
 }