public static SSystemDefaultsTable GetSystemDefaults() { SSystemDefaultsTable ReturnValue = null; TDBTransaction ReadTransaction = null; bool DBAccessCallSuccessful = false; DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction( IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, ref ReadTransaction, delegate { TServerBusyHelper.CoordinatedAutoRetryCall("Loading all SystemDefaults", ref DBAccessCallSuccessful, delegate { ReturnValue = SSystemDefaultsAccess.LoadAll(ReadTransaction); DBAccessCallSuccessful = true; }); }); if (!DBAccessCallSuccessful) { throw new EDBAccessLackingCoordinationException("Loading of System Default failed: server was too busy!"); } return(ReturnValue); }
/// <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() { 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() { 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(); } }
public static SSystemDefaultsTable GetSystemDefaults() { SSystemDefaultsTable Ret; TDBTransaction ReadTransaction; Boolean NewTransaction = false; try { ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, out NewTransaction); Ret = SSystemDefaultsAccess.LoadAll(ReadTransaction); } finally { if (NewTransaction) { DBAccess.GDBAccessObj.RollbackTransaction(); } } return(Ret); }
public static void GetData(string ATablename, TSearchCriteria[] ASearchCriteria, out TTypedDataTable AResultTable, TDBTransaction AReadTransaction) { AResultTable = null; string context = string.Format("GetData {0}", SharedConstants.MODULE_ACCESS_MANAGER); // check access permissions for the current user TModuleAccessManager.CheckUserPermissionsForTable(ATablename, TTablePermissionEnum.eCanRead); // TODO: auto generate if (ATablename == AApSupplierTable.GetTableDBName()) { AResultTable = AApSupplierAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } else if (ATablename == AApDocumentTable.GetTableDBName()) { AResultTable = AApDocumentAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } else if (ATablename == ATransactionTypeTable.GetTableDBName()) { AResultTable = ATransactionTypeAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } else if (ATablename == ACurrencyTable.GetTableDBName()) { AResultTable = ACurrencyAccess.LoadAll(AReadTransaction); } else if (ATablename == ADailyExchangeRateTable.GetTableDBName()) { AResultTable = ADailyExchangeRateAccess.LoadAll(AReadTransaction); } else if (ATablename == ACorporateExchangeRateTable.GetTableDBName()) { AResultTable = ACorporateExchangeRateAccess.LoadAll(AReadTransaction); } else if (ATablename == ACurrencyLanguageTable.GetTableDBName()) { AResultTable = ACurrencyLanguageAccess.LoadAll(AReadTransaction); } else if (ATablename == AFeesPayableTable.GetTableDBName()) { AResultTable = AFeesPayableAccess.LoadAll(AReadTransaction); } else if (ATablename == AFeesReceivableTable.GetTableDBName()) { AResultTable = AFeesReceivableAccess.LoadAll(AReadTransaction); } else if (ATablename == AAnalysisTypeTable.GetTableDBName()) { AResultTable = AAnalysisTypeAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } else if (ATablename == AGiftBatchTable.GetTableDBName()) { AResultTable = AGiftBatchAccess.LoadAll(AReadTransaction); } else if (ATablename == AJournalTable.GetTableDBName()) { AResultTable = AJournalAccess.LoadAll(AReadTransaction); } else if (ATablename == ALedgerTable.GetTableDBName()) { AResultTable = ALedgerAccess.LoadAll(AReadTransaction); } else if (ATablename == MExtractMasterTable.GetTableDBName()) { if (ASearchCriteria == null) { AResultTable = MExtractMasterAccess.LoadAll(AReadTransaction); } else { AResultTable = MExtractMasterAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } } else if (ATablename == MExtractTable.GetTableDBName()) { // it does not make sense to load ALL extract rows for all extract masters so search criteria needs to be set if (ASearchCriteria != null) { AResultTable = MExtractAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } } else if (ATablename == PcAttendeeTable.GetTableDBName()) { AResultTable = PcAttendeeAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } else if (ATablename == PcConferenceCostTable.GetTableDBName()) { AResultTable = PcConferenceCostAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } else if (ATablename == PcEarlyLateTable.GetTableDBName()) { AResultTable = PcEarlyLateAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } else if (ATablename == PcSupplementTable.GetTableDBName()) { AResultTable = PcSupplementAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } else if (ATablename == PcDiscountTable.GetTableDBName()) { AResultTable = PcDiscountAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } else if (ATablename == PCountryTable.GetTableDBName()) { AResultTable = PCountryAccess.LoadAll(AReadTransaction); } else if (ATablename == PFormTable.GetTableDBName()) { string[] columns = TTypedDataTable.GetColumnStringList(PFormTable.TableId); StringCollection fieldList = new StringCollection(); for (int i = 0; i < columns.Length; i++) { // Do not load the template document - we don't display it and it is big! if (columns[i] != PFormTable.GetTemplateDocumentDBName()) { fieldList.Add(columns[i]); } } AResultTable = PFormAccess.LoadAll(fieldList, AReadTransaction); } else if (ATablename == PInternationalPostalTypeTable.GetTableDBName()) { AResultTable = PInternationalPostalTypeAccess.LoadAll(AReadTransaction); } else if (ATablename == PtApplicationTypeTable.GetTableDBName()) { AResultTable = PtApplicationTypeAccess.LoadAll(AReadTransaction); } else if (ATablename == PFormalityTable.GetTableDBName()) { AResultTable = PFormalityAccess.LoadAll(AReadTransaction); } else if (ATablename == PMailingTable.GetTableDBName()) { AResultTable = PMailingAccess.LoadAll(AReadTransaction); } else if (ATablename == PPartnerGiftDestinationTable.GetTableDBName()) { AResultTable = PPartnerGiftDestinationAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } else if (ATablename == PmDocumentTypeTable.GetTableDBName()) { AResultTable = PmDocumentTypeAccess.LoadAll(AReadTransaction); } else if (ATablename == SGroupTable.GetTableDBName()) { TSecurityChecks.CheckUserModulePermissions(SharedConstants.PETRAMODULE_SYSADMIN, context); AResultTable = SGroupAccess.LoadAll(AReadTransaction); } else if (ATablename == SSystemDefaultsTable.GetTableDBName()) { TSecurityChecks.CheckUserModulePermissions(SharedConstants.PETRAMODULE_SYSADMIN, context); AResultTable = SSystemDefaultsAccess.LoadAll(AReadTransaction); } else if (ATablename == SSystemDefaultsGuiTable.GetTableDBName()) { AResultTable = SSystemDefaultsGuiAccess.LoadAll(AReadTransaction); } else { throw new Exception("TCommonDataReader.GetData: unknown table " + ATablename); } // Accept row changes here so that the Client gets 'unmodified' rows AResultTable.AcceptChanges(); }
/// <summary> /// Stores a System Default in the DB. If it was already there it gets updated, if it wasn't there it gets added. /// </summary> /// <remarks>The change gets reflected in the System Defaults Cache the next time the System Defaults Cache /// gets accessed.</remarks> /// <param name="AKey">Name of the System Default.</param> /// <param name="AValue">Value of the System Default.</param> /// <param name="AAdded">True if the System Default got added, false if it already existed.</param> /// <remarks>SystemDefault Names are not case sensitive.</remarks> public void SetSystemDefault(String AKey, String AValue, out bool AAdded) { Boolean NewTransaction = false; Boolean ShouldCommit = false; SSystemDefaultsTable SystemDefaultsDT; try { TDBTransaction ReadWriteTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction( IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, out NewTransaction); SystemDefaultsDT = SSystemDefaultsAccess.LoadAll(ReadWriteTransaction); // This will find the row that matches a case-insensitive search of the table primary keys SystemDefaultsDT.CaseSensitive = false; // It is anyway SSystemDefaultsRow match = (SSystemDefaultsRow)SystemDefaultsDT.Rows.Find(AKey); if (match != null) { // I already have this System Default in the DB --> simply update the Value in the DB. // (This will often be the case!) match.DefaultValue = AValue; AAdded = false; } else { // The System Default isn't in the DB yet --> store it in the DB. var SystemDefaultsDR = SystemDefaultsDT.NewRowTyped(true); SystemDefaultsDR.DefaultCode = AKey; SystemDefaultsDR.DefaultDescription = "Created in OpenPetra"; SystemDefaultsDR.DefaultValue = AValue; SystemDefaultsDT.Rows.Add(SystemDefaultsDR); AAdded = true; } SSystemDefaultsAccess.SubmitChanges(SystemDefaultsDT, ReadWriteTransaction); ShouldCommit = true; } catch (Exception Exc) { TLogging.Log( "TSystemDefaultCache.SetSystemDefault: An Exception occured during the saving of the System Default '" + AKey + "'. Value to be saved: + '" + AValue + "'" + Environment.NewLine + Exc.ToString()); ShouldCommit = false; throw; } finally { if (NewTransaction) { if (ShouldCommit) { DBAccess.GDBAccessObj.CommitTransaction(); // We need to ensure that the next time the System Defaults Caches gets accessed it is refreshed from the DB!!! // Obtain thread-safe access to the FTableCached Field to prevent two (or more) Threads from getting a different // FTableCached value! lock (FTableCachedLockCookie) { FTableCached = false; } } else { DBAccess.GDBAccessObj.RollbackTransaction(); } } } }
/// <summary> /// Stores a System Default in the DB. If it was already there it gets updated, if it wasn't there it gets added. /// </summary> /// <remarks>The change gets reflected in the System Defaults Cache the next time the System Defaults Cache /// gets accessed.</remarks> /// <param name="AKey">Name of the System Default.</param> /// <param name="AValue">Value of the System Default.</param> /// <param name="AAdded">True if the System Default got added, false if it already existed.</param> /// <remarks>SystemDefault Names are not case sensitive.</remarks> public void SetSystemDefault(String AKey, String AValue, out bool AAdded) { TDataBase DBConnectionObj = null; TDBTransaction WriteTransaction = null; Boolean SubmissionOK = false; SSystemDefaultsTable SystemDefaultsDT; Boolean Added = false; try { // Open a separate DB Connection... DBConnectionObj = DBAccess.SimpleEstablishDBConnection("SetSystemDefault"); // ...and start a DB Transaction on that separate DB Connection DBConnectionObj.BeginAutoTransaction(IsolationLevel.ReadCommitted, ref WriteTransaction, ref SubmissionOK, "SetSystemDefault", delegate { SystemDefaultsDT = SSystemDefaultsAccess.LoadAll(WriteTransaction); // This will find the row that matches a case-insensitive search of the table primary keys SystemDefaultsDT.CaseSensitive = false; // It is anyway SSystemDefaultsRow match = (SSystemDefaultsRow)SystemDefaultsDT.Rows.Find(AKey); if (match != null) { // I already have this System Default in the DB --> simply update the Value in the DB. // (This will often be the case!) match.DefaultValue = AValue; Added = false; } else { // The System Default isn't in the DB yet --> store it in the DB. var SystemDefaultsDR = SystemDefaultsDT.NewRowTyped(true); SystemDefaultsDR.DefaultCode = AKey; SystemDefaultsDR.DefaultDescription = "Created in OpenPetra"; SystemDefaultsDR.DefaultValue = AValue; SystemDefaultsDT.Rows.Add(SystemDefaultsDR); Added = true; } SSystemDefaultsAccess.SubmitChanges(SystemDefaultsDT, WriteTransaction); SubmissionOK = true; }); AAdded = Added; } catch (Exception Exc) { TLogging.Log( "TSystemDefaultCache.SetSystemDefault: An Exception occured during the saving of the System Default '" + AKey + "'. Value to be saved: + '" + AValue + "'" + Environment.NewLine + Exc.ToString()); throw; } finally { if (SubmissionOK) { // We need to ensure that the next time the System Defaults Caches gets accessed it is refreshed from the DB!!! // Obtain thread-safe access to the FTableCached Field to prevent two (or more) Threads from getting a different // FTableCached value! lock (FTableCachedLockCookie) { FTableCached = false; } } if (DBConnectionObj != null) { DBConnectionObj.CloseDBConnection(); } } }
/// <summary> /// Stores a System Default in the DB. If it was already there it gets updated, if it wasn't there it gets added. /// </summary> /// <remarks>The change gets reflected in the System Defaults Cache the next time the System Defaults Cache /// gets accessed.</remarks> /// <param name="AKey">Name of the System Default.</param> /// <param name="AValue">Value of the System Default.</param> /// <param name="AAdded">True if the System Default got added, false if it already existed.</param> /// <param name="ADataBase"></param> /// <remarks>SystemDefault Names are not case sensitive.</remarks> public void SetSystemDefault(String AKey, String AValue, out bool AAdded, TDataBase ADataBase = null) { TDataBase DBConnectionObj = null; TDBTransaction WriteTransaction = new TDBTransaction(); bool SubmissionOK = false; SSystemDefaultsTable SystemDefaultsDT; Boolean Added = false; try { // Open a separate DB Connection... DBConnectionObj = DBAccess.Connect("SetSystemDefault", ADataBase); // ...and start a DB Transaction on that separate DB Connection DBConnectionObj.WriteTransaction(ref WriteTransaction, ref SubmissionOK, delegate { SystemDefaultsDT = SSystemDefaultsAccess.LoadAll(WriteTransaction); // This will find the row that matches a case-insensitive search of the table primary keys SystemDefaultsDT.CaseSensitive = false; // It is anyway SSystemDefaultsRow match = (SSystemDefaultsRow)SystemDefaultsDT.Rows.Find(AKey); if (match != null) { // I already have this System Default in the DB --> simply update the Value in the DB. // (This will often be the case!) match.DefaultValue = AValue; Added = false; } else { // The System Default isn't in the DB yet --> store it in the DB. var SystemDefaultsDR = SystemDefaultsDT.NewRowTyped(true); SystemDefaultsDR.DefaultCode = AKey; SystemDefaultsDR.DefaultDescription = "Created in OpenPetra"; SystemDefaultsDR.DefaultValue = AValue; SystemDefaultsDT.Rows.Add(SystemDefaultsDR); Added = true; } SSystemDefaultsAccess.SubmitChanges(SystemDefaultsDT, WriteTransaction); SubmissionOK = true; }); AAdded = Added; } catch (Exception Exc) { TLogging.Log( "TSystemDefaultCache.SetSystemDefault: An Exception occured during the saving of the System Default '" + AKey + "'. Value to be saved: + '" + AValue + "'" + Environment.NewLine + Exc.ToString()); throw; } finally { if (ADataBase == null) { DBConnectionObj.CloseDBConnection(); } if (SubmissionOK && (FSystemDefaultsDT != null)) { // We need to ensure that the next time the System Defaults Caches gets accessed it is refreshed from the DB!!! FSystemDefaultsDT.Clear(); FSystemDefaultsDT = null; } } }