Example #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);
 }
Example #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;
 }
Example #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);
 }
Example #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));
 }
Example #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;
 }
Example #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));
        }
Example #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());
        }
Example #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)));
        }
Example #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);
        }
Example #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);
        }
Example #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));
        }
Example #12
0
 public DbExecuteContext(IDataService dataService, IStatementSetting statement, DataSessionBase dataSession, IDictionary parameters, IDictionary items)
     : this(dataService, statement, null, null, parameters, items)
 {
     this.dataSession = dataSession;
 }
Example #13
0
 protected virtual string GetCommandText(IDbExecuteContext ctx, IStatementSetting statement, IDictionary parameterValues)
 {
     return statement.StatementText.GetCommandText(statement, parameterValues);
 }
Example #14
0
 protected internal virtual IDataStorage GetDataStorage(IStatementSetting statement)
 {
     return(this.DataStorage ?? this.DataService.GetDataStorage(statement));
 }
Example #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;
 }
Example #16
0
 protected internal virtual IDataStorage GetDataStorage(IStatementSetting statementSetting)
 {
     return(this.GetDataStorage(statementSetting.DataStorageName));
 }
Example #17
0
 public DbExecuteContext(IDataService dataService, IStatementSetting statement, DataSessionBase dataSession, IDictionary parameters, IDictionary items) : this(dataService, statement, null, null, parameters, items)
 {
     this.dataSession = dataSession;
 }
Example #18
0
 protected internal virtual IDataStorage GetDataStorage(IStatementSetting statement)
 {
     return this.DataStorage ?? this.DataService.GetDataStorage(statement);
 }
Example #19
0
 object IObjectMapper.Mapping(IStatementSetting statement, IDictionary dictionary, Type instanceType, object instance)
 {
     return(this.MappingInternal(statement, dictionary, instanceType, instance));
 }
Example #20
0
 object IObjectMapper.Mapping(IStatementSetting statement, IDictionary dictionary, Type instanceType, object instance)
 {
     return this.MappingInternal(statement, dictionary, instanceType, instance);
 }
Example #21
0
 protected virtual string GetCommandText(IStatementSetting statement, IDictionary parameters)
 {
     return statement.StatementText.ConfigSetting.Value.Value;
 }
Example #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));
        }
Example #23
0
 string ICommandTextParser.GetCommandText(IStatementSetting statement, IDictionary parameters)
 {
     return this.GetCommandText(statement, parameters);
 }
Example #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);
 }
Example #25
0
 protected virtual string GetCommandText(IStatementSetting statement, IDictionary parameters)
 {
     return(statement.StatementText.CommandText);
 }
Example #26
0
 string ICommandTextParser.GetCommandText(IStatementSetting statement, IDictionary parameters)
 {
     return(this.GetCommandText(statement, parameters));
 }
Example #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)));
        }