SqlSugar/Src/Asp.NetCore2/MongoDb.Ado.data/ExecuteNonQueryItems/ExecuteHandlerFactory.cs
2025-05-02 16:55:48 +08:00

36 lines
1.2 KiB
C#

using MongoDb.Ado.data;
using MongoDB.Bson;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Text;
namespace MongoDb.Ado.data
{
public class ExecuteHandlerFactory
{
public readonly static Dictionary<string, IMongoOperationHandler> Items = new Dictionary<string, IMongoOperationHandler>(StringComparer.OrdinalIgnoreCase)
{
{ "insert", new InsertHandler() },
{ "insertmany", new InsertManyHandler() },
{ "update", new UpdateHandler() },
{ "updatemany", new UpdateManyHandler() },
{ "delete", new DeleteHandler() },
{ "deletemany", new DeleteManyHandler() },
{ "find", new NonFindHandler() }
};
public static int Handler(string operation, string json, IMongoCollection<BsonDocument> collection)
{
var handlers = ExecuteHandlerFactory.Items;
if (!handlers.TryGetValue(operation, out var handler))
throw new NotSupportedException($"不支持的操作类型: {operation}");
handler.operation = operation;
return handler.Handle(collection, json);
}
}
}