示例#1
0
 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);
 }
示例#2
0
 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;
 }
示例#3
0
 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);
 }
示例#4
0
 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));
 }
示例#5
0
 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;
 }
示例#6
0
        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));
        }
示例#7
0
        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());
        }
示例#8
0
        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)));
        }
示例#9
0
        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);
        }
示例#10
0
        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);
        }
示例#11
0
        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));
        }
示例#12
0
 public DbExecuteContext(IDataService dataService, IStatementSetting statement, DataSessionBase dataSession, IDictionary parameters, IDictionary items)
     : this(dataService, statement, null, null, parameters, items)
 {
     this.dataSession = dataSession;
 }
示例#13
0
 protected virtual string GetCommandText(IDbExecuteContext ctx, IStatementSetting statement, IDictionary parameterValues)
 {
     return statement.StatementText.GetCommandText(statement, parameterValues);
 }
示例#14
0
 protected internal virtual IDataStorage GetDataStorage(IStatementSetting statement)
 {
     return(this.DataStorage ?? this.DataService.GetDataStorage(statement));
 }
示例#15
0
 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;
 }
示例#16
0
 protected internal virtual IDataStorage GetDataStorage(IStatementSetting statementSetting)
 {
     return(this.GetDataStorage(statementSetting.DataStorageName));
 }
示例#17
0
 public DbExecuteContext(IDataService dataService, IStatementSetting statement, DataSessionBase dataSession, IDictionary parameters, IDictionary items) : this(dataService, statement, null, null, parameters, items)
 {
     this.dataSession = dataSession;
 }
示例#18
0
 protected internal virtual IDataStorage GetDataStorage(IStatementSetting statement)
 {
     return this.DataStorage ?? this.DataService.GetDataStorage(statement);
 }
示例#19
0
 object IObjectMapper.Mapping(IStatementSetting statement, IDictionary dictionary, Type instanceType, object instance)
 {
     return(this.MappingInternal(statement, dictionary, instanceType, instance));
 }
示例#20
0
 object IObjectMapper.Mapping(IStatementSetting statement, IDictionary dictionary, Type instanceType, object instance)
 {
     return this.MappingInternal(statement, dictionary, instanceType, instance);
 }
示例#21
0
 protected virtual string GetCommandText(IStatementSetting statement, IDictionary parameters)
 {
     return statement.StatementText.ConfigSetting.Value.Value;
 }
示例#22
0
        protected override string GetCommandText(IStatementSetting statement, IDictionary parameters)
        {
            var config = statement.StatementText.ConfigSetting;

            return(this.GetCommandText(statement.GetObjectContext(this, () => config.ToSetting <DynamicTextSetting>()), parameters));
        }
示例#23
0
 string ICommandTextParser.GetCommandText(IStatementSetting statement, IDictionary parameters)
 {
     return this.GetCommandText(statement, parameters);
 }
示例#24
0
 protected override string GetCommandText(IStatementSetting statement, IDictionary parameters)
 {
     var config = statement.StatementText.ConfigSetting;
     return this.GetCommandText(statement.GetObjectContext(this, () => config.ToSetting<DynamicTextSetting>()), parameters);
 }
示例#25
0
 protected virtual string GetCommandText(IStatementSetting statement, IDictionary parameters)
 {
     return(statement.StatementText.CommandText);
 }
示例#26
0
 string ICommandTextParser.GetCommandText(IStatementSetting statement, IDictionary parameters)
 {
     return(this.GetCommandText(statement, parameters));
 }
示例#27
0
        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)));
        }