DBreeze.Scheme.RenameTableInternal C# (CSharp) Method

RenameTableInternal() private method

Renames user table, if it existed.

If there are threads which are working with this table, rename will not be finished and will return false

private RenameTableInternal ( string oldUserTableName, string newUserTableName ) : bool
oldUserTableName string
newUserTableName string
return bool
        private bool RenameTableInternal(string oldUserTableName, string newUserTableName)
        {
            this.DeleteTable(newUserTableName);

            _sync_openTablesHolder.EnterWriteLock();
            try
            {
                string oldTableName = GetUserTableNameAsString(oldUserTableName);
                string newTableName = GetUserTableNameAsString(newUserTableName);

                OpenTable ot = null;

                string alternativeTableLocation = String.Empty;
                bool inMemory = false;

                _openTablesHolder.TryGetValue(oldTableName, out ot);

                if (CheckAlternativeTableLocationsIntersections(oldUserTableName, out alternativeTableLocation))
                {
                    if (alternativeTableLocation == String.Empty)
                    {
                        //In-Memory Table
                        inMemory = true;
                    }
                    else
                    {
                        if (ot != null)
                        {
                            return false;       //Other threads are working with this table

                        }
                    }
                }
                else
                {
                    if (Engine.Configuration.Storage == DBreezeConfiguration.eStorage.MEMORY)
                    {
                        //In-Memory Table
                        inMemory = true;
                    }
                    else
                    {
                        if (ot != null)
                        {
                            return false;       //Other threads are working with this table

                        }
                    }
                }

                //Changing key in Schema db

                byte[] btOldTableName = GetUserTableNameAsByte(oldUserTableName);
                byte[] btNewTableName = GetUserTableNameAsByte(newUserTableName);

                LTrie.ChangeKey(ref btOldTableName, ref btNewTableName);
                LTrie.Commit();

                this.cachedTableNames.Remove(oldTableName);

                if (inMemory && ot != null)
                {
                    //Changing reference for in-memory table,
                    _openTablesHolder.Add(newTableName, ot);
                    _openTablesHolder.Remove(oldTableName);
                }

            }
            catch (System.Exception ex)
            {
                DBreezeException.Throw(DBreezeException.eDBreezeExceptions.SCHEME_TABLE_RENAME_FAILED, oldUserTableName, ex);
            }
            finally
            {
                _sync_openTablesHolder.ExitWriteLock();
            }

            return true;
        }