Exemplo n.º 1
0
        //internal bool IfWriteThread()
        //{
        //    return (_masterTrie.NestedTablesCoordinator.ModificationThreadId == System.Threading.Thread.CurrentThread.ManagedThreadId);
        //}


        internal NestedTable GetTable <TKey>(TKey key, uint tableIndex, bool insertIsAllowed)
        {
            byte[]   btKey = DataTypesConvertor.ConvertKey <TKey>(key);
            LTrieRow row   = null;

            if (insertIsAllowed)        //Insert of table is allowed by calls generation
            {
                row = table.GetKey(ref btKey, null);
                return(table.GetTable(row, ref btKey, tableIndex, this._masterTrie, true, false));
            }

            //Only selects are allowed

            if (_masterTrie.NestedTablesCoordinator.ModificationThreadId == System.Threading.Thread.CurrentThread.ManagedThreadId)
            {
                //This thread must NOT use cache
                row = table.GetKey(ref btKey, null);
                return(table.GetTable(row, ref btKey, tableIndex, this._masterTrie, false, false));
            }
            else
            {
                LTrieRootNode readRootNode = new LTrieRootNode(table);
                row = table.GetKey(ref btKey, readRootNode);

                return(table.GetTable(row, ref btKey, tableIndex, this._masterTrie, false, true));
            }
        }
Exemplo n.º 2
0
        private void ReadUserLastFileNumber()
        {
            byte[]   btKeyName = Encoding.UTF8.GetBytes(LastFileNumberKeyName);
            LTrieRow row       = LTrie.GetKey(btKeyName, false, false);

            if (row.Exists)
            {
                byte[] fullValue = row.GetFullValue(true);
                LastFileNumber = fullValue.To_UInt64_BigEndian();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Insert resource
        /// </summary>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="resourceName"></param>
        /// <param name="resourceObject"></param>
        /// <param name="resourceSettings">resource extra behaviour</param>
        public void Insert <TValue>(string resourceName, TValue resourceObject, Settings resourceSettings = null)
        {
            if (String.IsNullOrEmpty(resourceName))
            {
                return;
            }

            if (resourceSettings == null)
            {
                resourceSettings = _defaultSetting;
            }

            string rn = _urp + resourceName;

            byte[] btKey   = DataTypesConvertor.ConvertKey <string>(rn);
            byte[] btValue = DataTypesConvertor.ConvertValue <TValue>(resourceObject);

            _sync.EnterWriteLock();
            try
            {
                //------- Verification, to prevent storing of the identical value
                if (resourceSettings.InsertWithVerification)
                {
                    byte[] btExVal = null;
                    if (_d.TryGetValue(rn, out btExVal))
                    {
                        if (btExVal._ByteArrayEquals(btValue))
                        {
                            return;
                        }
                    }
                    else
                    {
                        //Grabbing from disk
                        if (resourceSettings.HoldOnDisk)
                        {
                            var row = LTrie.GetKey(btKey, false, false);
                            if (row.Exists)
                            {
                                btExVal = row.GetFullValue(false);
                                if (btExVal._ByteArrayEquals(btValue))
                                {
                                    if (resourceSettings.HoldInMemory)
                                    {
                                        _d[rn] = btValue;
                                    }

                                    return;
                                }
                            }
                        }
                    }
                }
                //-------


                if (resourceSettings.HoldOnDisk)
                {
                    bool cov = LTrie.OverWriteIsAllowed;
                    if (resourceSettings.FastUpdates)
                    {
                        LTrie.OverWriteIsAllowed = false;
                    }

                    LTrie.Add(btKey, btValue);
                    LTrie.Commit();

                    if (resourceSettings.FastUpdates)
                    {
                        LTrie.OverWriteIsAllowed = cov;
                    }
                }

                if (resourceSettings.HoldInMemory)
                {
                    _d[rn] = btValue;
                }
            }
            catch (Exception ex)
            {
                throw DBreezeException.Throw(DBreezeException.eDBreezeExceptions.DBREEZE_RESOURCES_CONCERNING, "in Insert", ex);
            }
            finally
            {
                _sync.ExitWriteLock();
            }


            #region "remark"
            //            if (holdInMemory)
            //            {
            //                _sync.EnterWriteLock();
            //                try
            //                {
            //                    _d[resourceName] = btValue;
            //                }
            //                catch (Exception ex)
            //                {
            //                    throw ex;
            //                }
            //                finally
            //                {
            //                    _sync.ExitWriteLock();
            //                }
            //            }

            //            Action a = () =>
            //            {

            //                _sync.EnterWriteLock();
            //                try
            //                {
            //                    LTrie.Add(btKey, btValue);
            //                    LTrie.Commit();
            //                }
            //                catch (Exception ex)
            //                {
            //                    throw ex;
            //                }
            //                finally
            //                {
            //                    _sync.ExitWriteLock();
            //                }
            //            };

            //#if NET35 || NETr40   //The same must be use for .NET 4.0

            //            new System.Threading.Thread(new System.Threading.ThreadStart(() =>
            //            {
            //                a();
            //            })).Start();
            //#else
            //            System.Threading.Tasks.Task.Run(() => {
            //                a();
            //            });
            //#endif
            #endregion
        }