/// <summary> /// Placeholder /// </summary> /// <param name="record"></param> public override void Update(EntityTree record) { DataModel dataModel = new DataModel(); DataModelTransaction transaction = DataModelTransaction.Current; EntityTreeRow entityTreeRow = DataModel.EntityTree.EntityTreeKey.Find(record.RowId); EntityRow child = DataModel.Entity.EntityKey.Find(record.ChildId); EntityRow parent = DataModel.Entity.EntityKey.Find(record.ParentId); String childName; entityTreeRow.AcquireWriterLock(transaction); if (!DataModelFilters.HasAccess(transaction, TradingSupport.UserId, entityTreeRow.ParentId, AccessRight.Write)) { throw new SecurityException("Current user does not have write access to the old parent entity"); } if (!DataModelFilters.HasAccess(transaction, TradingSupport.UserId, record.ParentId, AccessRight.Write)) { throw new SecurityException("Current user does not have write access to the new parent entity"); } parent.AcquireWriterLock(transaction); child.AcquireReaderLock(transaction); childName = child.Name; child.ReleaseLock(transaction.TransactionId); if (record.ChildId == record.ParentId) { throw new FaultException <ArgumentFault>(new ArgumentFault("Create EntityTree"), new FaultReason(String.Format("Cannot add {0} as a child of this element because it wil create a circular relationship", childName))); } if (IsParentEntity(transaction, parent, record.ChildId) == true) { throw new FaultException <ArgumentFault>(new ArgumentFault("Create EntityTree"), new FaultReason(String.Format("Cannot add {0} as a child of this element because it wil create a circular relationship", childName))); } if (!EntityPersistence.IsNameUnique(transaction, parent, childName)) { throw new FaultException <RecordExistsFault>( new RecordExistsFault("Entity", new object[] { childName }), "An entity with this name already exists"); } dataModel.UpdateEntityTree( record.ChildId, entityTreeRow.EntityTreeId, new object[] { entityTreeRow.EntityTreeId }, null, record.ParentId, entityTreeRow.RowVersion); }
/// <summary> /// Delete a WorkingOrderRow. /// </summary> /// <param name="dataModel">The data model.</param> /// <param name="transaction">The current transaction.</param> /// <param name="workingOrderRow">The working order row to delete.</param> /// <returns>Error code of any failure, or Success.</returns> public ErrorCode DeleteRow(DataModel dataModel, DataModelTransaction transaction, WorkingOrderRow workingOrderRow) { SecurityRow securityRow = null; EntityRow securityEntityRow = null; MatchRow[] matchRows; ConsumerDebtRow[] consumerDebtRows; ConsumerTrustRow[] consumerTrustRows; CreditCardRow creditCardRow = null; ConsumerRow consumerRow = null; Guid blotterId; Guid securityEntityId = Guid.Empty; Int64 securityEntityRowVersion = 0; Guid consumerId = Guid.Empty; Int64 consumerRowVersion = 0; Guid creditCardId = Guid.Empty; Int64 creditCardRowVersion = 0; Boolean consumerStillInUse = false; workingOrderRow.AcquireWriterLock(transaction.TransactionId, DataModel.LockTimeout); if (workingOrderRow.RowState == DataRowState.Deleted || workingOrderRow.RowState == DataRowState.Detached) { workingOrderRow.ReleaseLock(transaction.TransactionId); return(ErrorCode.RecordNotFound); } else { transaction.AddLock(workingOrderRow); } blotterId = workingOrderRow.BlotterId; securityRow = workingOrderRow.SecurityRowByFK_Security_WorkingOrder_SecurityId; matchRows = workingOrderRow.GetMatchRows(); if (matchRows != null) { foreach (MatchRow matchRow in matchRows) { if (IsSettled(transaction, matchRow)) { return(ErrorCode.RecordExists); } } } if (!DataModelFilters.HasAccess(transaction, TradingSupport.UserId, blotterId, AccessRight.Write)) { workingOrderRow.ReleaseLock(transaction.TransactionId); return(ErrorCode.AccessDenied); } securityRow.AcquireWriterLock(transaction.TransactionId, DataModel.LockTimeout); if (securityRow.RowState == DataRowState.Deleted || securityRow.RowState == DataRowState.Detached) { workingOrderRow.ReleaseLock(transaction.TransactionId); securityRow.ReleaseWriterLock(transaction.TransactionId); return(ErrorCode.RecordNotFound); } securityEntityRow = securityRow.EntityRow; consumerDebtRows = securityRow.GetConsumerDebtRows(); consumerTrustRows = securityRow.GetConsumerTrustRows(); securityRow.ReleaseWriterLock(transaction.TransactionId); securityEntityRow.AcquireWriterLock(transaction); if (securityEntityRow.RowState == DataRowState.Deleted || securityEntityRow.RowState == DataRowState.Detached) { workingOrderRow.ReleaseLock(transaction.TransactionId); securityEntityRow.ReleaseLock(transaction.TransactionId); return(ErrorCode.RecordNotFound); } securityEntityId = securityEntityRow.EntityId; securityEntityRowVersion = securityEntityRow.RowVersion; securityEntityRow.ReleaseLock(transaction.TransactionId); if (consumerTrustRows.Length > 0 && consumerDebtRows.Length > 0) { EventLog.Warning("Deleting a working order associated with both ConsumerDebt and ConsumerTrust rows"); } else if (consumerDebtRows.Length > 1) { EventLog.Warning("Deleting a working order associated with more than one ConsumerDebt row"); } else if (consumerTrustRows.Length > 1) { EventLog.Warning("Deleting a working order associated with more than one ConsumerTrust row"); } if (consumerDebtRows.Length == 1) { ConsumerDebtRow consumerDebtRow = consumerDebtRows[0]; consumerDebtRow.AcquireWriterLock(transaction); if (consumerDebtRow.RowState == DataRowState.Deleted || consumerDebtRow.RowState == DataRowState.Detached) { } else { creditCardRow = consumerDebtRow.CreditCardRow; consumerRow = consumerDebtRow.ConsumerRow; } consumerDebtRow.ReleaseLock(transaction.TransactionId); } else if (consumerTrustRows.Length == 1) { ConsumerTrustRow consumerTrustRow = consumerTrustRows[0]; consumerTrustRow.AcquireWriterLock(transaction); if (consumerTrustRow.RowState == DataRowState.Deleted || consumerTrustRow.RowState == DataRowState.Detached) { } else { consumerRow = consumerTrustRow.ConsumerRow; } consumerTrustRow.ReleaseLock(transaction.TransactionId); } if (consumerRow != null) { consumerRow.AcquireWriterLock(transaction); if (consumerRow.RowState == DataRowState.Deleted || consumerRow.RowState == DataRowState.Detached) { consumerRow = null; } else { consumerStillInUse = consumerRow.GetConsumerDebtRows().Length > 1; consumerId = consumerRow.ConsumerId; consumerRowVersion = consumerRow.RowVersion; } consumerRow.ReleaseLock(transaction.TransactionId); } if (creditCardRow != null) { creditCardRow.AcquireWriterLock(transaction); if (creditCardRow.RowState == DataRowState.Deleted || creditCardRow.RowState == DataRowState.Detached) { creditCardRow = null; } else { creditCardId = creditCardRow.ConsumerId; creditCardRowVersion = creditCardRow.RowVersion; } creditCardRow.ReleaseLock(transaction.TransactionId); } //gonna get the lock on the workingOrder and let the txn commit/rollback get rid of it //this will basically wrap the delete row //action in a critical section because the first //reader lock in the method is on the workingOrder row //workingOrderRow.AcquireWriterLock(transaction.TransactionId, DataModel.LockTimeout); if (workingOrderRow.RowState == DataRowState.Deleted || workingOrderRow.RowState == DataRowState.Detached) { workingOrderRow.ReleaseLock(transaction.TransactionId); return(ErrorCode.RecordNotFound); } //securityRow.AcquireWriterLock(transaction.TransactionId, DataModel.LockTimeout); //if(securityRow.RowState == DataRowState.Deleted || // securityRow.RowState == DataRowState.Detached) //{ // workingOrderRow.ReleaseLock(transaction.TransactionId); // return ErrorCode.RecordNotFound; //} if (creditCardRow != null && consumerStillInUse) { dataModel.DestroyCreditCard(new object[] { creditCardId }, creditCardRowVersion); } if (consumerRow != null && !consumerStillInUse) { dataModel.DestroyConsumer(new object[] { consumerId }, consumerRowVersion); } dataModel.DestroyEntity(new object[] { securityEntityId }, securityEntityRowVersion); return(ErrorCode.Success); }