Skip to content

Commit

Permalink
Merge branch 'master' into renovate/oracle.manageddataaccess
Browse files Browse the repository at this point in the history
  • Loading branch information
hazzik authored Aug 21, 2023
2 parents 7e93f95 + 555d340 commit c5e9233
Show file tree
Hide file tree
Showing 85 changed files with 2,731 additions and 3,885 deletions.
54 changes: 53 additions & 1 deletion releasenotes.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,40 @@
Build 5.4.3
Build 5.4.5
=============================

Release notes - NHibernate - Version 5.4.5

2 issues were resolved in this release.

** Task

* #3408 Release 5.4.4
* #3407 Release Merge 5.3.19 in 5.4.x


Build 5.4.4
=============================

Release notes - NHibernate - Version 5.4.4

6 issues were resolved in this release.

** Bug

* #3359 2nd level cache GetMany ineffective for collections
* #3354 Invalid program generated by FieldInterceptorProxyBuilder for indexer property getter
* #3352 Fetch throws "could not resolve property" error for a property that is not mapped

** Improvement

* #3368 Allow internal entity classes/interfaces in .NET Standard 2.0 for field interceptor

** Task

* #3386 Release 5.4.4
* #3367 Update readme with actual dev build information for 5.4


Build 5.4.3
=============================

Release notes - NHibernate - Version 5.4.3
Expand Down Expand Up @@ -259,6 +295,22 @@ Release notes - NHibernate - Version 5.4.0
* #2242 Test case for NH-3972 - SQL error when selecting a column of a subclass when sibling classes have a column of the same name


Build 5.3.19
=============================

Release notes - NHibernate - Version 5.3.19

2 issues were resolved in this release.

** Bug

* #3397 GenerateSchemaCreationScript creates many identical dialect instances

** Task

* #3405 Release 5.3.19


Build 5.3.18
=============================

Expand Down
73 changes: 72 additions & 1 deletion src/NHibernate.Test/Async/CacheTest/BatchableCacheFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1565,8 +1565,79 @@ public async Task QueryFetchEntityBatchCacheTestAsync(bool clearEntityCacheAfter
Assert.That(Sfi.Statistics.QueryCacheHitCount, Is.EqualTo(future ? 2 : 1), "Unexpected cache hit count");
}

[Test]
public async Task CollectionLazyInitializationFromCacheIsBatchedAsync()
{
using (var s = OpenSession())
{
var readOnly = await (s.GetAsync<ReadOnly>(await (s.Query<ReadOnly>().Select(x => x.Id).FirstAsync())));
Assert.That(readOnly.Items.Count, Is.EqualTo(6));
}

var itemPersister = Sfi.GetEntityPersister(typeof(ReadOnlyItem).FullName);
var itemCache = (BatchableCache) itemPersister.Cache.Cache;
itemCache.ClearStatistics();

using (var s = OpenSession())
{
var readOnly = await (s.GetAsync<ReadOnly>(await (s.Query<ReadOnly>().Select(x => x.Id).FirstAsync())));
Assert.That(readOnly.Items.Count, Is.EqualTo(6));
}

// 6 items with batch-size = 4 so 2 GetMany calls are expected 1st call: 4 items + 2nd call: 2 items
Assert.That(itemCache.GetMultipleCalls.Count, Is.EqualTo(2));
}

