Ejemplo n.º 1
0
        /// <summary>
        ///     初始化数据库环境、实例化子类中,所有Set属性
        /// </summary>
        public void Initializer()
        {
            if (IsInitializer)
            {
                return;
            }

            // 数据库提供者
            DbProvider = AbsDbProvider.CreateInstance(ContextConnection.DbType, ContextConnection.DataVer);

            var dbconfig = IocManager.Instance.Resolve <IConfigResolver>().DbConfig();

            // 默认SQL执行者
            Executeor = new ExecuteSql(new DbExecutor(ContextConnection.ConnectionString, ContextConnection.DbType, ContextConnection.CommandTimeout, !IsUnitOfWork && DbProvider.IsSupportTransaction ? IsolationLevel.RepeatableRead : IsolationLevel.Unspecified), this);

            // 代理SQL监控
            if (IocManager.Instance.IsRegistered <ISqlMonitor>())
            {
                Executeor = new ExecuteSqlMonitorProxy(Executeor);
            }

            // 队列管理者
            QueueManger = new QueueManger(this);
            // 手动编写SQL
            ManualSql = new ManualSql(this);
            // 上下文映射关系
            this.ContextMap = new ContextDataMap(ContextType);

            IsInitializer = true;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 注册依赖
        /// </summary>
        /// <param name="container"></param>
        /// <param name="store"></param>
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            var localConfigResolver = IocManager.Instance.Resolve <IConfigResolver>();
            var config = localConfigResolver.Get <DbConfig>();

            if (config.Items.Count == 0)
            {
                return;
            }
            config.Items.ForEach(m =>
            {
                // 注册Db连接
                var dbConnstring = AbsDbProvider.CreateInstance(m.DataType, m.DataVer).CreateDbConnstring(m.Server, m.Port, m.UserID, m.PassWord, m.Catalog, m.DataVer, m.Additional, m.ConnectTimeout, m.PoolMinSize, m.PoolMaxSize);
                container.Register(
                    Component.For <IContextConnection>()
                    .Named(m.Name)
                    .ImplementedBy <ContextConnection>()
                    .DependsOn(
                        Dependency.OnValue(dbConnstring.GetType(), dbConnstring),
                        Dependency.OnValue(m.DataType.GetType(), m.DataType),
                        Dependency.OnValue(m.CommandTimeout.GetType(), m.CommandTimeout),
                        Dependency.OnValue(m.DataType.GetType(), m.DataType)).LifestyleSingleton());
            });

            // 代理异常记录
            if (config.IsWriteSqlErrorLog)
            {
                container.Register(Component.For <ISqlMonitor>().ImplementedBy <MonitorSqlExceptionLog>().LifestyleTransient());
            }
            // 代理SQL记录
            if (config.IsWriteSqlRunLog)
            {
                container.Register(Component.For <ISqlMonitor>().ImplementedBy <MonitorSqlLog>().LifestyleTransient());
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     初始化数据库环境、实例化子类中,所有Set属性
        /// </summary>
        public void Initializer()
        {
            if (IsInitializer)
            {
                return;
            }

            // 数据库提供者
            DbProvider = AbsDbProvider.CreateInstance(_contextConnection.DbType, _contextConnection.DataVer);
            // 默认SQL执行者
            Executeor = new ExecuteSql(new DbExecutor(_contextConnection.ConnectionString, _contextConnection.DbType, _contextConnection.CommandTimeout, IsMergeCommand && DbProvider.IsSupportTransaction ? IsolationLevel.Serializable : IsolationLevel.Unspecified), this);
            // 代理SQL记录
            if (SystemConfigs.ConfigEntity.IsWriteDbLog)
            {
                Executeor = new ExecuteSqlLogProxy(Executeor);
            }
            // 代理异常记录
            if (SystemConfigs.ConfigEntity.IsWriteDbExceptionLog)
            {
                Executeor = new ExecuteSqlExceptionLogProxy(Executeor);
            }

            // 队列管理者
            QueueManger = new QueueManger(this);
            // 手动编写SQL
            ManualSql = new ManualSql(this);
            // 上下文映射关系
            this.ContextMap = new ContextDataMap(ContextType);

            IsInitializer = true;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 查询支持的SQL方法
 /// </summary>
 /// <param name="dbProvider">数据库提供者(不同数据库的特性)</param>
 /// <param name="expBuilder">表达式持久化</param>
 /// <param name="name">表名/视图名/存储过程名</param>
 protected SqlBuilder(AbsDbProvider dbProvider, ExpressionBuilder expBuilder, string name)
 {
     DbProvider = dbProvider;
     ExpBuilder = expBuilder;
     Name       = name;
     Param      = new List <DbParameter>();
     Sql        = new StringBuilder();
 }
Ejemplo n.º 5
0
 /// <summary>
 ///     查询支持的SQL方法
 /// </summary>
 /// <param name="dbProvider">数据库提供者(不同数据库的特性)</param>
 /// <param name="expBuilder">表达式持久化</param>
 /// <param name="name">表名/视图名/存储过程名</param>
 internal AbsSqlBuilder(AbsDbProvider dbProvider, ExpressionBuilder expBuilder, string name)
 {
     DbProvider = dbProvider;
     ExpBuilder = expBuilder;
     Name = name;
     Param = new List<DbParameter>();
     Sql = new StringBuilder();
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 实例化子类中,所有Set属性
        /// </summary>
        private void InstanceProperty()
        {
            IsMergeCommand = true;
            DbProvider     = AbsDbProvider.CreateInstance(DataBase.DataType);
            QueueManger    = new QueueManger(this);
            Executeor      = SystemConfigs.ConfigEntity.IsWriteDbLog ? new ExecuteSqlProxy(this) : new ExecuteSql(this);

            InstanceProperty(this, "TableSet`1");
            InstanceProperty(this, "TableSetCache`1");
            InstanceProperty(this, "ViewSet`1");
            InstanceProperty(this, "ViewSetCache`1");
            InstanceProperty(this, "ProcSet`1");
        }
        protected override string SetCacheLock()
        {
            lock (LockObject)
            {
                if (CacheList.ContainsKey(Key))
                {
                    return(CacheList[Key]);
                }

                DbInfo dbInfo = Key;
                CacheList.Add(Key, AbsDbProvider.CreateInstance(dbInfo.DataType, dbInfo.DataVer).CreateDbConnstring(dbInfo.UserID, dbInfo.PassWord, dbInfo.Server, dbInfo.Catalog, dbInfo.DataVer, dbInfo.ConnectTimeout, dbInfo.PoolMinSize, dbInfo.PoolMaxSize, dbInfo.Port));
            }

            return(CacheList[Key]);
        }
Ejemplo n.º 8
0
        /// <summary>
        ///     获取数据库连接对象
        /// </summary>
        /// <param name="dbType">数据库类型</param>
        /// <param name="connectionString">连接字符串</param>
        public static DbConnection GetDbConnection(eumDbType dbType, string connectionString)
        {
            DbConnection conn;

            switch (dbType)
            {
            case eumDbType.SqlServer:
                conn = new SqlConnection(connectionString);
                break;

            default:
                conn = AbsDbProvider.CreateInstance(dbType).DbProviderFactory.CreateConnection();
                break;
            }
            conn.ConnectionString = connectionString;
            return(conn);
        }
Ejemplo n.º 9
0
        /// <summary>
        ///     打开数据库连接
        /// </summary>
        private void Open()
        {
            if (_conn == null)
            {
                _factory             = AbsDbProvider.CreateInstance(DataType).GetDbProviderFactory;
                _comm                = _factory.CreateCommand();
                _comm.CommandTimeout = _commandTimeout;

                _conn = _factory.CreateConnection();
                _conn.ConnectionString = _connectionString;
                _comm.Connection       = _conn;
            }
            if (_conn.State == ConnectionState.Closed)
            {
                _conn.Open();
                _comm.Parameters.Clear();
            }
        }
Ejemplo n.º 10
0
        protected override string SetCacheLock()
        {
            lock (LockObject)
            {
                if (CacheList.ContainsKey(Key))
                {
                    return(CacheList[Key]);
                }

                DbInfo dbInfo = Key;
                if (dbInfo == null)
                {
                    Log.LogManger.Log.Error("未设置数据库配置文件"); return(null);
                }
                CacheList.Add(Key, AbsDbProvider.CreateInstance(dbInfo.DataType, dbInfo.DataVer).CreateDbConnstring(dbInfo.Server, dbInfo.Port, dbInfo.UserID, dbInfo.PassWord, dbInfo.Catalog, dbInfo.DataVer, dbInfo.Additional, dbInfo.ConnectTimeout, dbInfo.PoolMinSize, dbInfo.PoolMaxSize));
            }

            return(CacheList[Key]);
        }
Ejemplo n.º 11
0
        /// <summary>
        ///     创建数据库连接字符串
        /// </summary>
        /// <param name="dbIndex">数据库配置</param>
        public static string CreateConnString(int dbIndex = 0)
        {
            if (ConnList.ContainsKey(dbIndex))
            {
                return(ConnList[dbIndex]);
            }
            lock (LockObject)
            {
                if (ConnList.ContainsKey(dbIndex))
                {
                    return(ConnList[dbIndex]);
                }

                DbInfo dbInfo = dbIndex;
                ConnList.Add(dbIndex, AbsDbProvider.CreateInstance(dbInfo.DataType).CreateDbConnstring(dbInfo.UserID, dbInfo.PassWord, dbInfo.Server, dbInfo.Catalog, dbInfo.DataVer, dbInfo.ConnectTimeout, dbInfo.PoolMinSize, dbInfo.PoolMaxSize, dbInfo.Port));
            }

            return(ConnList[dbIndex]);
        }
Ejemplo n.º 12
0
        /// <summary>
        ///     打开数据库连接
        /// </summary>
        private void Open()
        {
            if (_conn == null)
            {
                _factory             = AbsDbProvider.CreateInstance(DataType).DbProviderFactory;
                _comm                = _factory.CreateCommand();
                _comm.CommandTimeout = _commandTimeout;

                _conn = _factory.CreateConnection();
                _conn.ConnectionString = _connectionString;
                _comm.Connection       = _conn;
            }
            if (_conn.State == ConnectionState.Closed)
            {
                _conn.Open();
                _comm.Parameters.Clear();
                // 是否开启事务
                if (IsTransaction)
                {
                    _comm.Transaction = _conn.BeginTransaction(TranLevel);
                }
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        ///     打开数据库连接
        /// </summary>
        private void Open()
        {
            if (_comm == null || _comm.Connection == null)
            {
                _factory = AbsDbProvider.CreateInstance(DataType).DbProviderFactory;
                _comm    = _factory.CreateCommand();
                // ReSharper disable once PossibleNullReferenceException
                _comm.Connection = _factory.CreateConnection();
                _comm.Connection.ConnectionString = _connectionString;
                _comm.CommandTimeout = _commandTimeout;
            }

            if (_comm.Connection.State == ConnectionState.Closed)
            {
                _comm.Parameters.Clear();
                _comm.Connection.Open();

                // 是否开启事务
                if (IsTransaction)
                {
                    _comm.Transaction = _comm.Connection.BeginTransaction(TranLevel);
                }
            }
        }
Ejemplo n.º 14
0
 /// <summary>
 /// 默认构造器
 /// </summary>
 /// <param name="dbProvider">数据库提供者(不同数据库的特性)</param>
 /// <param name="map">字段映射</param>
 /// <param name="paramList">SQL参数列表</param>
 protected AbsSqlVisitor(AbsDbProvider dbProvider, FieldMap map, List <DbParameter> paramList)
 {
     DbProvider = dbProvider;
     Map        = map;
     ParamList  = paramList;
 }
Ejemplo n.º 15
0
 /// <summary>
 ///     Select筛选字段时表达式树的解析
 /// </summary>
 /// <param name="dbProvider">数据库提供者(不同数据库的特性)</param>
 /// <param name="map">字段映射</param>
 /// <param name="paramList">SQL参数列表</param>
 public WhereVisitor(AbsDbProvider dbProvider, SetDataMap map, List <DbParameter> paramList) : base(dbProvider, map, paramList)
 {
 }
Ejemplo n.º 16
0
 /// <summary>
 ///     默认构造器
 /// </summary>
 /// <param name="dbProvider">数据库提供者(不同数据库的特性)</param>
 /// <param name="map">字段映射</param>
 /// <param name="paramList">SQL参数列表</param>
 protected AbsSqlVisitor(AbsDbProvider dbProvider, SetDataMap map, List <DbParameter> paramList)
 {
     DbProvider = dbProvider;
     SetMap     = map;
     ParamList  = paramList;
 }
Ejemplo n.º 17
0
 /// <summary>
 ///     存储过程生成器
 /// </summary>
 /// <param name="dbProvider">数据库驱动</param>
 /// <param name="setMap">实体类映射</param>
 /// <param name="name">存储过程名称</param>
 internal ProcBuilder(AbsDbProvider dbProvider, SetDataMap setMap, string name)
 {
     _dbProvider = dbProvider;
     _setMap     = setMap;
     Name        = name;
 }
 /// <summary>
 ///     查询支持的SQL方法
 /// </summary>
 /// <param name="dbProvider">数据库提供者(不同数据库的特性)</param>
 /// <param name="expBuilder">表达式持久化</param>
 /// <param name="name">表名/视图名/存储过程名</param>
 internal SqlServer2000Builder(AbsDbProvider dbProvider, ExpressionBuilder expBuilder, string name) : base(dbProvider, expBuilder, name)
 {
 }
Ejemplo n.º 19
0
 /// <summary>
 /// 查询支持的SQL方法
 /// </summary>
 /// <param name="dbProvider">数据库提供者(不同数据库的特性)</param>
 /// <param name="expBuilder">表达式持久化</param>
 /// <param name="name">表名/视图名/存储过程名</param>
 public SqLiteSqlBuilder(AbsDbProvider dbProvider, ExpressionBuilder expBuilder, string name) : base(dbProvider, expBuilder, name)
 {
 }
Ejemplo n.º 20
0
 /// <summary>
 ///     提供字段插入表达式树的解析
 /// </summary>
 /// <param name="dbProvider">数据库提供者(不同数据库的特性)</param>
 /// <param name="map">字段映射</param>
 /// <param name="paramList">SQL参数列表</param>
 public InsertVisitor(AbsDbProvider dbProvider, SetDataMap map, List<DbParameter> paramList) : base(dbProvider, map, paramList)
 {
 }
Ejemplo n.º 21
0
 /// <summary>
 ///     查询支持的SQL方法
 /// </summary>
 /// <param name="dbProvider">数据库提供者(不同数据库的特性)</param>
 /// <param name="expBuilder">表达式持久化</param>
 /// <param name="name">表名/视图名/存储过程名</param>
 internal SqLiteBuilder(AbsDbProvider dbProvider, ExpressionBuilder expBuilder, string name) : base(dbProvider, expBuilder, name)
 {
 }
Ejemplo n.º 22
0
 /// <summary>
 /// 查询支持的SQL方法
 /// </summary>
 /// <param name="dbProvider">数据库提供者(不同数据库的特性)</param>
 /// <param name="expBuilder">表达式持久化</param>
 /// <param name="name">表名/视图名/存储过程名</param>
 public SqlServerSqlBuilder2000(AbsDbProvider dbProvider, ExpressionBuilder expBuilder, string name) : base(dbProvider, expBuilder, name)
 {
 }
Ejemplo n.º 23
0
 /// <summary>
 ///     查询支持的SQL方法
 /// </summary>
 /// <param name="dbProvider">数据库提供者(不同数据库的特性)</param>
 /// <param name="expBuilder">表达式持久化</param>
 /// <param name="name">表名/视图名/存储过程名</param>
 internal OracleBuilder(AbsDbProvider dbProvider, ExpressionBuilder expBuilder, string name) : base(dbProvider, expBuilder, name)
 {
 }
Ejemplo n.º 24
0
 /// <summary>
 /// 默认构造器
 /// </summary>
 /// <param name="dbProvider">数据库提供者(不同数据库的特性)</param>
 /// <param name="map">字段映射</param>
 /// <param name="paramList">SQL参数列表</param>
 public InsertVisitor(AbsDbProvider dbProvider, FieldMap map, List <DbParameter> paramList) : base(dbProvider, map, paramList)
 {
 }
Ejemplo n.º 25
0
 /// <summary>
 ///     默认构造器
 /// </summary>
 /// <param name="dbProvider">数据库提供者(不同数据库的特性)</param>
 /// <param name="map">字段映射</param>
 /// <param name="paramList">SQL参数列表</param>
 protected AbsSqlVisitor(AbsDbProvider dbProvider, SetDataMap map, List<DbParameter> paramList)
 {
     DbProvider = dbProvider;
     SetMap = map;
     ParamList = paramList;
 }
Ejemplo n.º 26
0
 /// <summary>
 ///     查询支持的SQL方法
 /// </summary>
 /// <param name="dbProvider">数据库提供者(不同数据库的特性)</param>
 /// <param name="expBuilder">表达式持久化</param>
 /// <param name="name">表名/视图名/存储过程名</param>
 internal PostgreSqlBuilder(AbsDbProvider dbProvider, ExpressionBuilder expBuilder, string name) : base(dbProvider, expBuilder, name)
 {
 }
Ejemplo n.º 27
0
 /// <summary>
 ///     查询支持的SQL方法
 /// </summary>
 /// <param name="dbProvider">数据库提供者(不同数据库的特性)</param>
 /// <param name="expBuilder">表达式持久化</param>
 /// <param name="name">表名/视图名/存储过程名</param>
 internal SqlServerBuilder(AbsDbProvider dbProvider, ExpressionBuilder expBuilder, string name) : base(dbProvider, expBuilder, name)
 {
 }
Ejemplo n.º 28
0
 /// <summary>
 ///     查询支持的SQL方法
 /// </summary>
 /// <param name="dbProvider">数据库提供者(不同数据库的特性)</param>
 /// <param name="expBuilder">表达式持久化</param>
 /// <param name="name">表名/视图名/存储过程名</param>
 internal OleDbSqlBuilder(AbsDbProvider dbProvider, ExpressionBuilder expBuilder, string name) : base(dbProvider, expBuilder, name)
 {
 }
 /// <summary>
 ///     Select筛选字段时表达式树的解析
 /// </summary>
 /// <param name="dbProvider">数据库提供者(不同数据库的特性)</param>
 /// <param name="map">字段映射</param>
 /// <param name="paramList">SQL参数列表</param>
 public OleDbWhereVisitor(AbsDbProvider dbProvider, SetDataMap map, List<DbParameter> paramList) : base(dbProvider, map, paramList)
 {
 }