Exemplo n.º 1
0
 internal Provider(Application parent)
 {
     _id     = Guid.NewGuid();
     _parent = parent;
     _dbLib  = _parent.DbLib;
     _parent = parent;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Renew a read-only transaction.
        /// This acquires a new reader lock for a transaction handle that had been released by mdb_txn_reset().
        /// It must be called before a reset transaction may be used again.
        /// </summary>
        public void Renew()
        {
            var handle = CheckDisposed();
            var ret    = DbLib.mdb_txn_renew(handle);

            ErrorUtil.CheckRetCode(ret);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Commit all the operations of a transaction into the database.
        /// The transaction handle is freed. It and its cursors must not be used again after this call, except with mdb_cursor_renew().
        /// Note: Earlier documentation incorrectly said all cursors would be freed. Only write-transactions free cursors.
        /// </summary>
        public void Commit()
        {
            var ret = DbRetCode.SUCCESS;
            // we check here, as we dont want to throw an exception in the CER, but won't use this handle.
            var handle = CheckDisposed();
            var txnId  = IntPtr.Zero;

            RuntimeHelpers.PrepareConstrainedRegions();
            try { /* */ }
            finally {
                // now we use atomic access to the handle
                handle = Interlocked.CompareExchange(ref txn, IntPtr.Zero, txn);
                // if the txn handle was valid before we cleared it, lets close the handle
                if (handle != IntPtr.Zero)
                {
                    txnId = DbLib.mdb_txn_id(handle);
                    ret   = DbLib.mdb_txn_commit(handle);
                }
            }

            if (handle != IntPtr.Zero)
            {
                // weather the call succeeded or not, the transaction cannot be re-used.
                ReleaseManagedResources(true);
                disposed?.Invoke(txnId);

                ErrorUtil.CheckRetCode(ret);
                Committed();
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Set the size of the memory map to use for this environment.
 /// The size should be a multiple of the OS page size. The default is 10485760 bytes. The size of the memory map
 /// is also the maximum size of the database. The value should be chosen as large as possible, to accommodate
 /// future growth of the database. This function should be called after mdb_env_create() and before mdb_env_open().
 /// It may be called at later times if no transactions are active in this process.
 /// Note that the library does not check for this condition, the caller must ensure it explicitly.
 /// </summary>
 /// <remarks>
 /// The new size takes effect immediately for the current process but will not be persisted to any others
 /// until a write transaction has been committed by the current process. Also, only mapsize increases are persisted
 /// into the environment.
 /// If the mapsize is increased by another process, and data has grown beyond the range of the current mapsize,
 /// mdb_txn_begin() will return MDB_MAP_RESIZED. This function may be called with a size of zero to adopt the new size.
 /// Any attempt to set a size smaller than the space already consumed by the environment will be silently changed
 /// to the current size of the used space.
 /// Note: the current MapSize can be obtained by calling GetEnvInfo().
 /// </remarks>
 /// <param name="newValue"></param>
 public void SetMapSize(long newValue)
 {
     if (autoReduceMapSizeIn32BitProcess && (IntPtr.Size == 4) && (newValue > int.MaxValue))
     {
         newValue = int.MaxValue;
     }
     RunChecked((handle) => DbLib.mdb_env_set_mapsize(handle, (IntPtr)newValue));
 }
Exemplo n.º 5
0
        internal void Load()
        {
            DbLib dbLib = new DbLib();

            DataTable dataTable = dbLib.SessionGet(_id);

            Load(dataTable.Rows[0]);
        }
Exemplo n.º 6
0
 internal Appointment(Application parent, Patient patient, Referrer referrer, Provider provider, ClinicType clinicType)
 {
     _parent          = parent;
     _dbLib           = _parent.DbLib;
     _ubrn            = _parent.GetMaxUBRN();
     _patient         = patient;
     _referrer        = referrer;
     _provider        = provider;
     _clinicType      = clinicType;
     _createdDateTime = DateTime.Now;
     _status          = AppointmentStatus.Pending;
 }
Exemplo n.º 7
0
        /// <summary>
        /// Implementation of Dispose() pattern. See <see cref="Dispose()"/>.
        /// </summary>
        /// <param name="disposing"><c>true</c> if explicity disposing (finalizer not run), <c>false</c> if disposed from finalizer.</param>
        protected virtual void Dispose(bool disposing)
        {
            var handle = Interlocked.Exchange(ref txn, IntPtr.Zero);

            // if the txn handle was valid before we cleared it, lets close the handle
            if (handle != IntPtr.Zero)
            {
                var txnId = DbLib.mdb_txn_id(handle);
                DbLib.mdb_txn_abort(handle);
                ReleaseManagedResources();
                disposed?.Invoke(txnId);
            }
        }
Exemplo n.º 8
0
 public static void CheckRetCode(DbRetCode ret)
 {
     if (ret != DbRetCode.SUCCESS)
     {
         string errStr;
         if (ret > MdbLowError && ret <= DbRetCode.LAST_ERRCODE)
         {
             errStr = DbLib.mdb_strerror(ret);
         }
         else
         {
             errStr = DotNetStr(ret);
         }
         throw new LmdbException(ret, errStr);
     }
 }
Exemplo n.º 9
0
        /// <summary>Constructor.</summary>
        /// <param name="config">Configuration to use.</param>
        public LmdbEnvironment(LmdbEnvironmentConfiguration config = null)
        {
            // so that we can refer back to the Environment instance
            instanceHandle = GCHandle.Alloc(this, GCHandleType.WeakTrackResurrection);

            DbRetCode ret;

            RuntimeHelpers.PrepareConstrainedRegions();
            try { /* */ }
            finally {
                IntPtr envHandle;
                ret = DbLib.mdb_env_create(out envHandle);
                if (ret == DbRetCode.SUCCESS)
                {
                    var ret2 = DbLib.mdb_env_set_userctx(envHandle, (IntPtr)instanceHandle);
                    if (ret2 == DbRetCode.SUCCESS)
                    {
                        this.env = envHandle;
                    }
                    else
                    {
                        ret = ret2;
                        DbLib.mdb_env_close(envHandle);
                    }
                }
            }
            ErrorUtil.CheckRetCode(ret);

            if (config != null)
            {
                this.autoReduceMapSizeIn32BitProcess = config.AutoReduceMapSizeIn32BitProcess;
                if (config.MapSize.HasValue)
                {
                    this.SetMapSize(config.MapSize.Value);
                }
                if (config.MaxDatabases.HasValue)
                {
                    this.MaxDatabases = config.MaxDatabases.Value;
                }
                if (config.MaxReaders.HasValue)
                {
                    this.MaxReaders = config.MaxReaders.Value;
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Commit all the operations of a transaction into the database.
        /// The transaction handle is freed. It and its cursors must not be used again after this call, except with mdb_cursor_renew().
        /// Note: Earlier documentation incorrectly said all cursors would be freed. Only write-transactions free cursors.
        /// </summary>
        public void Commit()
        {
            // we check here, as we dont want to throw an exception later, but won't use this handle.
            var currentHandle = CheckDisposed();

            // now we use atomic access to the handle
            var handle = Interlocked.Exchange(ref txn, IntPtr.Zero);

            // if the txn handle was valid before we cleared it, lets close the handle
            if (handle != IntPtr.Zero)
            {
                var txnId = DbLib.mdb_txn_id(handle);
                var ret   = DbLib.mdb_txn_commit(handle);
                // whether the call succeeded or not, the transaction cannot be re-used.
                ReleaseManagedResources(true);
                disposed?.Invoke(txnId);

                ErrorUtil.CheckRetCode(ret);
                Committed();
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Implementation of Dispose() pattern. See <see cref="Dispose()"/>.
        /// </summary>
        /// <param name="disposing"><c>true</c> if explicity disposing (finalizer not run), <c>false</c> if disposed from finalizer.</param>
        protected virtual void Dispose(bool disposing)
        {
            IntPtr handle = IntPtr.Zero;
            IntPtr txnId  = IntPtr.Zero;

            RuntimeHelpers.PrepareConstrainedRegions();
            try { /* */ }
            finally {
                handle = Interlocked.CompareExchange(ref txn, IntPtr.Zero, txn);
                // if the txn handle was valid before we cleared it, lets close the handle
                if (handle != IntPtr.Zero)
                {
                    txnId = DbLib.mdb_txn_id(handle);
                    DbLib.mdb_txn_abort(handle);
                }
            }

            if (handle != IntPtr.Zero)
            {
                ReleaseManagedResources();
                disposed?.Invoke(txnId);
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Reset a read-only transaction.
        /// Abort the transaction like mdb_txn_abort(), but keep the transaction handle. mdb_txn_renew() may reuse the handle.
        /// This saves allocation overhead if the process will start a new read-only transaction soon, and also locking overhead
        /// if MDB_NOTLS is in use.The reader table lock is released, but the table slot stays tied to its thread or MDB_txn.
        /// Use mdb_txn_abort() to discard a reset handle, and to free its lock table slot if MDB_NOTLS is in use.
        /// Cursors opened within the transaction must not be used again after this call, except with mdb_cursor_renew().
        /// Reader locks generally don't interfere with writers, but they keep old versions of database pages allocated.
        /// Thus they prevent the old pages from being reused when writers commit new data, and so under heavy load
        /// the database size may grow much more rapidly than otherwise.
        /// </summary>
        public void Reset()
        {
            var handle = CheckDisposed();

            DbLib.mdb_txn_reset(handle);
        }
Exemplo n.º 13
0
 private Application()
 {
     _dbLib = new DbLib();
 }
Exemplo n.º 14
0
 internal Appointment(Application parent, DataRow dataRow)
 {
     _parent = parent;
     _dbLib  = _parent.DbLib;
     Load(dataRow);
 }
Exemplo n.º 15
0
 private Application(Session session)
 {
     _dbLib   = new DbLib();
     _session = session;
 }
Exemplo n.º 16
0
 internal Provider(Application parent, DataRow dataRow)
 {
     _parent = parent;
     _dbLib  = _parent.DbLib;
     this.Load(dataRow);
 }
Exemplo n.º 17
0
 internal Referrer(Application parent)
 {
     _id     = Guid.NewGuid();
     _parent = parent;
     _dbLib  = _parent.DbLib;
 }
Exemplo n.º 18
0
        /// <summary>
        /// Retrieve the multi-value options for the database.
        /// </summary>
        public MultiValueDatabaseOptions GetMultiValueOptions(Transaction transaction)
        {
            uint opts = GetChecked((uint handle, out uint value) => DbLib.mdb_dbi_flags(transaction.Handle, handle, out value));

            return(unchecked ((MultiValueDatabaseOptions)opts));
        }
Exemplo n.º 19
0
 internal Referrer(Application parent, DataRow dataRow)
 {
     _parent = parent;
     _dbLib  = _parent.DbLib;
     Load(dataRow);
 }
Exemplo n.º 20
0
 internal Slot(Application parent)
 {
     _id     = Guid.NewGuid();
     _parent = parent;
     _dbLib  = _parent.DbLib;
 }