예제 #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)));
        }