public override void PerformXMLActions()
        {
            try
            {
                var mongoDB = new MongoDBAcess(DatabaseName);
                if (RemovedKey == "ALL")
                {
                    mongoDB.RemoveAllKVFromCollection(TableName);
                }
                else
                {
                    // Remove record PK from any Index File
                    RemoveFromIndexFiles(mongoDB);

                    // Remove record PK from FK value
                    RemoveFromFKIndexFiles(mongoDB);

                    // Remove record from UQ file
                    RemoveFromUQIndexFiles(mongoDB);

                    // Remove record from main table collection
                    mongoDB.RemoveKVFromCollection(TableName, RemovedKey);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
示例#2
0
        private void InsertRecord(string key, string value)
        {
            try
            {
                // Insert into main table data file
                MongoDB.InsertKVIntoCollection(TableName, key, value);

                // Insert into FK index file
                foreach (var newFKRecords in NewForeignKeyEntries)
                {
                    // Check if the Foreign Key from the referenced table has any other assigned records from the current table
                    if (MongoDB.CollectionContainsKey(newFKRecords.MongoDBFilename, newFKRecords.ForeignKeyRecord.Key))
                    {
                        var existingReferences = MongoDB.GetRecordValueWithKey(newFKRecords.MongoDBFilename, newFKRecords.ForeignKeyRecord.Key);
                        existingReferences += "#" + newFKRecords.ForeignKeyRecord.Value;

                        // who needs update when you can just delete and add back
                        MongoDB.RemoveKVFromCollection(newFKRecords.MongoDBFilename, newFKRecords.ForeignKeyRecord.Key);
                        MongoDB.InsertKVIntoCollection(newFKRecords.MongoDBFilename, newFKRecords.ForeignKeyRecord.Key, existingReferences);
                    }
                    // Otherwise just add a new Key-Value entry
                    else
                    {
                        MongoDB.InsertKVIntoCollection(newFKRecords.MongoDBFilename, newFKRecords.ForeignKeyRecord.Key, newFKRecords.ForeignKeyRecord.Value);
                    }
                }

                // Insert into Unique Key files
                var columnValues = (key + '#' + value).Split('#');
                foreach (var uniqueKey in UniqueKeyData)
                {
                    var uqValue = columnValues.ElementAt(UniqueKeyPositions.Find(elem => elem.Key == uniqueKey.Item1.ToString()).Value);
                    MongoDB.InsertKVIntoCollection(uniqueKey.Item2, uqValue, key);
                }

                // Insert into any index files
                foreach (var indexFile in TableUtils.GetIndexFiles(DatabaseName, TableName))
                {
                    var indexKey      = "";
                    var recordColumns = (key + '#' + value).Split('#');

                    // Build the key from the specified Index KV file
                    foreach (var indexColumn in indexFile.IndexColumns)
                    {
                        indexKey += recordColumns[ColumnsInfo.FindIndex(elem => elem.ColumnName == indexColumn)] + '#';
                    }
                    indexKey = indexKey.Remove(indexKey.Length - 1);

                    if (indexFile.IsUnique)
                    {
                        MongoDB.InsertKVIntoCollection(indexFile.IndexFileName, indexKey, key);
                    }
                    else
                    {
                        if (MongoDB.CollectionContainsKey(indexFile.IndexFileName, indexKey))
                        {
                            // Append the new record PK to the value of the index key
                            var indexValue = MongoDB.GetRecordValueWithKey(indexFile.IndexFileName, indexKey) + '#' + key;
                            MongoDB.RemoveKVFromCollection(indexFile.IndexFileName, indexKey);
                            MongoDB.InsertKVIntoCollection(indexFile.IndexFileName, indexKey, indexValue);
                        }
                        else
                        {
                            MongoDB.InsertKVIntoCollection(indexFile.IndexFileName, indexKey, key);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }