/// <summary> /// Loads the System Defaults into the cached Typed DataTable. /// /// The System Defaults are retrieved from the s_system_defaults table and are /// put into a Typed DataTable that has the structure of this table. /// /// </summary> /// <returns>void</returns> private void LoadSystemDefaultsTable() { TDataBase DBAccessObj = DBAccess.Connect("LoadSystemDefaultsTable", FDataBase); TDBTransaction ReadTransaction = new TDBTransaction(); if (FSystemDefaultsDT != null) { FSystemDefaultsDT.Clear(); } DBAccessObj.ReadTransaction(ref ReadTransaction, delegate { FSystemDefaultsDT = SSystemDefaultsAccess.LoadAll(ReadTransaction); }); if (FDataBase == null) { DBAccessObj.CloseDBConnection(); } }
/// <summary> /// Loads the System Defaults into the cached Typed DataTable. /// /// The System Defaults are retrieved from the s_system_defaults table and are /// put into a Typed DataTable that has the structure of this table. /// /// </summary> /// <returns>void</returns> private void LoadSystemDefaultsTable() { TDataBase DBAccessObj = new Ict.Common.DB.TDataBase(); TDBTransaction ReadTransaction = null; // Prevent other threads from obtaining a read lock on the cache table while we are (re)loading the cache table! FReadWriteLock.AcquireWriterLock(SharedConstants.THREADING_WAIT_INFINITE); try { if (FSystemDefaultsDT != null) { FSystemDefaultsDT.Clear(); } try { DBAccessObj.EstablishDBConnection(TSrvSetting.RDMBSType, TSrvSetting.PostgreSQLServer, TSrvSetting.PostgreSQLServerPort, TSrvSetting.PostgreSQLDatabaseName, TSrvSetting.DBUsername, TSrvSetting.DBPassword, "", "SystemDefaultsCache DB Connection"); DBAccessObj.BeginAutoReadTransaction(IsolationLevel.RepeatableRead, ref ReadTransaction, delegate { FSystemDefaultsDT = SSystemDefaultsAccess.LoadAll(ReadTransaction); }); } finally { DBAccessObj.CloseDBConnection(); } // Thread.Sleep(5000); uncomment this for debugging. This allows checking whether read access to FSystemDefaultsDT actually waits until we release the WriterLock in the finally block. } finally { // Other threads are now free to obtain a read lock on the cache table. FReadWriteLock.ReleaseWriterLock(); } }
/// <summary> /// Loads the System Defaults into the cached Typed DataTable. /// /// The System Defaults are retrieved from the s_system_defaults table and are /// put into a Typed DataTable that has the structure of this table. /// /// </summary> /// <returns>void</returns> private void LoadSystemDefaultsTable() { TDBTransaction ReadTransaction; Boolean NewTransaction = false; // Prevent other threads from obtaining a read lock on the cache table while we are (re)loading the cache table! FReadWriteLock.AcquireWriterLock(SharedConstants.THREADING_WAIT_INFINITE); try { if (FSystemDefaultsDT != null) { FSystemDefaultsDT.Clear(); } try { ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.RepeatableRead, TEnforceIsolationLevel.eilMinimum, out NewTransaction); FSystemDefaultsDT = SSystemDefaultsAccess.LoadAll(ReadTransaction); } finally { if (NewTransaction) { DBAccess.GDBAccessObj.CommitTransaction(); TLogging.LogAtLevel(7, "TSystemDefaultsCache.LoadSystemDefaultsTable: commited own transaction."); } } // Thread.Sleep(5000); uncomment this for debugging. This allows checking whether read access to FSystemDefaultsDT actually waits until we release the WriterLock in the finally block. } finally { // Other threads are now free to obtain a read lock on the cache table. FReadWriteLock.ReleaseWriterLock(); } }