public StoreResult UpdateDocument(ITransaction transaction, string collection, long rowId, JSONDocument update) { PersistenceManagerTransaction pmTransaction = transaction as PersistenceManagerTransaction; StorageResult <byte[]> storageResult = _storageManager.UpdateDocument(pmTransaction, _metadataIndices[collection].GetFileId(rowId), collection, rowId, SerializeDocument(update)); if (storageResult.Status != StoreResult.Success) { return(storageResult.Status); } lock (_metadataIndices) { _metadataIndices[collection].Add(rowId, storageResult.FileId); } MetaDataIndexOperation operation = new MetaDataIndexOperation() { ActualDocumentSize = update.Size, FileId = storageResult.FileId, OperationType = OperationType.Update, RowId = _metadataIndices[collection].GetRowId(new DocumentKey(update.Key)) }; (pmTransaction.MetadataTransaction as MetaDataIndexTransaction).AddOperation(new DocumentKey(update.Key), operation); StoreResult metadataResult = _metadataIndices[collection].StoreKeyMetadata(pmTransaction.MetadataTransaction.InnerObject as ITransaction, update, rowId); if (metadataResult != StoreResult.Success) //undo data operation { //_storageManager.DeleteDocument(pmTransaction.DataTransaction, storageResult.FileId, _collectionName, rowId); return(metadataResult); } return(StoreResult.Success); }
public StoreResult RemoveDocument(ITransaction transaction, string collection, long rowId, JSONDocument document, IOperationContext context) { PersistenceManagerTransaction pmTransaction = transaction as PersistenceManagerTransaction; StorageResult <byte[]> storageResult = _storageManager.DeleteDocument(pmTransaction, _metadataIndices[collection].GetFileId(rowId), collection, rowId); if (storageResult.Status != StoreResult.Success && storageResult.Status != StoreResult.SuccessDelete && storageResult.Status != StoreResult.SuccessKeyDoesNotExist) { return(storageResult.Status); } MetaDataIndexOperation operation = new MetaDataIndexOperation() { ActualDocumentSize = document.Size, FileId = storageResult.FileId, OperationType = OperationType.Remove, RowId = rowId }; (pmTransaction.MetadataTransaction as MetaDataIndexTransaction).AddOperation(new DocumentKey(document.Key), operation); StoreResult metadataResult = _metadataIndices[collection].RemovekeyMetadata(pmTransaction.MetadataTransaction.InnerObject as ITransaction, document, rowId, context); if (metadataResult != StoreResult.Success) //undo data operation { _storageManager.StoreDocument(pmTransaction, collection, rowId, SerializeDocument(document)); return(metadataResult); } return(StoreResult.SuccessDelete); }