public DelayTable GetTable(string strDatabaseName, string strTableName) { if (this.m_lock.TryEnterWriteLock(this.m_nLockTimeout) == false) { throw new ApplicationException("为 DelayTableCollection 加写锁时失败。Timeout=" + this.m_nLockTimeout.ToString()); } try { string strName = strDatabaseName + "." + strTableName; DelayTable table = (DelayTable)name_table[strName]; if (table == null) { table = new DelayTable(); table.DatabaseName = strDatabaseName; table.TableName = strTableName; name_table[strName] = table; } return(table); } finally { this.m_lock.ExitWriteLock(); } }
public List <DelayTable> GetTables(string strDatabaseName) { if (this.m_lock.TryEnterReadLock(this.m_nLockTimeout) == false) { throw new ApplicationException("为 DelayTableCollection 加读锁时失败。Timeout=" + this.m_nLockTimeout.ToString()); } try { List <DelayTable> results = new List <DelayTable>(); foreach (string key in this.name_table.Keys) { DelayTable table = (DelayTable)name_table[key]; if (table.DatabaseName == strDatabaseName) { results.Add(table); } } return(results); } finally { this.m_lock.ExitReadLock(); } }
public void Remove(DelayTable table) { if (this.m_lock.TryEnterWriteLock(this.m_nLockTimeout) == false) throw new ApplicationException("为 DelayTableCollection 加写锁时失败。Timeout=" + this.m_nLockTimeout.ToString()); try { foreach (string key in this.name_table.Keys) { DelayTable current = (DelayTable)name_table[key]; if (current == table) { this.name_table.Remove(key); return; } } } finally { this.m_lock.ExitWriteLock(); } }
public void Remove(DelayTable table) { if (this.m_lock.TryEnterWriteLock(this.m_nLockTimeout) == false) { throw new ApplicationException("为 DelayTableCollection 加写锁时失败。Timeout=" + this.m_nLockTimeout.ToString()); } try { foreach (string key in this.name_table.Keys) { DelayTable current = (DelayTable)name_table[key]; if (current == table) { this.name_table.Remove(key); return; } } } finally { this.m_lock.ExitWriteLock(); } }
public void Free() { if (this.m_lock.TryEnterWriteLock(this.m_nLockTimeout) == false) { throw new ApplicationException("为 DelayTableCollection 加写锁时失败。Timeout=" + this.m_nLockTimeout.ToString()); } try { foreach (string key in this.name_table.Keys) { DelayTable table = (DelayTable)this.name_table[key]; if (table != null) { table.Free(); } } this.name_table.Clear(); } finally { this.m_lock.ExitWriteLock(); } }
public DelayTable GetTable(string strDatabaseName, string strTableName) { if (this.m_lock.TryEnterWriteLock(this.m_nLockTimeout) == false) throw new ApplicationException("为 DelayTableCollection 加写锁时失败。Timeout=" + this.m_nLockTimeout.ToString()); try { string strName = strDatabaseName + "." + strTableName; DelayTable table = (DelayTable)name_table[strName]; if (table == null) { table = new DelayTable(); table.DatabaseName = strDatabaseName; table.TableName = strTableName; name_table[strName] = table; } return table; } finally { this.m_lock.ExitWriteLock(); } }
// return: // -1 出错 // 0 成功 public int Write( string strDatabaseName, KeyCollection keys, delegate_getfilename getfilename, out string strError) { strError = ""; // 确保 keys 里面的事项是排序过的。如果没有排序,本函数也能工作,只是效率略低 DelayTable table = null; KeyCollection part_keys = new KeyCollection(); foreach (KeyItem item in keys) { if (table == null) { table = GetTable(strDatabaseName, item.SqlTableName); if (string.IsNullOrEmpty(table.FileName) == true) { string strFilename = getfilename(strDatabaseName, item.SqlTableName); int nRet = table.Create(strFilename, out strError); if (nRet == -1) { return(-1); } } } else { if (table.TableName != item.SqlTableName) { if (part_keys.Count > 0) { table.Write(part_keys); part_keys.Clear(); } table = GetTable(strDatabaseName, item.SqlTableName); if (string.IsNullOrEmpty(table.FileName) == true) { string strFilename = getfilename(strDatabaseName, item.SqlTableName); int nRet = table.Create(strFilename, out strError); if (nRet == -1) { return(-1); } } } } part_keys.Add(item); } if (part_keys.Count > 0) { Debug.Assert(table != null, ""); table.Write(part_keys); part_keys.Clear(); } return(0); }