|
@@ -30,7 +30,7 @@ namespace ET.Server
|
|
|
|
|
|
|
|
public static async ETTask<T> Query<T>(this DBComponent self, long id, string collection = null) where T : Entity
|
|
public static async ETTask<T> Query<T>(this DBComponent self, long id, string collection = null) where T : Entity
|
|
|
{
|
|
{
|
|
|
- using (await self.Fiber().CoroutineLockComponent.Wait(CoroutineLockType.DB, id % DBComponent.TaskCount))
|
|
|
|
|
|
|
+ using (await self.Root().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.DB, id % DBComponent.TaskCount))
|
|
|
{
|
|
{
|
|
|
IAsyncCursor<T> cursor = await self.GetCollection<T>(collection).FindAsync(d => d.Id == id);
|
|
IAsyncCursor<T> cursor = await self.GetCollection<T>(collection).FindAsync(d => d.Id == id);
|
|
|
|
|
|
|
@@ -41,7 +41,7 @@ namespace ET.Server
|
|
|
public static async ETTask<List<T>> Query<T>(this DBComponent self, Expression<Func<T, bool>> filter, string collection = null)
|
|
public static async ETTask<List<T>> Query<T>(this DBComponent self, Expression<Func<T, bool>> filter, string collection = null)
|
|
|
where T : Entity
|
|
where T : Entity
|
|
|
{
|
|
{
|
|
|
- using (await self.Fiber().CoroutineLockComponent.Wait(CoroutineLockType.DB, RandomGenerator.RandInt64() % DBComponent.TaskCount))
|
|
|
|
|
|
|
+ using (await self.Root().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.DB, RandomGenerator.RandInt64() % DBComponent.TaskCount))
|
|
|
{
|
|
{
|
|
|
IAsyncCursor<T> cursor = await self.GetCollection<T>(collection).FindAsync(filter);
|
|
IAsyncCursor<T> cursor = await self.GetCollection<T>(collection).FindAsync(filter);
|
|
|
|
|
|
|
@@ -52,7 +52,7 @@ namespace ET.Server
|
|
|
public static async ETTask<List<T>> Query<T>(this DBComponent self, long taskId, Expression<Func<T, bool>> filter, string collection = null)
|
|
public static async ETTask<List<T>> Query<T>(this DBComponent self, long taskId, Expression<Func<T, bool>> filter, string collection = null)
|
|
|
where T : Entity
|
|
where T : Entity
|
|
|
{
|
|
{
|
|
|
- using (await self.Fiber().CoroutineLockComponent.Wait(CoroutineLockType.DB, taskId % DBComponent.TaskCount))
|
|
|
|
|
|
|
+ using (await self.Root().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.DB, taskId % DBComponent.TaskCount))
|
|
|
{
|
|
{
|
|
|
IAsyncCursor<T> cursor = await self.GetCollection<T>(collection).FindAsync(filter);
|
|
IAsyncCursor<T> cursor = await self.GetCollection<T>(collection).FindAsync(filter);
|
|
|
|
|
|
|
@@ -67,7 +67,7 @@ namespace ET.Server
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- using (await self.Fiber().CoroutineLockComponent.Wait(CoroutineLockType.DB, id % DBComponent.TaskCount))
|
|
|
|
|
|
|
+ using (await self.Root().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.DB, id % DBComponent.TaskCount))
|
|
|
{
|
|
{
|
|
|
foreach (string collectionName in collectionNames)
|
|
foreach (string collectionName in collectionNames)
|
|
|
{
|
|
{
|
|
@@ -87,7 +87,7 @@ namespace ET.Server
|
|
|
|
|
|
|
|
public static async ETTask<List<T>> QueryJson<T>(this DBComponent self, string json, string collection = null) where T : Entity
|
|
public static async ETTask<List<T>> QueryJson<T>(this DBComponent self, string json, string collection = null) where T : Entity
|
|
|
{
|
|
{
|
|
|
- using (await self.Fiber().CoroutineLockComponent.Wait(CoroutineLockType.DB, RandomGenerator.RandInt64() % DBComponent.TaskCount))
|
|
|
|
|
|
|
+ using (await self.Root().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.DB, RandomGenerator.RandInt64() % DBComponent.TaskCount))
|
|
|
{
|
|
{
|
|
|
FilterDefinition<T> filterDefinition = new JsonFilterDefinition<T>(json);
|
|
FilterDefinition<T> filterDefinition = new JsonFilterDefinition<T>(json);
|
|
|
IAsyncCursor<T> cursor = await self.GetCollection<T>(collection).FindAsync(filterDefinition);
|
|
IAsyncCursor<T> cursor = await self.GetCollection<T>(collection).FindAsync(filterDefinition);
|
|
@@ -97,7 +97,7 @@ namespace ET.Server
|
|
|
|
|
|
|
|
public static async ETTask<List<T>> QueryJson<T>(this DBComponent self, long taskId, string json, string collection = null) where T : Entity
|
|
public static async ETTask<List<T>> QueryJson<T>(this DBComponent self, long taskId, string json, string collection = null) where T : Entity
|
|
|
{
|
|
{
|
|
|
- using (await self.Fiber().CoroutineLockComponent.Wait(CoroutineLockType.DB, RandomGenerator.RandInt64() % DBComponent.TaskCount))
|
|
|
|
|
|
|
+ using (await self.Root().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.DB, RandomGenerator.RandInt64() % DBComponent.TaskCount))
|
|
|
{
|
|
{
|
|
|
FilterDefinition<T> filterDefinition = new JsonFilterDefinition<T>(json);
|
|
FilterDefinition<T> filterDefinition = new JsonFilterDefinition<T>(json);
|
|
|
IAsyncCursor<T> cursor = await self.GetCollection<T>(collection).FindAsync(filterDefinition);
|
|
IAsyncCursor<T> cursor = await self.GetCollection<T>(collection).FindAsync(filterDefinition);
|
|
@@ -116,7 +116,7 @@ namespace ET.Server
|
|
|
collection = typeof (T).FullName;
|
|
collection = typeof (T).FullName;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- using (await self.Fiber().CoroutineLockComponent.Wait(CoroutineLockType.DB, RandomGenerator.RandInt64() % DBComponent.TaskCount))
|
|
|
|
|
|
|
+ using (await self.Root().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.DB, RandomGenerator.RandInt64() % DBComponent.TaskCount))
|
|
|
{
|
|
{
|
|
|
await self.GetCollection(collection).InsertManyAsync(list);
|
|
await self.GetCollection(collection).InsertManyAsync(list);
|
|
|
}
|
|
}
|
|
@@ -128,7 +128,6 @@ namespace ET.Server
|
|
|
|
|
|
|
|
public static async ETTask Save<T>(this DBComponent self, T entity, string collection = null) where T : Entity
|
|
public static async ETTask Save<T>(this DBComponent self, T entity, string collection = null) where T : Entity
|
|
|
{
|
|
{
|
|
|
- Fiber fiber = self.Fiber();
|
|
|
|
|
if (entity == null)
|
|
if (entity == null)
|
|
|
{
|
|
{
|
|
|
Log.Error($"save entity is null: {typeof (T).FullName}");
|
|
Log.Error($"save entity is null: {typeof (T).FullName}");
|
|
@@ -141,7 +140,7 @@ namespace ET.Server
|
|
|
collection = entity.GetType().FullName;
|
|
collection = entity.GetType().FullName;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- using (await fiber.CoroutineLockComponent.Wait(CoroutineLockType.DB, entity.Id % DBComponent.TaskCount))
|
|
|
|
|
|
|
+ using (await self.Root().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.DB, entity.Id % DBComponent.TaskCount))
|
|
|
{
|
|
{
|
|
|
await self.GetCollection(collection).ReplaceOneAsync(d => d.Id == entity.Id, entity, new ReplaceOptions { IsUpsert = true });
|
|
await self.GetCollection(collection).ReplaceOneAsync(d => d.Id == entity.Id, entity, new ReplaceOptions { IsUpsert = true });
|
|
|
}
|
|
}
|
|
@@ -149,7 +148,6 @@ namespace ET.Server
|
|
|
|
|
|
|
|
public static async ETTask Save<T>(this DBComponent self, long taskId, T entity, string collection = null) where T : Entity
|
|
public static async ETTask Save<T>(this DBComponent self, long taskId, T entity, string collection = null) where T : Entity
|
|
|
{
|
|
{
|
|
|
- Fiber fiber = self.Fiber();
|
|
|
|
|
if (entity == null)
|
|
if (entity == null)
|
|
|
{
|
|
{
|
|
|
Log.Error($"save entity is null: {typeof (T).FullName}");
|
|
Log.Error($"save entity is null: {typeof (T).FullName}");
|
|
@@ -162,7 +160,7 @@ namespace ET.Server
|
|
|
collection = entity.GetType().FullName;
|
|
collection = entity.GetType().FullName;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- using (await fiber.CoroutineLockComponent.Wait(CoroutineLockType.DB, taskId % DBComponent.TaskCount))
|
|
|
|
|
|
|
+ using (await self.Root().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.DB, taskId % DBComponent.TaskCount))
|
|
|
{
|
|
{
|
|
|
await self.GetCollection(collection).ReplaceOneAsync(d => d.Id == entity.Id, entity, new ReplaceOptions { IsUpsert = true });
|
|
await self.GetCollection(collection).ReplaceOneAsync(d => d.Id == entity.Id, entity, new ReplaceOptions { IsUpsert = true });
|
|
|
}
|
|
}
|
|
@@ -170,14 +168,13 @@ namespace ET.Server
|
|
|
|
|
|
|
|
public static async ETTask Save(this DBComponent self, long id, List<Entity> entities)
|
|
public static async ETTask Save(this DBComponent self, long id, List<Entity> entities)
|
|
|
{
|
|
{
|
|
|
- Fiber fiber = self.Fiber();
|
|
|
|
|
if (entities == null)
|
|
if (entities == null)
|
|
|
{
|
|
{
|
|
|
Log.Error($"save entity is null");
|
|
Log.Error($"save entity is null");
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- using (await self.Fiber().CoroutineLockComponent.Wait(CoroutineLockType.DB, id % DBComponent.TaskCount))
|
|
|
|
|
|
|
+ using (await self.Root().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.DB, id % DBComponent.TaskCount))
|
|
|
{
|
|
{
|
|
|
foreach (Entity entity in entities)
|
|
foreach (Entity entity in entities)
|
|
|
{
|
|
{
|
|
@@ -210,7 +207,7 @@ namespace ET.Server
|
|
|
|
|
|
|
|
public static async ETTask<long> Remove<T>(this DBComponent self, long id, string collection = null) where T : Entity
|
|
public static async ETTask<long> Remove<T>(this DBComponent self, long id, string collection = null) where T : Entity
|
|
|
{
|
|
{
|
|
|
- using (await self.Fiber().CoroutineLockComponent.Wait(CoroutineLockType.DB, id % DBComponent.TaskCount))
|
|
|
|
|
|
|
+ using (await self.Root().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.DB, id % DBComponent.TaskCount))
|
|
|
{
|
|
{
|
|
|
DeleteResult result = await self.GetCollection<T>(collection).DeleteOneAsync(d => d.Id == id);
|
|
DeleteResult result = await self.GetCollection<T>(collection).DeleteOneAsync(d => d.Id == id);
|
|
|
|
|
|
|
@@ -220,7 +217,7 @@ namespace ET.Server
|
|
|
|
|
|
|
|
public static async ETTask<long> Remove<T>(this DBComponent self, long taskId, long id, string collection = null) where T : Entity
|
|
public static async ETTask<long> Remove<T>(this DBComponent self, long taskId, long id, string collection = null) where T : Entity
|
|
|
{
|
|
{
|
|
|
- using (await self.Fiber().CoroutineLockComponent.Wait(CoroutineLockType.DB, taskId % DBComponent.TaskCount))
|
|
|
|
|
|
|
+ using (await self.Root().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.DB, taskId % DBComponent.TaskCount))
|
|
|
{
|
|
{
|
|
|
DeleteResult result = await self.GetCollection<T>(collection).DeleteOneAsync(d => d.Id == id);
|
|
DeleteResult result = await self.GetCollection<T>(collection).DeleteOneAsync(d => d.Id == id);
|
|
|
|
|
|
|
@@ -230,7 +227,7 @@ namespace ET.Server
|
|
|
|
|
|
|
|
public static async ETTask<long> Remove<T>(this DBComponent self, Expression<Func<T, bool>> filter, string collection = null) where T : Entity
|
|
public static async ETTask<long> Remove<T>(this DBComponent self, Expression<Func<T, bool>> filter, string collection = null) where T : Entity
|
|
|
{
|
|
{
|
|
|
- using (await self.Fiber().CoroutineLockComponent.Wait(CoroutineLockType.DB, RandomGenerator.RandInt64() % DBComponent.TaskCount))
|
|
|
|
|
|
|
+ using (await self.Root().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.DB, RandomGenerator.RandInt64() % DBComponent.TaskCount))
|
|
|
{
|
|
{
|
|
|
DeleteResult result = await self.GetCollection<T>(collection).DeleteManyAsync(filter);
|
|
DeleteResult result = await self.GetCollection<T>(collection).DeleteManyAsync(filter);
|
|
|
|
|
|
|
@@ -241,7 +238,7 @@ namespace ET.Server
|
|
|
public static async ETTask<long> Remove<T>(this DBComponent self, long taskId, Expression<Func<T, bool>> filter, string collection = null)
|
|
public static async ETTask<long> Remove<T>(this DBComponent self, long taskId, Expression<Func<T, bool>> filter, string collection = null)
|
|
|
where T : Entity
|
|
where T : Entity
|
|
|
{
|
|
{
|
|
|
- using (await self.Fiber().CoroutineLockComponent.Wait(CoroutineLockType.DB, taskId % DBComponent.TaskCount))
|
|
|
|
|
|
|
+ using (await self.Root().GetComponent<CoroutineLockComponent>().Wait(CoroutineLockType.DB, taskId % DBComponent.TaskCount))
|
|
|
{
|
|
{
|
|
|
DeleteResult result = await self.GetCollection<T>(collection).DeleteManyAsync(filter);
|
|
DeleteResult result = await self.GetCollection<T>(collection).DeleteManyAsync(filter);
|
|
|
|
|
|