[Test]
public async Task CollectionLazyInitializationFromCacheIsBatched_FillCacheByQueryCacheAsync()
{
var itemPersister = Sfi.GetEntityPersister(typeof(ReadOnlyItem).FullName);
var itemCache = (BatchableCache) itemPersister.Cache.Cache;
itemCache.ClearStatistics();
int id;
using (var s = OpenSession())
{
id = await (s.Query<ReadOnly>().Select(x => x.Id).FirstAsync());
var readOnly = (await (s.Query<ReadOnly>().Fetch(x => x.Items)
.Where(x => x.Id == id)
.WithOptions(x => x.SetCacheable(true))
.ToListAsync()))
.First();
Assert.That(itemCache.PutMultipleCalls.Count, Is.EqualTo(1));
Assert.That(itemCache.GetMultipleCalls.Count, Is.EqualTo(0));
Assert.That(NHibernateUtil.IsInitialized(readOnly.Items));
Assert.That(readOnly.Items.Count, Is.EqualTo(6));
}

itemCache.ClearStatistics();
using (var s = OpenSession())
{
var readOnly = (await (s.Query<ReadOnly>().Fetch(x => x.Items)
.Where(x => x.Id == id)
.WithOptions(x => x.SetCacheable(true))
.ToListAsync()))
.First();
Assert.That(itemCache.PutMultipleCalls.Count, Is.EqualTo(0));
Assert.That(itemCache.GetMultipleCalls.Count, Is.EqualTo(1));
Assert.That(NHibernateUtil.IsInitialized(readOnly.Items));
Assert.That(readOnly.Items.Count, Is.EqualTo(6));
}

itemCache.ClearStatistics();


using (var s = OpenSession())
{
var readOnly = await (s.GetAsync<ReadOnly>(id));
Assert.That(readOnly.Items.Count, Is.EqualTo(6));
}

// 6 items with batch-size = 4 so 2 GetMany calls are expected 1st call: 4 items + 2nd call: 2 items
Assert.That(itemCache.GetMultipleCalls.Count, Is.EqualTo(2));
}

