private void CheckConcurrencyControl(VerificationStage verificationStage) { if (_busObj.Status.IsNew) { return; //If the object is new there cannot be a concurrency error. } IDatabaseConnection connection = DatabaseConnection.CurrentConnection; if (connection == null) { return; } if (!(BORegistry.DataAccessor.BusinessObjectLoader is BusinessObjectLoaderDB)) { return; } var statement = GetSelectSQLStatement(); using (IDataReader dr = connection.LoadDataReader(statement)) { // If this object no longer exists in the database // then we have a concurrency conflict since it has been deleted by another process. // If our objective was to delete it as well then no worries else throw error. var drHasData = dr.Read(); if (!(drHasData) && !_busObj.Status.IsDeleted) { //The object you are trying to update has been deleted by another user. throw new BusObjDeleteConcurrencyControlException(_busObj.ClassDef.ClassName, _busObj.ID.ToString(), _busObj); } var versionNumberBusinessObject = (int)_versionNumber.Value; var versionNumberDB = (int)dr[_versionNumber.DatabaseFieldName]; if (versionNumberDB == versionNumberBusinessObject) { return; } var dateLastUpdatedInDB = dr[_dateLastUpdated.DatabaseFieldName].ToString(); var userNameLastUpdated = (string)dr[_userLastUpdated.DatabaseFieldName]; var machineLastUpdated = (string)dr[_machineLastUpdated.DatabaseFieldName]; ThrowConcurrencyException(verificationStage, userNameLastUpdated, machineLastUpdated, dateLastUpdatedInDB); } }
private void ThrowConcurrencyException(VerificationStage verificationStage, string userNameLastUpdated, string machineLastUpdated, string dateLastUpdatedInDB) { if (verificationStage == VerificationStage.BeforeBeginEdit) { throw new BusObjBeginEditConcurrencyControlException(_busObj.ClassDef.ClassName, userNameLastUpdated, machineLastUpdated, DateTime.Parse(dateLastUpdatedInDB), _busObj.ID.ToString(), _busObj); } throw new BusObjOptimisticConcurrencyControlException(_busObj.ClassDef.ClassName, userNameLastUpdated, machineLastUpdated, DateTime.Parse(dateLastUpdatedInDB), _busObj.ID.ToString(), _busObj); }
private void ThrowConcurrencyException(VerificationStage verificationStage, string userNameLastUpdated, string machineLastUpdated, string dateLastUpdatedInDB) { if (verificationStage == VerificationStage.BeforeBeginEdit) { throw new BusObjBeginEditConcurrencyControlException(_busObj.ClassDef.ClassName, userNameLastUpdated, machineLastUpdated, DateTime.Parse(dateLastUpdatedInDB), _busObj.ID.ToString(), _busObj); } throw new BusObjOptimisticConcurrencyControlException(_busObj.ClassDef.ClassName, userNameLastUpdated, machineLastUpdated, DateTime.Parse(dateLastUpdatedInDB), _busObj.ID.ToString(), _busObj); }
private void CheckConcurrencyControl(VerificationStage verificationStage) { if (_busObj.Status.IsNew) return; //If the object is new there cannot be a concurrency error. IDatabaseConnection connection = DatabaseConnection.CurrentConnection; if (connection == null) return; if (!(BORegistry.DataAccessor.BusinessObjectLoader is BusinessObjectLoaderDB)) return; var statement = GetSelectSQLStatement(); using (IDataReader dr = connection.LoadDataReader(statement)) { // If this object no longer exists in the database // then we have a concurrency conflict since it has been deleted by another process. // If our objective was to delete it as well then no worries else throw error. var drHasData = dr.Read(); if (!(drHasData) && !_busObj.Status.IsDeleted) { //The object you are trying to update has been deleted by another user. throw new BusObjDeleteConcurrencyControlException(_busObj.ClassDef.ClassName, _busObj.ID.ToString(), _busObj); } var versionNumberBusinessObject = (int) _versionNumber.Value; var versionNumberDB = (int) dr[_versionNumber.DatabaseFieldName]; if (versionNumberDB == versionNumberBusinessObject) return; var dateLastUpdatedInDB = dr[_dateLastUpdated.DatabaseFieldName].ToString(); var userNameLastUpdated = (string) dr[_userLastUpdated.DatabaseFieldName]; var machineLastUpdated = (string) dr[_machineLastUpdated.DatabaseFieldName]; ThrowConcurrencyException(verificationStage, userNameLastUpdated, machineLastUpdated, dateLastUpdatedInDB); } }