Exemple #1
0
 public DbAdapter(DbDriverType driverType, IDbConnectionInfo connectionInfo)
 {
     Driver = DbDriverFactory.GetInstance(driverType);
     ConnectionInfo = connectionInfo;
     Connection = Driver.BuildConnection(ConnectionInfo);
     OpenConnection();
 }
Exemple #2
0
 public DbAdapter(DbDriverType driverType, IDbConnectionInfo connectionInfo)
 {
     Driver         = DbDriverFactory.GetInstance(driverType);
     ConnectionInfo = connectionInfo;
     Connection     = Driver.BuildConnection(ConnectionInfo);
     OpenConnection();
 }
Exemple #3
0
        /// <summary>
        /// 注册根据配置连接及指定驱动类型注册全局数据区厂对象,以便工厂直接创建数据库上下文
        /// 连接字符串已加密
        /// </summary>
        /// <param name="ConnectionStringKey">配置数据链接字符串健值,如果有多屋,则应如下:db:ConnStr</param>
        /// <param name="dbDriverType">指定驱动类型</param>
        /// <param name="Key">加密的密钥</param>
        /// <returns>返回应用注册对象,以便继续进行注册</returns>
        public IAppRegister RegGlobalDbContextForDecrypt(string ConnectionStringKey, DbDriverType dbDriverType, string Key = "")
        {
            string connstr = config.GetAppSetting(ConnectionStringKey).ToStringValue();

            Global.DbContextFactory = DbContextFactory.CreateFactory(connstr, dbDriverType);
            return(this);
        }
Exemple #4
0
 /// <summary>
 /// 注册日志组件,采用数据库保存方式
 /// </summary>
 /// <param name="type">日志类型</param>
 /// <param name="SqlConnectstring">数据库链接</param>
 /// <param name="LogTableName">日志保存表名</param>
 public static void RegisLogger(LogType type, string SqlConnectstring, string LogTableName, DbDriverType dbType = DbDriverType.SQLServer)
 {
     logType       = type;
     LogSaveType   = 1;
     SqlConnectStr = SqlConnectstring;
     logTable      = LogTableName;
     DBType        = dbType;
 }
Exemple #5
0
        /// <summary>
        /// 注册根据配置连接及指定驱动类型注册全局数据区厂对象,以便工厂直接创建数据库上下文
        /// 连接字符串未加密
        /// </summary>
        /// <param name="ConnectionStringKey">配置数据链接字符串健值,如果有多屋,则应如下:db:ConnStr</param>
        /// <param name="DbDriverTypeKey">指定驱动类型的配置键值</param>
        /// <returns>返回应用注册对象,以便继续进行注册</returns>
        public IAppRegister RegGlobalDbContext(string ConnectionStringKey, string DbDriverTypeKey)
        {
            string       connstr      = config.GetAppSetting(ConnectionStringKey).ToStringValue();
            DbDriverType dbDriverType = (DbDriverType)config.GetAppSetting(DbDriverTypeKey).ToInt();

            Global.DbContextFactory = DbContextFactory.CreateFactory(connstr, dbDriverType);
            return(this);
        }
Exemple #6
0
        public static IDbDriver GetInstance(DbDriverType driverType)
        {
            switch (driverType)
            {
            case DbDriverType.Postgres:
                return(new PostgresDriver());

            default:
                throw new ArgumentException(String.Format("Invalid DB Driver Type '{0}' specified!", driverType));
            }
        }
        public static IDbDriver GetInstance(DbDriverType driverType)
        {
            switch (driverType)
            {
                case DbDriverType.Postgres:
                    return new PostgresDriver();

                default:
                    throw new ArgumentException(String.Format("Invalid DB Driver Type '{0}' specified!", driverType));
            }
        }