private async Task AssertMultipleCacheCallsAsync<TEntity>(IEnumerable<int> loadIds, IReadOnlyList<int> getIds, int idIndex,
int[][] fetchedIdIndexes, int[] putIdIndexes, Func<int, bool> cacheBeforeLoadFn = null, CancellationToken cancellationToken = default(CancellationToken))
int[][] fetchedIdIndexes, int[] putIdIndexes, Func<int, bool> cacheBeforeLoadFn = null, CancellationToken cancellationToken = default(CancellationToken))
where TEntity : CacheEntity
{
var persister = Sfi.GetEntityPersister(typeof(TEntity).FullName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,18 @@ public async Task TestLinqFetchPropertyAsync()
AssertFetchProperty(person);
}

[Test]
public async Task TestLinqFetchPropertyAfterSelectAsync()
{
using var s = OpenSession();
var owner = await (s.Query<Animal>()
.Select(a => a.Owner)
.Fetch(o => o.Image)
.FirstOrDefaultAsync(o => o.Id == 1));

AssertFetchProperty(owner);
}

private static void AssertFetchProperty(Person person)
{
Assert.That(person, Is.Not.Null);
Expand Down
3 changes: 3 additions & 0 deletions src/NHibernate.Test/Async/LazyProperty/LazyPropertyFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ public async Task CanGetValueForNonLazyPropertyAsync()
Assert.That(book.Name, Is.EqualTo("some name"));
Assert.That(book.FieldInterceptor, Is.EqualTo("Why not that name?"));
Assert.That(NHibernateUtil.IsPropertyInitialized(book, "ALotOfText"), Is.False);
//GH-3354 Exception accessing indexer property
Assert.That(book[0], Is.EqualTo(0));
Assert.DoesNotThrow(() => book[0] = 0);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

using System.Linq;
using NHibernate.Criterion;
using NHibernate.Dialect;
using NHibernate.Linq;
using NHibernate.SqlCommand;
using NHibernate.Transform;
Expand All @@ -20,7 +19,7 @@ namespace NHibernate.Test.NHSpecificTest.GH1994
{
using System.Threading.Tasks;
[TestFixture]
public class FixtureAsync : BugTestCase
public class ManyToManyFilteredFixtureAsync : BugTestCase
{
protected override void OnSetUp()
{
Expand All @@ -41,14 +40,7 @@ protected override void OnTearDown()
using (var session = OpenSession())
using (var transaction = session.BeginTransaction())
{
// The HQL delete does all the job inside the database without loading the entities, but it does
// not handle delete order for avoiding violating constraints if any. Use
// session.Delete("from System.Object");
// instead if in need of having NHibernate ordering the deletes, but this will cause
// loading the entities in the session.

session.Delete("from System.Object");

transaction.Commit();
}
}
Expand All @@ -70,9 +62,6 @@ public async Task TestUnfilteredLinqQueryAsync()
[Test]
public async Task TestFilteredByWhereCollectionLinqQueryAsync()
{
if(Dialect is PostgreSQLDialect)
Assert.Ignore("Dialect doesn't support 0/1 to bool implicit cast");

using (var s = OpenSession())
{
var query = await (s.Query<Asset>()
Expand Down Expand Up @@ -150,5 +139,31 @@ public async Task TestQueryOverRestrictionWithClauseAsync()
Assert.That(query[0].Documents.Count, Is.EqualTo(1), "filtered asset documents");
}
}

[Test]
public async Task LazyLoadAsync()
{
using (var s = OpenSession())
{
var asset = await (s.Query<Asset>().FirstAsync());
Assert.That(asset.Documents.Count, Is.EqualTo(2));
Assert.That(asset.DocumentsBag.Count, Is.EqualTo(2));
Assert.That(asset.DocumentsFiltered.Count, Is.EqualTo(1));
}
}

[Test]
public async Task LazyLoadFilteredAsync()
{
using (var s = OpenSession())
{
s.EnableFilter("deletedFilter").SetParameter("deletedParam", false);

var asset = await (s.Query<Asset>().FirstAsync());
Assert.That(asset.Documents.Count, Is.EqualTo(1));
Assert.That(asset.DocumentsBag.Count, Is.EqualTo(1));
Assert.That(asset.DocumentsFiltered.Count, Is.EqualTo(1));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by AsyncGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------


using System.Data;
using NHibernate.Dialect;
using NHibernate.SqlTypes;
using NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.GH3311SqlQueryParam
{
using System.Threading.Tasks;
[TestFixture]
public class SqlQueryParamTypeFixtureAsync : BugTestCase
{
protected override void OnSetUp()
{
using var session = OpenSession();
using var transaction = session.BeginTransaction();
var e1 = new Entity {Name = "Bob"};
session.Save(e1);

var e2 = new Entity {Name = "Sally"};
session.Save(e2);

transaction.Commit();
}

protected override bool AppliesTo(Dialect.Dialect dialect)
{
return
//Dialects like SQL Server CE, Firebird don't distinguish AnsiString from String
(Dialect.GetTypeName(new SqlType(DbType.AnsiString)) != Dialect.GetTypeName(new SqlType(DbType.String))
|| Dialect is SQLiteDialect);
}

protected override void OnTearDown()
{
using var session = OpenSession();
using var transaction = session.BeginTransaction();
session.CreateQuery("delete from System.Object").ExecuteUpdate();

transaction.Commit();
}

[Test]
public async Task AppliesParameterTypeFromQueryParamAsync()
{
using var log = new SqlLogSpy();
using var s = OpenSession();
await (s.GetNamedQuery("entityIdByName").SetParameter("name", "Bob").UniqueResultAsync<object>());
Assert.That(log.GetWholeLog(), Does.Contain("Type: AnsiString"));
}
}
}
16 changes: 16 additions & 0 deletions src/NHibernate.Test/Async/NHSpecificTest/GH3327/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,21 @@ WHERE NOT (
)");
Assert.That((await (q.ListAsync()))[0], Is.EqualTo(0));
}

[Test]
public async Task NotNotExistsNegatedAsync()
{
using var log = new SqlLogSpy();
using var session = OpenSession();
var results = await (session.CreateQuery(
@"SELECT COUNT(ROOT.Id)
FROM Entity AS ROOT
WHERE NOT (
NOT EXISTS (FROM ChildEntity AS CHILD WHERE CHILD.Parent = ROOT)
AND NOT ROOT.Name = 'Parent'
)").ListAsync());
Assert.That(log.GetWholeLog(), Does.Not.Contains(" NOT ").IgnoreCase);
Assert.That(results.Count, Is.EqualTo(1));
}
}
}
Loading

0 comments on commit c5e9233

Please sign in to comment.