Skip to content

Commit 9dfb09d

Browse files
committed
Apply workaround for Oracle lack of native Int support
1 parent ac97538 commit 9dfb09d

File tree

1 file changed

+51
-29
lines changed

1 file changed

+51
-29
lines changed

Orm/Xtensive.Orm.Tests/Storage/IgnoreRulesValidateTest.cs

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ public void IgnoreSimpleColumnTest()
309309

310310
var catalog = GetCatalog();
311311
var schema = catalog.DefaultSchema.Name;
312-
CreateColumn(catalog, schema, "MyEntity2", "SimpleIgnoredColumn", new SqlValueType(SqlType.Int32));
312+
CreateColumn(catalog, schema, "MyEntity2", "SimpleIgnoredColumn", GetTypeForInteger(SqlType.Int32));
313313
var ignoreRuleCollection = new IgnoreRuleCollection();
314314
_ = ignoreRuleCollection.IgnoreColumn("SimpleIgnoredColumn").WhenTable("MyEntity2");
315315

@@ -325,7 +325,7 @@ public void IgnoreReferencedColumnTest()
325325

326326
var catalog = GetCatalog();
327327
var schema = catalog.DefaultSchema.Name;
328-
CreateColumn(catalog, schema, "MyEntity2", "ReferencedIgnoredColumn", new SqlValueType(SqlType.Int64));
328+
CreateColumn(catalog, schema, "MyEntity2", "ReferencedIgnoredColumn", GetTypeForInteger(SqlType.Int64));
329329
CreateForeignKeyInDb(catalog, schema, "MyEntity2", "ReferencedIgnoredColumn", "MyEntity1", "Id", "FK_MyEntity1_MyEntity1ID");
330330
var ignoreRuleCollection = new IgnoreRuleCollection();
331331
_ = ignoreRuleCollection.IgnoreColumn("ReferencedIgnoredColumn").WhenTable("MyEntity2").WhenSchema(schema);
@@ -341,7 +341,7 @@ public void IgnoreSimpleTableTest()
341341
var catalog = GetCatalog();
342342
var schema = catalog.DefaultSchema.Name;
343343
var addedColumnsNames = new[] { "Id", "FirstColumn" };
344-
var addedColumnsTypes = new[] { new SqlValueType(SqlType.Int32), new SqlValueType(SqlType.Int64) };
344+
var addedColumnsTypes = new[] { GetTypeForInteger(SqlType.Int32), GetTypeForInteger(SqlType.Int64) };
345345