Exemple #8
0
        public static string ToCreateTableScript(DbDriverType dbType, TableSchema tableSchema)
        {
            string result = "";

            if (dbType == DbDriverType.Mysql)
            {
                result = new MySqlDriver(null, "", "").ToCreateTableScript(tableSchema);
            }
            else if (dbType == DbDriverType.Oracle)
            {
                result = new OracleDriver(null, "", "").ToCreateTableScript(tableSchema);
            }
            else if (dbType == DbDriverType.Sqlite)
            {
                result = new SqliteDriver(null, "", "").ToCreateTableScript(tableSchema);
            }
            else
            {
                result = new SqlServer2000Driver(null, "", "").ToCreateTableScript(tableSchema);
            }

            return(result);
        }
 public DataTableDbWriter(DbDriverType driverType, IDbConnectionInfo connectionInfo, DbTableInitializationOptions tableInitializationOptions = default(DbTableInitializationOptions))
 {
     Adapter = new DbAdapter(driverType, connectionInfo);
     this.tableInitializationOptions = tableInitializationOptions;
 }
 public DataTableDbWriter(DbDriverType driverType, IDbConnectionInfo connectionInfo, DbTableInitializationOptions tableInitializationOptions = default(DbTableInitializationOptions))
 {
     Adapter = new DbAdapter(driverType, connectionInfo);
     this.tableInitializationOptions = tableInitializationOptions;
 }
Exemple #11
0
 /// <summary>
 /// 根据链接字符串和数据驱动类型创建数据工厂
 /// </summary>
 /// <param name="connStr">链接字符串</param>
 /// <param name="type">驱动类型</param>
 /// <returns>返回新建的工厂</returns>
 public static DbContextFactory CreateFactory(string connStr, DbDriverType type)
 {
     return(new DbContextFactory(connStr, type));
 }
Exemple #12
0
 /// <summary>
 /// 构造函数:创建系统指定驱动的数据访问对象信息
 /// </summary>
 /// <param name="connStr">数据库联接字符</param>
 /// <param name="type">数据库类型</param>
 private DbContextFactory(string connStr, DbDriverType type)
 {
     ConnectionString = connStr;
     DbDriverType     = type;
 }
Exemple #13
0
 /// <summary>
 /// 注册系统日志的类型
 /// </summary>
 /// <param name="TypeConfigKey"></param>
 /// <param name="SqlConnectstring"></param>
 /// <param name="LogTableName"></param>
 /// <param name="dbType"></param>
 /// <returns></returns>
 public IAppRegister RegDbLogger(string TypeConfigKey, string SqlConnectstring, string LogTableName, DbDriverType dbType = DbDriverType.SQLServer)
 {
     Loger.RegisLogger(LibHelper.GetAppSetting(TypeConfigKey), SqlConnectstring, LogTableName, dbType);
     return(this);
 }
Exemple #14
0
 /// <summary>
 /// 注册系统日志的类型
 /// </summary>
 /// <param name="type"></param>
 /// <param name="SqlConnectstring"></param>
 /// <param name="LogTableName"></param>
 /// <param name="dbType"></param>
 /// <returns></returns>
 public IAppRegister RegDbLogger(LogType type, string SqlConnectstring, string LogTableName, DbDriverType dbType = DbDriverType.SQLServer)
 {
     Loger.RegisLogger(type, SqlConnectstring, LogTableName, dbType);
     return(this);
 }
Exemple #15
0
        public static void RegisLogger(string TypeExp, string SqlConnectstring, string LogTableName, DbDriverType dbType = DbDriverType.SQLServer)
        {
            if (TypeExp.IsWhiteSpace())
            {
                logType = LogType.Error;
            }
            else if (TypeExp.ToUpper().Equals("ERROR"))
            {
                logType = LogType.Error;
            }
            else if (TypeExp.ToUpper().Equals("INFO"))
            {
                logType = LogType.Info;
            }
            else if (TypeExp.ToUpper().Equals("DEBUG"))
            {
                logType = LogType.Debug;
            }
            else if (TypeExp.ToUpper().Equals("WARN"))
            {
                logType = LogType.Warn;
            }
            else if (TypeExp.ToUpper().Equals("TRACE"))
            {
                logType = LogType.Trace;
            }
            else
            {
                logType = LogType.Error;
            }

            RegisLogger(logType, SqlConnectstring, LogTableName, dbType);
        }
Exemple #16
0
 public static void RegisLogger(string TypeExp, string SqlConnectstring, string LogTableName, DbDriverType dbType = DbDriverType.SQLServer)
 {
     Loger.RegisLogger(TypeExp, SqlConnectstring, LogTableName, dbType);
 }
Exemple #17
0
 /// <summary>
 /// 创建数据访问对象实例
 /// </summary>
 /// <returns></returns>
 public static IDbContext CreateDbUtil(string ConnectionString, DbDriverType type)
 {
     return(DbContextFactory.CreateFactory(ConnectionString, type).CreateContext());
 }