2025-05-02 07:54:16 +08:00
|
|
|
|
using MongoDb.Ado.data;
|
2025-05-02 15:42:18 +08:00
|
|
|
|
using MongoDB.Bson;
|
|
|
|
|
using MongoDB.Driver;
|
2025-05-02 07:54:16 +08:00
|
|
|
|
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() },
|
2025-05-02 11:39:41 +08:00
|
|
|
|
{ "find", new NonFindHandler() }
|
2025-05-02 07:54:16 +08:00
|
|
|
|
};
|
2025-05-02 15:42:18 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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}");
|
2025-05-02 16:55:48 +08:00
|
|
|
|
handler.operation = operation;
|
2025-05-02 15:42:18 +08:00
|
|
|
|
return handler.Handle(collection, json);
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-02 07:54:16 +08:00
|
|
|
|
}
|
|
|
|
|
}
|