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. 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.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/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..0dcf8f4ab21 100644 --- a/src/NHibernate/Mapping/Table.cs +++ b/src/NHibernate/Mapping/Table.cs @@ -26,14 +26,11 @@ 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(); 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; @@ -52,7 +49,6 @@ public class Table : IRelationalModel /// public Table() { - uniqueInteger = tableCounter++; } public Table(string name) : this() @@ -189,11 +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; } + get { return uniqueInteger ?? throw new InvalidOperationException(nameof(UniqueInteger) + " has not been supplied"); } + set { uniqueInteger = value; } } /// 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 @@ - +