protected internal virtual IDbCommandWrap GetCommandWrap(IStatementSetting statement) { DbConnection connection; var closeConnectionOnCommandDisposed = true; if (this.IsInTransaction) { if (this.transaction == null) { lock (this.lockTransaction) { if (this.transaction == null) { connection = this.GetConnection(statement); connection.Open(); if(this.DataService.Debug) { LogService.WriteLog(this, LogLevel.DEBUG, "Connection open with transaction:" + connection.GetHashCode()); } this.transaction = connection.BeginTransaction(); } } } connection = this.Transaction.Connection; closeConnectionOnCommandDisposed = false; } else { connection = this.GetConnection(statement); connection.Open(); if(this.DataService.Debug) { LogService.WriteLog(this, LogLevel.DEBUG, "Connection open without transaction:" + connection.GetHashCode()); } } var command = connection.CreateCommand(); command.Transaction = this.Transaction; return new DbCommandWrap(command, closeConnectionOnCommandDisposed); }
public DbExecuteContext(IDataService dataService, IStatementSetting statement, IDataStorage dataStorage, IDbCommandWrap commandWrap, IDictionary parameters, IDictionary items) : base(items) { this.DataService = dataService; this.Statement = statement; this.DataStorage = dataStorage; this.CommandWrap = commandWrap; this.Parameters = parameters; }
protected virtual string GetCommandText(IDbExecuteContext ctx, IStatementSetting statement, IDictionary parameterValues) { if (statement.StatementText.Parser != null) { return(statement.StatementText.Parser.GetCommandText(statement, parameterValues)); } return(statement.StatementText.CommandText); }
protected virtual object MappingInternal(IStatementSetting statement, IDictionary dictionary, Type instanceType, object instance) { var parameters = new HybridDictionary { { typeof(IObjectMapper), dictionary } }; if(instance != null) { parameters.Add(typeof(ObjectMapperExtender), instance); } var resultType = statement.ResultTypeName; return this.GetOrCreateObject(resultType, instanceType, parameters, x => ObjectMapper.RefectionMapping(x, dictionary)); }
protected internal virtual IDataStorage GetDataStorage(IStatementSetting statementSetting) { var storageName = statementSetting.DataStorageName; if (string.IsNullOrEmpty(storageName)) { throw new DataException($"未找到名为 [{statementSetting.Name}] 的Sql语句对应的存储名,未配置Sql存储?"); } return(this.GetDataStorage(statementSetting.DataStorageName)); }
private void Trace(IStatementSetting statement, IDictionary parameters, string commandText) { var sb = new StringBuilder(); sb.AppendFormat("{0}\r\n{1}\r\n", statement.Name, commandText); sb.Append("{"); foreach (var key in parameters.Keys) { sb.AppendFormat("{0}={1},", key, parameters[key]); } sb.Append("}"); LogService.WriteLog(this, LogLevel.DEBUG, sb.ToString()); }
protected virtual object MappingInternal(IStatementSetting statement, IDictionary dictionary, Type instanceType, object instance) { var parameters = new HybridDictionary { { typeof(IObjectMapper), dictionary } }; if (instance != null) { parameters.Add(typeof(ObjectMapperExtender), instance); } var resultType = statement.ResultTypeName; return(this.GetOrCreateObject(resultType, instanceType, parameters, x => ObjectMapper.RefectionMapping(x, dictionary))); }
protected virtual DbConnection GetConnection(IStatementSetting statement) { if (this.connection != null) { return(this.connection); } var storage = this.DataStorage ?? this.DataService.GetDataStorage(statement); if (this.connection == null) { lock (this.lockConnection) { if (this.connection == null) { this.connection = storage.GetConnection(); } } } return(this.connection); }
protected override string GetCommandText(IStatementSetting statement, IDictionary parameters) { if (!this.templates.Contains(statement)) { lock (this.templates) { if (!this.templates.Contains(statement)) { Razor.Compile(statement.StatementText.ConfigSetting.Value.Value.Trim(' ', '\t', '\n'), typeof(DynamicParameter), statement.Name); if (!this.templates.Contains(statement)) { this.templates.Add(statement); } } } } var commandText = Razor.Run(statement.Name, new DynamicParameter(parameters)); this.Trace(statement, parameters, commandText); return(commandText); }
protected internal virtual IDbCommandWrap GetCommandWrap(IStatementSetting statement) { DbConnection connection; var closeConnectionOnCommandDisposed = true; if (this.IsInTransaction) { if (this.transaction == null) { lock (this.lockTransaction) { if (this.transaction == null) { connection = this.GetConnection(statement); connection.Open(); if (this.DataService.Debug) { LogService.WriteLog(this, LogLevel.DEBUG, "Connection open with transaction:" + connection.GetHashCode()); } this.transaction = connection.BeginTransaction(); } } } connection = this.Transaction.Connection; closeConnectionOnCommandDisposed = false; } else { connection = this.GetConnection(statement); connection.Open(); if (this.DataService.Debug) { LogService.WriteLog(this, LogLevel.DEBUG, "Connection open without transaction:" + connection.GetHashCode()); } } var command = connection.CreateCommand(); command.Transaction = this.Transaction; return(new DbCommandWrap(command, closeConnectionOnCommandDisposed)); }
public DbExecuteContext(IDataService dataService, IStatementSetting statement, DataSessionBase dataSession, IDictionary parameters, IDictionary items) : this(dataService, statement, null, null, parameters, items) { this.dataSession = dataSession; }
protected virtual string GetCommandText(IDbExecuteContext ctx, IStatementSetting statement, IDictionary parameterValues) { return statement.StatementText.GetCommandText(statement, parameterValues); }
protected internal virtual IDataStorage GetDataStorage(IStatementSetting statement) { return(this.DataStorage ?? this.DataService.GetDataStorage(statement)); }
protected virtual DbConnection GetConnection(IStatementSetting statement) { if(this.connection != null) { return this.connection; } var storage = this.DataStorage ?? this.DataService.GetDataStorage(statement); if (this.connection == null) { lock(this.lockConnection) { if(this.connection == null) { this.connection = storage.GetConnection(); } } } return this.connection; }
protected internal virtual IDataStorage GetDataStorage(IStatementSetting statementSetting) { return(this.GetDataStorage(statementSetting.DataStorageName)); }
protected internal virtual IDataStorage GetDataStorage(IStatementSetting statement) { return this.DataStorage ?? this.DataService.GetDataStorage(statement); }
object IObjectMapper.Mapping(IStatementSetting statement, IDictionary dictionary, Type instanceType, object instance) { return(this.MappingInternal(statement, dictionary, instanceType, instance)); }
object IObjectMapper.Mapping(IStatementSetting statement, IDictionary dictionary, Type instanceType, object instance) { return this.MappingInternal(statement, dictionary, instanceType, instance); }
protected virtual string GetCommandText(IStatementSetting statement, IDictionary parameters) { return statement.StatementText.ConfigSetting.Value.Value; }
protected override string GetCommandText(IStatementSetting statement, IDictionary parameters) { var config = statement.StatementText.ConfigSetting; return(this.GetCommandText(statement.GetObjectContext(this, () => config.ToSetting <DynamicTextSetting>()), parameters)); }
string ICommandTextParser.GetCommandText(IStatementSetting statement, IDictionary parameters) { return this.GetCommandText(statement, parameters); }
protected override string GetCommandText(IStatementSetting statement, IDictionary parameters) { var config = statement.StatementText.ConfigSetting; return this.GetCommandText(statement.GetObjectContext(this, () => config.ToSetting<DynamicTextSetting>()), parameters); }
protected virtual string GetCommandText(IStatementSetting statement, IDictionary parameters) { return(statement.StatementText.CommandText); }
string ICommandTextParser.GetCommandText(IStatementSetting statement, IDictionary parameters) { return(this.GetCommandText(statement, parameters)); }
protected virtual object MappingInternal(IStatementSetting statement, IDictionary dictionary, Type instanceType, object instance) { var resultType = statement.ResultTypeName; return(this.GetOrCreateObject(resultType, instanceType, x => ObjectMapper.RefectionMapping(x, dictionary))); }