/// <summary> /// Renames user table, if it existed. /// <para>If there are threads which are working with this table, rename will not be finished and will return false</para> /// </summary> /// <param name="oldUserTableName"></param> /// <param name="newUserTableName"></param> /// <returns>true if successfully renamed, otherwise false</returns> 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); }