/// <summary> /// 以快速键值对照来获取 DbProviderFactory。 /// </summary> /// <param name="provider"></param> /// <returns></returns> public static DbProviderFactory GetFactory(string provider) { //ISqlConverter Factory switch (provider) { case DbSetting.Provider_SqlClient: if (_sql == null) { _sql = DbProviderFactories.GetFactory(DbSetting.Provider_SqlClient); } return(_sql); case DbSetting.Provider_SqlCe: if (_sqlCe == null) { _sqlCe = DbProviderFactories.GetFactory(DbSetting.Provider_SqlCe); } return(_sqlCe); default: if (DbSetting.IsOracleProvider(provider)) { if (_oracle == null) { _oracle = DbProviderFactories.GetFactory(provider); } return(_oracle); } return(DbProviderFactories.GetFactory(provider)); //throw new NotSupportedException("This type of database is not supportted now:" + provider); } }
public void DMT_RefreshComments() { using (var context = new RafyDbMigrationContext(UnitTestEntityRepositoryDataProvider.DbSettingName)) { context.RefreshComments(); if (context.DbSetting.ProviderName.Contains("MySql")) { //数据库数据 using (var db = DbAccesserFactory.Create(context.DbSetting)) { Func <string, DataRow[]> queryComments = tableName => { var table = db.QueryDataTable(@"show full columns from `" + tableName + "`"); return(table.Rows.Cast <DataRow>().ToArray()); }; var rows = queryComments("ARTICLE"); Assert.IsTrue(rows.Any(r => r["Field"].ToString() == "Id"), "实体的标识属性。"); Assert.IsTrue(rows.Any(r => r["Field"].ToString() == "AdministratorId"), "文章的管理员"); Assert.IsTrue(rows.Any(r => r["Field"].ToString() == "CreatedTime"), "实体的创建时间。"); rows = queryComments("Roles"); var roleTypeDesc = rows.FirstOrDefault(r => r["Field"].ToString() == "RoleType"); Assert.IsNotNull(roleTypeDesc, "枚举属性必须有注释。"); var comment = roleTypeDesc["Comment"].ToString(); Assert.AreEqual(comment, @"角色的类型 0:(Normal, 一般) 1:(Administrator, 管理员)"); } } else if (!DbSetting.IsOracleProvider(context.DbSetting)) { //数据库数据 using (var db = DbAccesserFactory.Create(context.DbSetting)) { Func <string, DataRow[]> queryComments = tableName => { var table = db.QueryDataTable(@"select t.name tableName, c.name columnName, p.Value Comment from sys.all_columns c join sys.tables t on c.object_id = t.object_id join sys.extended_properties p on p.major_id = c.object_id and p.minor_id = c.column_id where t.name = '" + tableName + "'"); return(table.Rows.Cast <DataRow>().ToArray()); }; var rows = queryComments("ARTICLE"); Assert.IsTrue(rows.Any(r => r["columnName"].ToString() == "Id"), "主键必须有注释。"); Assert.IsTrue(rows.Any(r => r["columnName"].ToString() == "AdministratorId"), "外键必须有注释。"); Assert.IsTrue(rows.Any(r => r["columnName"].ToString() == "CreatedTime"), "扩展属性必须有注释。"); rows = queryComments("Roles"); var roleTypeDesc = rows.FirstOrDefault(r => r["columnName"].ToString() == "RoleType"); Assert.IsNotNull(roleTypeDesc, "枚举属性必须有注释。"); var comment = roleTypeDesc["Comment"].ToString(); Assert.AreEqual(comment, @"角色的类型 0:(Normal, 一般) 1:(Administrator, 管理员)"); //WF_ 开头的动态属性。 } } } }
private void UnitTestPlugin_RuntimeStarting(object sender, EventArgs e) { var dbSetting = DbSetting.FindOrCreate(UnitTestEntityRepositoryDataProvider.DbSettingName); if (DbSetting.IsOracleProvider(dbSetting)) { OracleBatchImporter.EnableBatchSequence(RF.ResolveInstance <BookRepository>()); OracleBatchImporter.EnableBatchSequence(RF.ResolveInstance <InvoiceRepository>()); } }
public static void GenerateDb() { if (ConfigurationHelper.GetAppSettingOrDefault("单元测试-生成数据库", false)) { using (var c = new RafyDbMigrationContext(DbSettingNames.DbMigrationHistory)) { c.RunDataLossOperation = DataLossOperation.All; c.AutoMigrate(); } using (var c = new RafyDbMigrationContext(DbSettingNames.RafyPlugins)) { c.HistoryRepository = new DbHistoryRepository(); c.RunDataLossOperation = DataLossOperation.All; c.AutoMigrate(); } using (var c = new RafyDbMigrationContext(UnitTestEntityRepositoryDataProvider.DbSettingName)) { c.HistoryRepository = new DbHistoryRepository(); c.RunDataLossOperation = DataLossOperation.All; c.AutoMigrate(); } using (RdbDataProvider.RedirectDbSetting(UnitTestEntityRepositoryDataProvider.DbSettingName, UnitTestEntityRepositoryDataProvider.DbSettingName_Duplicate)) { using (var c = new RafyDbMigrationContext(UnitTestEntityRepositoryDataProvider.DbSettingName_Duplicate)) { c.ClassMetaReader.EntityDbSettingName = UnitTestEntityRepositoryDataProvider.DbSettingName; c.ClassMetaReader.IsGeneratingForeignKey = false; c.HistoryRepository = new DbHistoryRepository(); c.RunDataLossOperation = DataLossOperation.All; c.AutoMigrate(); } } using (var c = new RafyDbMigrationContext(UnitTest2EntityRepositoryDataProvider.DbSettingName)) { c.HistoryRepository = new DbHistoryRepository(); c.RunDataLossOperation = DataLossOperation.All; c.AutoMigrate(); } using (var c = new RafyDbMigrationContext(StringTestEntityDataProvider.DbSettingName)) { c.HistoryRepository = new DbHistoryRepository(); c.RunDataLossOperation = DataLossOperation.All; c.AutoMigrate(); } //启用批量更新 var dbSetting = DbSetting.FindOrCreate(UnitTestEntityRepositoryDataProvider.DbSettingName); if (DbSetting.IsOracleProvider(dbSetting)) { OracleBatchImporter.EnableBatchSequence(RF.ResolveInstance <BookRepository>()); OracleBatchImporter.EnableBatchSequence(RF.ResolveInstance <InvoiceRepository>()); } } }
private void CreateTable() { //不再使用 Date 类型,因为 Oracle 和 SQLServer 里面的数据的精度不一样。改为使用 LONG //Oracle 中的 DateTime 类型为 Date var timeType = DbSetting.IsOracleProvider(this.DbSetting) ? OracleDbTypeHelper.ConvertToOracleTypeString(DbType.Int64) : SqlDbTypeHelper.ConvertToSQLTypeString(DbType.Int64); this.DBA.RawAccesser.ExecuteText(string.Format(@"CREATE TABLE {1}(ID INT NOT NULL,Value {0} NOT NULL,PRIMARY KEY (ID))", timeType, TableName)); this.DBA.ExecuteText("INSERT INTO " + TableName + " (ID,VALUE) VALUES (1, {0})", DefaultMinTime.Ticks); }
private void UnitTestPlugin_RuntimeStarting(object sender, EventArgs e) { var dbSetting = DbSetting.FindOrCreate(UnitTestEntityRepositoryDataProvider.DbSettingName); if (DbSetting.IsOracleProvider(dbSetting)) { Rafy.Domain.ORM.BatchSubmit.Oracle.OracleBatchImporter.EnableBatchSequence( RF.Concrete <BookRepository>() ); } }
//private void UnitTestPlugin_RuntimeStarting(object sender, EventArgs e) //{ // InitailizeSequences(); //} public static void InitailizeSequences() { var dbSetting = DbSetting.FindOrCreate(UnitTestEntityRepositoryDataProvider.DbSettingName); if (DbSetting.IsOracleProvider(dbSetting)) { OracleBatchImporter.EnableBatchSequence(RF.ResolveInstance <BookCategoryRepository>()); OracleBatchImporter.EnableBatchSequence(RF.ResolveInstance <FolderRepository>()); OracleBatchImporter.EnableBatchSequence(RF.ResolveInstance <BookRepository>()); OracleBatchImporter.EnableBatchSequence(RF.ResolveInstance <InvoiceRepository>()); } }
/// <summary> /// 根据数据库配置来创建对应数据库的批量导入器。 /// </summary> /// <param name="setting"></param> /// <returns></returns> public static IBatchImporter CreateImporter(DbSetting setting) { switch (setting.ProviderName) { case DbSetting.Provider_SqlClient: return(new SqlBatchImporter()); default: if (DbSetting.IsOracleProvider(setting)) { return(new OracleBatchImporter()); } throw new NotSupportedException("目前不支持该类型数据库的批量导入:" + setting.ProviderName); } }
/// <summary> /// 配置实体的元数据 /// </summary> protected override void ConfigMeta() { //配置实体的所有属性都映射到数据表中。 Meta.MapTable().MapAllProperties(); //Id 属性不再是主键,主键改为 Name 属性。 var setting = DbSetting.FindOrCreate(UnitTestEntityRepositoryDataProvider.DbSettingName); Meta.Property(Building.NameProperty).MapColumn().IsPrimaryKey(true); var idColumn = Meta.Property(Building.IdProperty).MapColumn().IsPrimaryKey(false); if (DbSetting.IsOracleProvider(setting) || setting.ProviderName.Contains("MySql")) { idColumn.IsIdentity(false); } }
public virtual List <OrganizationNotTree> GetByOrgIdAndUserNameContainChild(long orgId, string userName = "") { FormattedSql sql = new FormattedSql(); var dbSettingName = RBACPlugin.DbSettingName; var dbSetting = DbSetting.FindOrCreate(dbSettingName); if (DbSetting.IsOracleProvider(dbSetting)) { sql = @"select oorg.Id,oorg.Name from T_RBAC_ORGANIZATION oorg LEFT JOIN T_RBAC_OrganizationUser ou on(oorg.id = ou.organizationid and ou.dbi_isphantom = 0) LEFT JOIN T_Users u on(u.id = ou.userid and u.dbi_isphantom = 0) where(oorg.dbi_isphantom = 0 or oorg.dbi_isphantom is null) and oorg.wf_approvalstatus = 300 and oorg.treeindex like (select treeindex || '%' from T_RBAC_ORGANIZATION org where org.id = {0}) "; } else { sql = @"select oorg.Id,oorg.Name from T_RBAC_ORGANIZATION oorg LEFT JOIN T_RBAC_OrganizationUser ou on(oorg.id = ou.organizationid and ou.dbi_isphantom = 0) LEFT JOIN T_Users u on(u.id = ou.userid and u.dbi_isphantom = 0) where(oorg.dbi_isphantom = 0 or oorg.dbi_isphantom is null) and oorg.wf_approvalstatus = 300 and oorg.treeindex like (select treeindex + '%' from T_RBAC_ORGANIZATION org where org.id = {0}) "; } if (!string.IsNullOrEmpty(userName)) { sql.Append(string.Format("and u.username = '******' ", userName)); } sql.Parameters.Add(orgId); LiteDataTable dt = (this.DataQueryer as RdbDataQueryer).QueryTable(sql); List <OrganizationNotTree> result = new List <OrganizationNotTree>(); if (dt != null && dt.Rows.Count > 0) { foreach (var row in dt.Rows) { result.Add(new OrganizationNotTree { Id = Convert.ToInt64(row["Id"]), Name = Convert.ToString(row["Name"]) }); } } return(result); //return (OrganizationList)(this.DataQueryer as RdbDataQueryer).QueryData(sql); }
public void DMT_CreateColumn_CLOB() { if (DbSetting.IsOracleProvider(UnitTest2EntityRepositoryDataProvider.DbSettingName)) { this.Test(destination => { var taskTable = destination.FindTable("Task"); taskTable.AddColumn("TestingColumn", DbType.String, "CLOB", isRequired: true); }, result => { var taskTable = result.FindTable("Task"); var c1 = taskTable.FindColumn("TestingColumn"); Assert.IsTrue(c1 != null && c1.IsRequired); Assert.IsTrue(dbTypeConverter.IsCompatible(c1.DbType, DbType.String)); }); } }
/// <summary> /// 创建指定的链接字符串的转换器 /// </summary> /// <param name="provider">指定的数据库的提供程序</param> /// <returns>返回针对指定数据库的 ISqlProvider 类型的具体对象实例</returns> public static ISqlProvider Create(string provider) { //ISqlConverter Factory switch (provider) { case DbSetting.Provider_Odbc: if (_odbcConverter == null) { _odbcConverter = new ODBCProvider(); } return(_odbcConverter); case DbSetting.Provider_SqlClient: case DbSetting.Provider_SqlCe: case DbSetting.Provider_SQLite: if (_sqlConverter == null) { _sqlConverter = new SqlServerProvider(); } return(_sqlConverter); //PatrickLiu 增加的有关 MySql 的代码 case DbSetting.Provider_MySql: if (_mySqlConverter == null) { _mySqlConverter = new MySqlServerProvider(); } return(_mySqlConverter); default: if (DbSetting.IsOracleProvider(provider)) { if (_oracleConverter == null) { _oracleConverter = new OracleProvider(); } return(_oracleConverter); } if (_sqlConverter == null) { _sqlConverter = new SqlServerProvider(); } return(_sqlConverter); } }
public void DMT_RefreshComments() { using (var context = new RafyDbMigrationContext(UnitTestEntityRepositoryDataProvider.DbSettingName)) { context.RefreshComments(); if (!DbSetting.IsOracleProvider(context.DbSetting)) { //数据库数据 using (var db = DbAccesserFactory.Create(context.DbSetting)) { var rowsCount = Convert.ToInt32(db.QueryValue( @"select COUNT(0) from sys.extended_properties p join sys.tables t on p.major_id = t.object_id where t.name = 'ARTICLE'")); Assert.IsTrue(rowsCount > 0); } } } }
public static void GenerateDb() { if (ConfigurationHelper.GetAppSettingOrDefault("单元测试-生成数据库", false)) { using (var c = new RafyDbMigrationContext(DbSettingNames.DbMigrationHistory)) { c.RunDataLossOperation = DataLossOperation.All; c.AutoMigrate(); } using (var c = new RafyDbMigrationContext(DbSettingNames.RafyPlugins)) { c.HistoryRepository = new DbHistoryRepository(); c.RunDataLossOperation = DataLossOperation.All; c.AutoMigrate(); } using (var c = new RafyDbMigrationContext(UnitTestEntityRepositoryDataProvider.DbSettingName)) { c.HistoryRepository = new DbHistoryRepository(); c.RunDataLossOperation = DataLossOperation.All; c.AutoMigrate(); } using (var c = new RafyDbMigrationContext(UnitTest2EntityRepositoryDataProvider.DbSettingName)) { c.HistoryRepository = new DbHistoryRepository(); c.RunDataLossOperation = DataLossOperation.All; c.AutoMigrate(); } using (var c = new RafyDbMigrationContext(StringTestEntityDataProvider.DbSettingName)) { c.HistoryRepository = new DbHistoryRepository(); c.RunDataLossOperation = DataLossOperation.All; c.AutoMigrate(); } //启用批量更新 var dbSetting = DbSetting.FindOrCreate(UnitTestEntityRepositoryDataProvider.DbSettingName); if (DbSetting.IsOracleProvider(dbSetting)) { OracleBatchImporter.EnableBatchSequence(RF.Concrete <BookRepository>()); } } }
/// <summary> /// 以快速键值对照来获取 DbProviderFactory。 /// </summary> /// <param name="provider"></param> /// <returns>返回DbProviderFactory类型的具体对象实例</returns> public static DbProviderFactory GetFactory(string provider) { switch (provider) { case DbSetting.Provider_SqlClient: if (_sql == null) { #if NET45 _sql = DbProviderFactories.GetFactory(DbSetting.Provider_SqlClient); #endif #if NS2 _sql = LoadFromAssembly("System.Data.SqlClient.SqlClientFactory, System.Data.SqlClient"); //_sql = System.Data.SqlClient.SqlClientFactory.Instance; #endif } return(_sql); case DbSetting.Provider_SQLite: if (_sqlite == null) { _sqlite = LoadFromAssembly("System.Data.SQLite.SQLiteFactory, System.Data.SQLite"); } return(_sqlite); case DbSetting.Provider_SqlCe: if (_sqlCe == null) { #if NET45 _sqlCe = DbProviderFactories.GetFactory(DbSetting.Provider_SqlCe); #endif #if NS2 _sqlCe = LoadFromAssembly("System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe"); //_sqlCe = System.Data.SqlServerCe.SqlCeProviderFactory.Instance; #endif } return(_sqlCe); case DbSetting.Provider_MySql: if (_mySql == null) { #if NET45 _mySql = DbProviderFactories.GetFactory(DbSetting.Provider_MySql); #endif #if NS2 _mySql = LoadFromAssembly("MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data"); //_mySql = MySql.Data.MySqlClient.MySqlClientFactory.Instance; #endif } return(_mySql); default: if (DbSetting.IsOracleProvider(provider)) { if (_oracle == null) { #if NET45 _oracle = DbProviderFactories.GetFactory(provider); #endif #if NS2 _oracle = LoadFromAssembly("Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess"); //_oracle = Oracle.ManagedDataAccess.Client.OracleClientFactory.Instance; #endif } return(_oracle); } #if NET45 return(DbProviderFactories.GetFactory(provider)); #endif #if NS2 return(System.Data.SqlClient.SqlClientFactory.Instance); #endif //throw new NotSupportedException("This type of database is not supportted now:" + provider); } }