346346
if (createConstraintsWithTable) {
347347
var delayedOp = CreateTableDelayed(catalog, schema, "MyIgnoredEntity", addedColumnsNames, addedColumnsTypes);
@@ -366,7 +366,7 @@ public void IgnoreReferencedTableTest()
366366
var catalog = GetCatalog();
367367
var schema = catalog.DefaultSchema.Name;
368368
var addedColumnsNames = new[] { "Id", "FirstColumn", "MyEntity2Id" };
369-
var addedColumnsTypes = new[] { new SqlValueType(SqlType.Int32), new SqlValueType(SqlType.Int64), new SqlValueType(SqlType.Int64) };
369+
var addedColumnsTypes = new[] { GetTypeForInteger(SqlType.Int32), GetTypeForInteger(SqlType.Int64), GetTypeForInteger(SqlType.Int64) };
370370

371371
if (createConstraintsWithTable) {
372372
var delayedOp = CreateTableDelayed(catalog, schema, "MyIgnoredEntity", addedColumnsNames, addedColumnsTypes);
@@ -393,7 +393,7 @@ public void InsertIntoTableWithIgnoredColumnTest()
393393

394394
var catalog = GetCatalog();
395395
var schema = catalog.DefaultSchema.Name;
396-
CreateColumn(catalog, schema, "Myentity2", "SimpleIgnoredColumn", new SqlValueType(SqlType.Int64));
396+
CreateColumn(catalog, schema, "Myentity2", "SimpleIgnoredColumn", GetTypeForInteger(SqlType.Int64));
397397
var ignoreRuleCollection = new IgnoreRuleCollection();
398398
_ = ignoreRuleCollection.IgnoreColumn("SimpleIgnoredColumn").WhenTable("MyEntity2");
399399

@@ -416,7 +416,7 @@ public void InsertIntoTableWithNotNullableIgnoredColumnTest()
416416
var catalog = GetCatalog();
417417
var schema = catalog.Schemas[catalog.DefaultSchema.Name] ?? catalog.Schemas[0];
418418

419-
schema.Tables["MyEntity2"].CreateColumn("SimpleIgnoredColumn", new SqlValueType(SqlType.Int64)).IsNullable = false;
419+
schema.Tables["MyEntity2"].CreateColumn("SimpleIgnoredColumn", GetTypeForInteger(SqlType.Int64)).IsNullable = false;
420420

421421
var alter = SqlDdl.Alter(schema.Tables["MyEntity2"],
422422
SqlDdl.AddColumn(schema.Tables["MyEntity2"].TableColumns["SimpleIgnoredColumn"]));
@@ -443,7 +443,7 @@ public void DropTableWithIgnoredColumnTest()
443443

444444
var catalog = GetCatalog();
445445
var schema = catalog.DefaultSchema.Name;
446-
CreateColumn(catalog, schema, "MyEntity2", "SimpleIgnoredColumn", new SqlValueType(SqlType.Int64));
446+
CreateColumn(catalog, schema, "MyEntity2", "SimpleIgnoredColumn", GetTypeForInteger(SqlType.Int64));
447447

448448
var ignoreRuleCollection = new IgnoreRuleCollection();
449449
_ = ignoreRuleCollection.IgnoreColumn("SimpleIgnoredColumn").WhenTable("MyEntity2");
@@ -462,7 +462,7 @@ public void DropReferencedTableTest()
462462

463463
var catalog = GetCatalog();
464464
var schema = catalog.DefaultSchema.Name;
465-
CreateColumn(catalog, schema, "MyEntity2", "ReferencedIgnoredColumn", new SqlValueType(SqlType.Int64));
465+
CreateColumn(catalog, schema, "MyEntity2", "ReferencedIgnoredColumn", GetTypeForInteger(SqlType.Int64));
466466
CreateForeignKeyInDb(catalog, schema, "MyEntity2", "ReferencedIgnoredColumn", "MyEntity1", "Id", "FK_MyEntity1_MyEntity1ID");
467467

468468
var ignoreRuleCollection = new IgnoreRuleCollection();
@@ -480,9 +480,9 @@ public void IgnoreColumnsByMaskValidateTest()
480480

481481
var catalog = GetCatalog();
482482
var schema = catalog.DefaultSchema.Name;
483-
CreateColumn(catalog, schema, "MyEntity2", "IgnoreFirstColumn", new SqlValueType(SqlType.Int64));
484-
CreateColumn(catalog, schema, "MyEntity2", "IgnoreSecondColumn", new SqlValueType(SqlType.Int64));
485-
CreateColumn(catalog, schema, "MyEntity2", "IgnoreThirdColumn", new SqlValueType(SqlType.Int64));
483+
CreateColumn(catalog, schema, "MyEntity2", "IgnoreFirstColumn", GetTypeForInteger(SqlType.Int64));
484+
CreateColumn(catalog, schema, "MyEntity2", "IgnoreSecondColumn", GetTypeForInteger(SqlType.Int64));
485+
CreateColumn(catalog, schema, "MyEntity2", "IgnoreThirdColumn", GetTypeForInteger(SqlType.Int64));
486486
var ignoreRules = new IgnoreRuleCollection();
487487
_ = ignoreRules.IgnoreColumn("Ignore*");
488488

@@ -497,7 +497,7 @@ public void IgnoreTablesByMaskValidateTest()
497497
var catalog = GetCatalog();
498498
var schema = catalog.DefaultSchema.Name;
499499
var addedColumnsNames = new[] { "Id", "FirstColumn", "SecondColumn" };
500-
var addedColumnsTypes = new[] { new SqlValueType(SqlType.Int64), new SqlValueType(SqlType.Int64), new SqlValueType(SqlType.Int64) };
500+
var addedColumnsTypes = new[] { GetTypeForInteger(SqlType.Int64), GetTypeForInteger(SqlType.Int64), GetTypeForInteger(SqlType.Int64) };
501501

502502
if (createConstraintsWithTable) {
503503
var delayedOp = CreateTableDelayed(catalog, schema, "IgnoredFirstTable", addedColumnsNames, addedColumnsTypes);
@@ -529,7 +529,7 @@ public void IgnoreAllColumnsInTableByMaskValidateTest()
529529
var catalog = GetCatalog();
530530
var schema = catalog.DefaultSchema.Name;
531531
var addedColumnsNames = new[] { "Id", "FirstColumn", "SecondColumn" };
532-
var addedColumnsTypes = new[] { new SqlValueType(SqlType.Int64), new SqlValueType(SqlType.Int64), new SqlValueType(SqlType.Int64) };
532+
var addedColumnsTypes = new[] { GetTypeForInteger(SqlType.Int64), GetTypeForInteger(SqlType.Int64), GetTypeForInteger(SqlType.Int64) };
533533

534534
if (createConstraintsWithTable) {
535535
var delayedOp = CreateTableDelayed(catalog, schema, "IgnoredTable", addedColumnsNames, addedColumnsTypes);
@@ -554,8 +554,8 @@ public void UpgradeDomainWithIgnoreRuleByMaskInPerformModeTest()
554554
var catalog = GetCatalog();
555555
var schema = catalog.Schemas[catalog.DefaultSchema.Name] ?? catalog.Schemas[0];
556556

557-
CreateColumn(catalog, schema.Name, "MyEntity2", "IgnoredFirstColumn", new SqlValueType(SqlType.Int64));
558-
CreateColumn(catalog, schema.Name, "MyEntity2", "IgnoredSecondColumn", new SqlValueType(SqlType.Int64));
557+
CreateColumn(catalog, schema.Name, "MyEntity2", "IgnoredFirstColumn", GetTypeForInteger(SqlType.Int64));
558+
CreateColumn(catalog, schema.Name, "MyEntity2", "IgnoredSecondColumn", GetTypeForInteger(SqlType.Int64));
559559

560560
var ignoreRules = new IgnoreRuleCollection();
561561
_ = ignoreRules.IgnoreColumn("Ignored*").WhenTable("MyEntity2");
@@ -583,8 +583,8 @@ public void UpgradeDomainWithIgnoreRuleByMaskInPerformSafelyModeTest()
583583

584584
var catalog = GetCatalog();
585585
var schema = catalog.Schemas[catalog.DefaultSchema.Name] ?? catalog.Schemas[0];
586-
CreateColumn(catalog, schema.Name, "MyEntity2", "IgnoredFirstColumn", new SqlValueType(SqlType.Int64));
587-
CreateColumn(catalog, schema.Name, "MyEntity2", "IgnoredSecondColumn", new SqlValueType(SqlType.Int64));
586+
CreateColumn(catalog, schema.Name, "MyEntity2", "IgnoredFirstColumn", GetTypeForInteger(SqlType.Int64));
587+
CreateColumn(catalog, schema.Name, "MyEntity2", "IgnoredSecondColumn", GetTypeForInteger(SqlType.Int64));
588588

589589
var ignoreRules = new IgnoreRuleCollection();
590590
_ = ignoreRules.IgnoreColumn("Ignored*");
@@ -619,11 +619,11 @@ public void MultischemaValidateTest()
619619
BuildComplexDomain(DomainUpgradeMode.Recreate, null, new[] { typeof(Model1.Customer) }, new[] { typeof(Model3.MyEntity1) }).Dispose();
620620

621621
catalog = GetCatalog();
622-
CreateColumn(catalog, Schema2, "MyEntity2", "ReferencedIgnoredColumn", new SqlValueType(SqlType.Int64));
622+
CreateColumn(catalog, Schema2, "MyEntity2", "ReferencedIgnoredColumn", GetTypeForInteger(SqlType.Int64));
623623
CreateForeignKeyInDb(catalog, Schema2, "MyEntity2", "ReferencedIgnoredColumn", "MyEntity1", "Id", "FK_MyEntity2_MyEntity1_MyEntity1ID");
624624

625625
var addedColumnsNames = new[] { "Id", "FirstColumn", "MyEntity2Id" };
626-
var addedColumnsTypes = new[] { new SqlValueType(SqlType.Int32), new SqlValueType(SqlType.Int64), new SqlValueType(SqlType.Int64) };
626+
var addedColumnsTypes = new[] { GetTypeForInteger(SqlType.Int32), GetTypeForInteger(SqlType.Int64), GetTypeForInteger(SqlType.Int64) };
627627
CreateTable(catalog, Schema2, "MyIgnoredEntity", addedColumnsNames, addedColumnsTypes);
628628
CreatePrimaryKeyInDb(catalog, Schema2, "MyIgnoredEntity", "Id", "PK_MyIgnoreTable_Id");
629629
CreateForeignKeyInDb(catalog, Schema2, "MyIgnoredEntity", "MyEntity2Id", "MyEntity2", "Id", "FK_MyIgnoredEntity_MyEntity2_Id");
@@ -648,11 +648,11 @@ public void MultidatabaseValidateTest()
648648
BuildComplexDomain(DomainUpgradeMode.Recreate, null, new[] { typeof(Model1.Customer) }, new[] { typeof(Model3.MyEntity1) }).Dispose();
649649

650650
var secondCatalog = GetCatalog(Multimapping.MultidatabaseTest.Database2Name);
651-
CreateColumn(secondCatalog, defaultSchema, "MyEntity2", "ReferencedIgnoredColumn", new SqlValueType(SqlType.Int64), true);
651+
CreateColumn(secondCatalog, defaultSchema, "MyEntity2", "ReferencedIgnoredColumn", GetTypeForInteger(SqlType.Int64), true);
652652
CreateForeignKeyInDb(secondCatalog, defaultSchema, "MyEntity2", "ReferencedIgnoredColumn", "MyEntity1", "Id", "FK_MyEntity2_MyEntity1_MyEntity1ID", true);
653653

654654
var addedColumnsNames = new[] { "Id", "FirstColumn", "MyEntity2Id" };
655-
var addedColumnsTypes = new[] { new SqlValueType(SqlType.Int32), new SqlValueType(SqlType.Int64), new SqlValueType(SqlType.Int64) };
655+
var addedColumnsTypes = new[] { GetTypeForInteger(SqlType.Int32), GetTypeForInteger(SqlType.Int64), GetTypeForInteger(SqlType.Int64) };
656656
CreateTable(secondCatalog, defaultSchema, "MyIgnoredEntity", addedColumnsNames, addedColumnsTypes, true);
657657
CreatePrimaryKeyInDb(secondCatalog, defaultSchema, "MyIgnoredEntity", "Id", "PK_MyIgnoreTable_Id", true);
658658
CreateForeignKeyInDb(secondCatalog, defaultSchema, "MyIgnoredEntity", "MyEntity2Id", "MyEntity2", "Id", "FK_MyIgnoredEntity_MyEntity2_Id", true);
@@ -680,11 +680,11 @@ public void MultischemaUpgrageInPerformModeTest()
680680
BuildDomainAndFillData();
681681

682682
catalog = GetCatalog();
683-
CreateColumn(catalog, Schema2, "MyEntity2", "ReferencedIgnoredColumn", new SqlValueType(SqlType.Int64));
683+
CreateColumn(catalog, Schema2, "MyEntity2", "ReferencedIgnoredColumn", GetTypeForInteger(SqlType.Int64));
684684
CreateForeignKeyInDb(catalog, Schema2, "MyEntity2", "ReferencedIgnoredColumn", "MyEntity1", "Id", "FK_MyEntity2_MyEntity1_MyEntity1ID");
685685

686686
var addedColumnsNames = new[] { "Id", "FirstColumn", "MyEntity2Id" };
687-
var addedColumnsTypes = new[] { new SqlValueType(SqlType.Int32), new SqlValueType(SqlType.Int64), new SqlValueType(SqlType.Int64) };
687+
var addedColumnsTypes = new[] { GetTypeForInteger(SqlType.Int32), GetTypeForInteger(SqlType.Int64), GetTypeForInteger(SqlType.Int64) };
688688
CreateTable(catalog, Schema2, "MyIgnoredEntity", addedColumnsNames, addedColumnsTypes);
689689
CreatePrimaryKeyInDb(catalog, Schema2, "MyIgnoredEntity", "Id", "PK_MyIgnoreTable_Id");
690690
CreateForeignKeyInDb(catalog, Schema2, "MyIgnoredEntity", "MyEntity2Id", "MyEntity2", "Id", "FK_MyIgnoredEntity_MyEntity2_Id");
@@ -717,11 +717,11 @@ public void MultischemaUpgrageInPerformSafelyModeTest()
717717
BuildDomainAndFillData();
718718

719719
catalog = GetCatalog();
720-
CreateColumn(catalog, Schema2, "MyEntity2", "ReferencedIgnoredColumn", new SqlValueType(SqlType.Int64));
720+
CreateColumn(catalog, Schema2, "MyEntity2", "ReferencedIgnoredColumn", GetTypeForInteger(SqlType.Int64));
721721
CreateForeignKeyInDb(catalog, Schema2, "MyEntity2", "ReferencedIgnoredColumn", "MyEntity1", "Id", "FK_MyEntity2_MyEntity1_MyEntity1ID");
722722

723723
var addedColumnsNames = new[] { "Id", "FirstColumn", "MyEntity2Id" };
724-
var addedColumnsTypes = new[] { new SqlValueType(SqlType.Int32), new SqlValueType(SqlType.Int64), new SqlValueType(SqlType.Int64) };
724+
var addedColumnsTypes = new[] { GetTypeForInteger(SqlType.Int32), GetTypeForInteger(SqlType.Int64), GetTypeForInteger(SqlType.Int64) };
725725
CreateTable(catalog, Schema2, "MyIgnoredEntity", addedColumnsNames, addedColumnsTypes);
726726
CreatePrimaryKeyInDb(catalog, Schema2, "MyIgnoredEntity", "Id", "PK_MyIgnoreTable_Id");
727727
CreateForeignKeyInDb(catalog, Schema2, "MyIgnoredEntity", "MyEntity2Id", "MyEntity2", "Id", "FK_MyIgnoredEntity_MyEntity2_Id");
@@ -751,11 +751,11 @@ public void MultidatabaseUpgradeInPerformModeTest()
751751
BuildDomainAndFillData();
752752

753753
var secondCatalog = GetCatalog(Multimapping.MultidatabaseTest.Database2Name);
754-
CreateColumn(secondCatalog, defaultSchema, "MyEntity2", "ReferencedIgnoredColumn", new SqlValueType(SqlType.Int64), true);
754+
CreateColumn(secondCatalog, defaultSchema, "MyEntity2", "ReferencedIgnoredColumn", GetTypeForInteger(SqlType.Int64), true);
755755
CreateForeignKeyInDb(secondCatalog, defaultSchema, "MyEntity2", "ReferencedIgnoredColumn", "MyEntity1", "Id", "FK_MyEntity2_MyEntity1_MyEntity1ID", true);
756756

757757
var addedColumnsNames = new[] { "Id", "FirstColumn", "MyEntity2Id" };
758-
var addedColumnsTypes = new[] { new SqlValueType(SqlType.Int32), new SqlValueType(SqlType.Int64), new SqlValueType(SqlType.Int64) };
758+
var addedColumnsTypes = new[] { GetTypeForInteger(SqlType.Int32), GetTypeForInteger(SqlType.Int64), GetTypeForInteger(SqlType.Int64) };
759759
CreateTable(secondCatalog, defaultSchema, "MyIgnoredEntity", addedColumnsNames, addedColumnsTypes, true);
760760
CreatePrimaryKeyInDb(secondCatalog, defaultSchema, "MyIgnoredEntity", "Id", "PK_MyIgnoreTable_Id", true);
761761
CreateForeignKeyInDb(secondCatalog, defaultSchema, "MyIgnoredEntity", "MyEntity2Id", "MyEntity2", "Id", "FK_MyIgnoredEntity_MyEntity2_Id", true);
@@ -784,10 +784,10 @@ public void MultidatabaseUpgradeInPerformSafelyModeTest()
784784
BuildDomainAndFillData();
785785

786786
var secondCatalog = GetCatalog(Multimapping.MultidatabaseTest.Database2Name);
787-
CreateColumn(secondCatalog, defaultSchema, "MyEntity2", "ReferencedIgnoredColumn", new SqlValueType(SqlType.Int64), true);
787+
CreateColumn(secondCatalog, defaultSchema, "MyEntity2", "ReferencedIgnoredColumn", GetTypeForInteger(SqlType.Int64), true);
788788
CreateForeignKeyInDb(secondCatalog, defaultSchema, "MyEntity2", "ReferencedIgnoredColumn", "MyEntity1", "Id", "FK_MyEntity2_MyEntity1_MyEntity1ID", true);
789789
var addedColumnsNames = new[] { "Id", "FirstColumn", "MyEntity2Id" };
790-
var addedColumnsTypes = new[] { new SqlValueType(SqlType.Int32), new SqlValueType(SqlType.Int64), new SqlValueType(SqlType.Int64) };
790+
var addedColumnsTypes = new[] { GetTypeForInteger(SqlType.Int32), GetTypeForInteger(SqlType.Int64), GetTypeForInteger(SqlType.Int64) };
791791
CreateTable(secondCatalog, defaultSchema, "MyIgnoredEntity", addedColumnsNames, addedColumnsTypes, true);
792792
CreatePrimaryKeyInDb(secondCatalog, defaultSchema, "MyIgnoredEntity", "Id", "PK_MyIgnoreTable_Id", true);
793793
CreateForeignKeyInDb(secondCatalog, defaultSchema, "MyIgnoredEntity", "MyEntity2Id", "MyEntity2", "Id", "FK_MyIgnoredEntity_MyEntity2_Id", true);
@@ -1130,5 +1130,27 @@ private void ClearMultidatabaseAndMultischemaFlags()
11301130
isMultidatabaseTest = false;
11311131
isMultischemaTest = false;
11321132
}
1133+
1134+
private SqlValueType GetTypeForInteger(SqlType sqlType)
1135+
{
1136+
if (!StorageProviderInfo.Instance.CheckProviderIs(StorageProvider.Oracle)) {
1137+
return new SqlValueType(sqlType);
1138+
}
1139+
1140+
const int ShortPrecision = 5;
1141+
const int IntPrecision = 10;
1142+
const int LongPrecision = 20;
1143+
1144+
if (sqlType == SqlType.Int16) {
1145+
return new SqlValueType(SqlType.Decimal, ShortPrecision, 0);
1146+
}
1147+
if (sqlType == SqlType.Int32) {
1148+
return new SqlValueType(SqlType.Decimal, IntPrecision, 0);
1149+
}
1150+
if (sqlType == SqlType.Int64) {
1151+
return new SqlValueType(SqlType.Decimal, LongPrecision, 0);
1152+
}
1153+
return new SqlValueType(sqlType);
1154+
}
11331155
}
11341156
}

0 commit comments

Comments
 (0)