From dab000dd704e58564d097bf7ae10100b5bac9d50 Mon Sep 17 00:00:00 2001 From: Roman Artiukhin Date: Sat, 6 Jan 2018 14:10:09 +0530 Subject: [PATCH 1/6] Scoped table.UniqueInteger to session factory configuration --- src/NHibernate/Cfg/Mappings.cs | 7 +++++-- src/NHibernate/Mapping/Table.cs | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/NHibernate/Cfg/Mappings.cs b/src/NHibernate/Cfg/Mappings.cs index 8b955edf087..6056a9b9c7c 100644 --- a/src/NHibernate/Cfg/Mappings.cs +++ b/src/NHibernate/Cfg/Mappings.cs @@ -271,6 +271,7 @@ public Table AddTable(string schema, string catalog, string name, string subsele table.Catalog = catalog; table.Subselect = subselect; table.SchemaActions = GetSchemaActions(schemaAction); + table.UniqueInteger = tables.Count; tables[key] = table; } else @@ -337,15 +338,17 @@ public Table AddDenormalizedTable(string schema, string catalog, string name, bo Subselect = subselect }; - Table existing; - if (tables.TryGetValue(key, out existing)) + var tableIndex = tables.Count; + if (tables.TryGetValue(key, out var existing)) { if (existing.IsPhysicalTable) { throw new DuplicateMappingException("table", name); } + tableIndex = existing.UniqueInteger; } + table.UniqueInteger = tableIndex; tables[key] = table; return table; } diff --git a/src/NHibernate/Mapping/Table.cs b/src/NHibernate/Mapping/Table.cs index 9956f298118..1f01b9557cf 100644 --- a/src/NHibernate/Mapping/Table.cs +++ b/src/NHibernate/Mapping/Table.cs @@ -33,7 +33,7 @@ public class Table : IRelationalModel private readonly LinkedHashMap columns = new LinkedHashMap(); private readonly Dictionary foreignKeys = new Dictionary(); private readonly Dictionary indexes = new Dictionary(); - private readonly int uniqueInteger; + private int uniqueInteger; private readonly Dictionary uniqueKeys = new Dictionary(); private string catalog; private string comment; @@ -194,6 +194,7 @@ public string Schema public int UniqueInteger { get { return uniqueInteger; } + internal set { uniqueInteger = value; } } /// From 2108e49267e40a088c13fb5ed18efad3b4089a97 Mon Sep 17 00:00:00 2001 From: Roman Artiukhin Date: Wed, 10 Jan 2018 19:57:03 +0530 Subject: [PATCH 2/6] Removed tableCounter with tests --- .../MappingTest/TableFixture.cs | 42 +------------------ src/NHibernate/Mapping/Table.cs | 4 -- 2 files changed, 1 insertion(+), 45 deletions(-) diff --git a/src/NHibernate.Test/MappingTest/TableFixture.cs b/src/NHibernate.Test/MappingTest/TableFixture.cs index 332a980f3ab..927e468fcd0 100644 --- a/src/NHibernate.Test/MappingTest/TableFixture.cs +++ b/src/NHibernate.Test/MappingTest/TableFixture.cs @@ -61,45 +61,5 @@ public void SchemaNameQuoted() Assert.AreEqual("[schema].name", tbl.GetQualifiedName(dialect)); } - - [Test] - public void TablesUniquelyNamed() - { - Table tbl1 = new Table(); - Table tbl2 = new Table(); - - Assert.AreEqual(tbl1.UniqueInteger + 1, tbl2.UniqueInteger); - } - - [Test] - public void TablesUniquelyNamedOnlyWithinThread() - { - var uniqueIntegerList = new System.Collections.Concurrent.ConcurrentBag(); - var method = new ThreadStart(() => - { - Table tbl1 = new Table(); - Table tbl2 = new Table(); - - // Store these values for later comparison - uniqueIntegerList.Add(tbl1.UniqueInteger); - uniqueIntegerList.Add(tbl2.UniqueInteger); - - // Ensure that within a thread we have unique integers - Assert.AreEqual(tbl1.UniqueInteger + 1, tbl2.UniqueInteger); - }); - - var thread1 = new CrossThreadTestRunner(method); - var thread2 = new CrossThreadTestRunner(method); - - thread1.Start(); - thread2.Start(); - - thread1.Join(); - thread2.Join(); - - // There should in total be 4 tables, but only two distinct identifiers. - Assert.AreEqual(4, uniqueIntegerList.Count); - Assert.AreEqual(2, uniqueIntegerList.Distinct().Count()); - } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Mapping/Table.cs b/src/NHibernate/Mapping/Table.cs index 1f01b9557cf..4a62a005ed1 100644 --- a/src/NHibernate/Mapping/Table.cs +++ b/src/NHibernate/Mapping/Table.cs @@ -26,9 +26,6 @@ public enum SchemaAction [Serializable] public class Table : IRelationalModel { - [ThreadStatic] - private static int tableCounter; - private readonly List checkConstraints = new List(); private readonly LinkedHashMap columns = new LinkedHashMap(); private readonly Dictionary foreignKeys = new Dictionary(); @@ -52,7 +49,6 @@ public class Table : IRelationalModel /// public Table() { - uniqueInteger = tableCounter++; } public Table(string name) : this() From 0c293140466bc48b480702d293e045cc43f99a77 Mon Sep 17 00:00:00 2001 From: Roman Artiukhin Date: Sun, 7 Jan 2018 14:34:57 +0530 Subject: [PATCH 3/6] guarded against UniqueInteger undefined usage --- src/NHibernate/Mapping/Table.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NHibernate/Mapping/Table.cs b/src/NHibernate/Mapping/Table.cs index 4a62a005ed1..ca230c27cca 100644 --- a/src/NHibernate/Mapping/Table.cs +++ b/src/NHibernate/Mapping/Table.cs @@ -30,7 +30,7 @@ public class Table : IRelationalModel private readonly LinkedHashMap columns = new LinkedHashMap(); private readonly Dictionary foreignKeys = new Dictionary(); private readonly Dictionary indexes = new Dictionary(); - private int uniqueInteger; + private int? uniqueInteger; private readonly Dictionary uniqueKeys = new Dictionary(); private string catalog; private string comment; @@ -189,7 +189,7 @@ public string Schema /// The unique number of the Table. public int UniqueInteger { - get { return uniqueInteger; } + get { return uniqueInteger ?? throw new InvalidOperationException(nameof(UniqueInteger) + " has not been supplied"); } internal set { uniqueInteger = value; } } From 15edb128c0e2fa92e0c2702ce1e6fbce5d323bad Mon Sep 17 00:00:00 2001 From: Roman Artiukhin Date: Sun, 7 Jan 2018 15:29:12 +0530 Subject: [PATCH 4/6] Fixed test --- src/NHibernate.Test/MappingTest/ColumnFixture.cs | 2 +- src/NHibernate/Mapping/Table.cs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/NHibernate.Test/MappingTest/ColumnFixture.cs b/src/NHibernate.Test/MappingTest/ColumnFixture.cs index 3363fb1675c..7b9aa8b2b32 100644 --- a/src/NHibernate.Test/MappingTest/ColumnFixture.cs +++ b/src/NHibernate.Test/MappingTest/ColumnFixture.cs @@ -81,7 +81,7 @@ public void GetAliasWithTableSuffixRespectsMaxAliasLength(string columnName) // Test case is meant for a max length of 10, adjusts name if it is more. columnName = AdjustColumnNameToMaxLength(columnName, dialect, 10); - var table = new Table(); + var table = new Table() {UniqueInteger = 1}; var column = new Column(columnName); string generatedAlias = column.GetAlias(dialect, table); diff --git a/src/NHibernate/Mapping/Table.cs b/src/NHibernate/Mapping/Table.cs index ca230c27cca..0dcf8f4ab21 100644 --- a/src/NHibernate/Mapping/Table.cs +++ b/src/NHibernate/Mapping/Table.cs @@ -185,12 +185,13 @@ public string Schema /// /// Gets the unique number of the Table. + /// Used for SQL alias generation /// /// The unique number of the Table. public int UniqueInteger { get { return uniqueInteger ?? throw new InvalidOperationException(nameof(UniqueInteger) + " has not been supplied"); } - internal set { uniqueInteger = value; } + set { uniqueInteger = value; } } /// From 04978140ecf48dd6511cb724dcaf44577204953c Mon Sep 17 00:00:00 2001 From: Roman Artiukhin Date: Wed, 10 Jan 2018 19:52:30 +0530 Subject: [PATCH 5/6] Disable metadata pooling --- teamcity.build | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/teamcity.build b/teamcity.build index 7a5c05a4d2f..9a5d35b3815 100644 --- a/teamcity.build +++ b/teamcity.build @@ -124,7 +124,7 @@ - + @@ -140,7 +140,7 @@ - + @@ -155,7 +155,7 @@ - + @@ -164,7 +164,7 @@ - + From 187560d4e1abf9f73a91d5a407ac1341619b3fcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Delaporte?= Date: Wed, 10 Jan 2018 14:49:02 +0100 Subject: [PATCH 6/6] Completed Oracle instructions. --- lib/teamcity/oracle/oracle_installation.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/teamcity/oracle/oracle_installation.txt b/lib/teamcity/oracle/oracle_installation.txt index a8537751970..14b5b4fd904 100644 --- a/lib/teamcity/oracle/oracle_installation.txt +++ b/lib/teamcity/oracle/oracle_installation.txt @@ -41,4 +41,10 @@ This is needed because NHibernate test uses the managed driver NuGet package, bu version needs to be removed from the GAC. Read more on https://stackoverflow.com/a/35176586/1178314. Not doing this may notably cause failures in distributed transaction tests. +Adjust the connection string for the tests: +The tests involve creating and dropping many tables, sometimes with the same names but different data +types. This does not play well with Oracle meta data pooling, which needs to be disabled. +Add into your ODP.NET connection string: +Metadata Pooling=false;Self Tuning=false; + Please note that some tests are dependent on the machine locales, and may fail if they are not English.