mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 18:22:23 +08:00
Update tenant
This commit is contained in:
@@ -11,13 +11,15 @@ namespace SqlSugar
|
||||
void BeginTran();
|
||||
void CommitTran();
|
||||
void RollbackTran();
|
||||
void ChangeDatabase(string configId);
|
||||
void ChangeDatabase(dynamic configId);
|
||||
void ChangeDatabase(Func<ConnectionConfig, bool> changeExpression);
|
||||
DbResult<bool> UseTran(Action action, Action<Exception> errorCallBack = null);
|
||||
Task<DbResult<bool>> UseTranAsync(Action action, Action<Exception> errorCallBack = null);
|
||||
DbResult<T> UseTran<T>(Func<T> action, Action<Exception> errorCallBack = null);
|
||||
|
||||
Task<DbResult<T>> UseTranAsync<T>(Func<T> action, Action<Exception> errorCallBack = null);
|
||||
void AddConnection(ConnectionConfig connection);
|
||||
SqlSugarProvider GetConnection(dynamic configId);
|
||||
|
||||
void Close();
|
||||
void Open();
|
||||
|
@@ -189,7 +189,7 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
return "CREATE {3} INDEX Index_{0}_{2} ON {0}({1})";
|
||||
return "alter table {0} rename to {1}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
return "SELECT count(*) FROM sqlite_master WHERE name = '{0}'";
|
||||
return "CREATE {3} INDEX Index_{0}_{2} ON {0}({1})";
|
||||
}
|
||||
}
|
||||
protected override string AddDefaultValueSql
|
||||
|
@@ -543,7 +543,44 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region TenantManager
|
||||
public void ChangeDatabase(string configId)
|
||||
public void AddConnection(ConnectionConfig connection)
|
||||
{
|
||||
Check.ArgumentNullException(connection, "AddConnection.connection can't be null");
|
||||
InitTenant();
|
||||
var db = this._AllClients.FirstOrDefault(it => it.ConnectionConfig.ConfigId == connection.ConfigId);
|
||||
if (db == null)
|
||||
{
|
||||
if (this._AllClients == null)
|
||||
{
|
||||
this._AllClients = new List<SugarTenant>();
|
||||
}
|
||||
var provider = new SqlSugarProvider(connection);
|
||||
if (connection.AopEvents != null)
|
||||
{
|
||||
provider.Ado.IsEnableLogEvent = true;
|
||||
}
|
||||
this._AllClients.Add(new SugarTenant()
|
||||
{
|
||||
ConnectionConfig = connection,
|
||||
Context = provider
|
||||
});
|
||||
}
|
||||
}
|
||||
public SqlSugarProvider GetConnection(dynamic configId)
|
||||
{
|
||||
InitTenant();
|
||||
var db = this._AllClients.FirstOrDefault(it => it.ConnectionConfig.ConfigId == configId);
|
||||
if (db == null)
|
||||
{
|
||||
Check.Exception(true, "ConfigId was not found {0}", configId);
|
||||
}
|
||||
if (db.Context == null)
|
||||
{
|
||||
db.Context = new SqlSugarProvider(db.ConnectionConfig);
|
||||
}
|
||||
return db.Context;
|
||||
}
|
||||
public void ChangeDatabase(dynamic configId)
|
||||
{
|
||||
var isLog = _Context.Ado.IsEnableLogEvent;
|
||||
Check.Exception(!_AllClients.Any(it => it.ConnectionConfig.ConfigId == configId), "ConfigId was not found {0}", configId);
|
||||
@@ -573,7 +610,7 @@ namespace SqlSugar
|
||||
public void BeginTran()
|
||||
{
|
||||
_IsAllTran = true;
|
||||
this.Context.Ado.BeginTran();
|
||||
AllClientEach(it => it.Ado.BeginTran());
|
||||
}
|
||||
public void CommitTran()
|
||||
{
|
||||
@@ -749,6 +786,18 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
}
|
||||
private void InitTenant()
|
||||
{
|
||||
if (this._AllClients == null)
|
||||
{
|
||||
this._AllClients = new List<SugarTenant>();
|
||||
this._AllClients.Add(new SugarTenant()
|
||||
{
|
||||
ConnectionConfig = this.CurrentConnectionConfig,
|
||||
Context = this.Context
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private SqlSugarProvider Synchronization()
|
||||
{
|
||||
|
Reference in New Issue
Block a user