diff --git a/src/AsyncGenerator.yml b/src/AsyncGenerator.yml index 5c7754819fb..b174d9a3e84 100644 --- a/src/AsyncGenerator.yml +++ b/src/AsyncGenerator.yml @@ -11,6 +11,12 @@ - conversion: Ignore name: ProcessResults containingTypeName: IQueryBatchItem + - conversion: Ignore + name: UnproxyForInitialized + containingTypeName: ForeignKeys + - conversion: Ignore + name: UsePreparedStatement + containingTypeName: DbTimestampType - conversion: Ignore name: PostProcessInsert containingTypeName: HqlSqlWalker diff --git a/src/NHibernate.DomainModel/Async/CustomPersister.cs b/src/NHibernate.DomainModel/Async/CustomPersister.cs index 9a671f2443b..72d94783f5d 100644 --- a/src/NHibernate.DomainModel/Async/CustomPersister.cs +++ b/src/NHibernate.DomainModel/Async/CustomPersister.cs @@ -34,44 +34,6 @@ public partial class CustomPersister : IEntityPersister #region IOptimisticCacheSource Members - public Task FindDirtyAsync(object[] currentState, object[] previousState, object entity, ISessionImplementor session, CancellationToken cancellationToken) - { - try - { - if (!Equals(currentState[0], previousState[0])) - { - return Task.FromResult(new int[] { 0 }); - } - else - { - return Task.FromResult(null); - } - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public Task FindModifiedAsync(object[] old, object[] current, object entity, ISessionImplementor session, CancellationToken cancellationToken) - { - try - { - if (!Equals(old[0], current[0])) - { - return Task.FromResult(new int[] { 0 }); - } - else - { - return Task.FromResult(null); - } - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - public Task GetNaturalIdentifierSnapshotAsync(object id, ISessionImplementor session, CancellationToken cancellationToken) { return Task.FromResult(null); @@ -165,18 +127,6 @@ public Task ForceVersionIncrementAsync(object id, object currentVersion, return Task.FromResult(null); } - public Task IsTransientAsync(object obj, ISessionImplementor session, CancellationToken cancellationToken) - { - try - { - return Task.FromResult(((Custom) obj).Id == null); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - public Task ProcessInsertGeneratedPropertiesAsync(object id, object entity, object[] state, ISessionImplementor session, CancellationToken cancellationToken) { return Task.CompletedTask; diff --git a/src/NHibernate.DomainModel/CustomPersister.cs b/src/NHibernate.DomainModel/CustomPersister.cs index a4f91c22644..00696be8d78 100644 --- a/src/NHibernate.DomainModel/CustomPersister.cs +++ b/src/NHibernate.DomainModel/CustomPersister.cs @@ -399,7 +399,7 @@ public object CreateProxy(object id, ISessionImplementor session) throw new NotSupportedException("no proxy for this class"); } - public bool? IsTransient(object obj, ISessionImplementor session) + public bool? IsTransient(object obj) { return ((Custom) obj).Id == null; } diff --git a/src/NHibernate.Test/Async/NHSpecificTest/Dates/DateTimeOffsetFixture.cs b/src/NHibernate.Test/Async/NHSpecificTest/Dates/DateTimeOffsetFixture.cs index d9e4bfce8e4..fa11a5bd0a1 100644 --- a/src/NHibernate.Test/Async/NHSpecificTest/Dates/DateTimeOffsetFixture.cs +++ b/src/NHibernate.Test/Async/NHSpecificTest/Dates/DateTimeOffsetFixture.cs @@ -22,7 +22,6 @@ namespace NHibernate.Test.NHSpecificTest.Dates { using System.Threading.Tasks; - using System.Threading; [TestFixture] public class DateTimeOffsetFixtureAsync : FixtureBaseAsync { @@ -76,22 +75,5 @@ public async Task SavingAndRetrievingTestAsync() await (tx.CommitAsync()); } } - - [Test] - public async Task NextAsync() - { - var type = NHibernateUtil.DateTimeOffset; - var current = DateTimeOffset.Now.AddTicks(-1); - object next = await (type.NextAsync(current, null, CancellationToken.None)); - - Assert.That(next, Is.TypeOf().And.Property("Ticks").GreaterThan(current.Ticks)); - } - - [Test] - public async Task SeedAsync() - { - var type = NHibernateUtil.DateTimeOffset; - Assert.That(await (type.SeedAsync(null, CancellationToken.None)), Is.TypeOf()); - } } } diff --git a/src/NHibernate.Test/Async/NHSpecificTest/GH1486/Fixture.cs b/src/NHibernate.Test/Async/NHSpecificTest/GH1486/Fixture.cs index 69b6e469b6a..8e22d8fd4ee 100644 --- a/src/NHibernate.Test/Async/NHSpecificTest/GH1486/Fixture.cs +++ b/src/NHibernate.Test/Async/NHSpecificTest/GH1486/Fixture.cs @@ -16,7 +16,6 @@ namespace NHibernate.Test.NHSpecificTest.GH1486 { using System.Threading.Tasks; - using System.Threading; [TestFixture] public class FixtureAsync : BugTestCase { @@ -142,12 +141,12 @@ public async Task TestDirectCallToIsModifiedAsync() var checkable = new [] { true, true, true }; Assert.That( - () => componentType.IsModifiedAsync(new object[] { "", "", "" }, person.Address, checkable, sessionImplementor, CancellationToken.None), + () => componentType.IsModified(new object[] { "", "", "" }, person.Address, checkable, sessionImplementor), Throws.Nothing, "Checking component against an array snapshot failed"); - var isModified = await (componentType.IsModifiedAsync(person.Address, person.Address, checkable, sessionImplementor, CancellationToken.None)); + var isModified = componentType.IsModified(person.Address, person.Address, checkable, sessionImplementor); Assert.That(isModified, Is.False, "Checking same component failed"); - isModified = await (componentType.IsModifiedAsync(new Address("1", "A", "B"), person.Address, checkable, sessionImplementor, CancellationToken.None)); + isModified = componentType.IsModified(new Address("1", "A", "B"), person.Address, checkable, sessionImplementor); Assert.That(isModified, Is.False, "Checking equal component failed"); } await (transaction.RollbackAsync()); diff --git a/src/NHibernate.Test/Async/NHSpecificTest/GH1496/AuditEventListener.cs b/src/NHibernate.Test/Async/NHSpecificTest/GH1496/AuditEventListener.cs index b7acde7891c..3ec3b8cab19 100644 --- a/src/NHibernate.Test/Async/NHSpecificTest/GH1496/AuditEventListener.cs +++ b/src/NHibernate.Test/Async/NHSpecificTest/GH1496/AuditEventListener.cs @@ -18,20 +18,28 @@ namespace NHibernate.Test.NHSpecificTest.GH1496 public partial class AuditEventListener : IPostUpdateEventListener { - public async Task OnPostUpdateAsync(PostUpdateEvent @event, CancellationToken cancellationToken) + public Task OnPostUpdateAsync(PostUpdateEvent @event, CancellationToken cancellationToken) { - if (isActive == false) - { return; } - - var modifiedItems = await (@event.Persister.FindModifiedAsync(@event.OldState, @event.State, @event.Entity, @event.Session, cancellationToken)); - foreach (int index in modifiedItems) + try { - ModifiedItems.Add(new Item + if (isActive == false) + { return Task.CompletedTask; } + + var modifiedItems = @event.Persister.FindModified(@event.OldState, @event.State, @event.Entity, @event.Session); + foreach (int index in modifiedItems) { - Index = index, - OldState = @event.OldState[index], - State = @event.State[index] - }); + ModifiedItems.Add(new Item + { + Index = index, + OldState = @event.OldState[index], + State = @event.State[index] + }); + } + return Task.CompletedTask; + } + catch (System.Exception ex) + { + return Task.FromException(ex); } } } diff --git a/src/NHibernate.Test/Async/TypesTest/AbstractDateTimeTypeFixture.cs b/src/NHibernate.Test/Async/TypesTest/AbstractDateTimeTypeFixture.cs index 4588e8d1017..dea3719bd4c 100644 --- a/src/NHibernate.Test/Async/TypesTest/AbstractDateTimeTypeFixture.cs +++ b/src/NHibernate.Test/Async/TypesTest/AbstractDateTimeTypeFixture.cs @@ -28,7 +28,6 @@ namespace NHibernate.Test.TypesTest { using System.Threading.Tasks; - using System.Threading; [TestFixture] public abstract class AbstractDateTimeTypeFixtureAsync : TypeFixtureBase { @@ -85,33 +84,6 @@ protected override void DropSchema() base.DropSchema(); } - [Test] - public async Task NextAsync() - { - // Take some margin, as DbTimestampType takes its next value from the database, which - // may have its clock a bit shifted even if running on the same server. (Seen with PostgreSQL, - // off by a few seconds, and with SAP HANA running in a vm, off by twenty seconds.) - var current = Now.Subtract(TimeSpan.FromMinutes(2)); - var next = await (Type.NextAsync(current, null, CancellationToken.None)); - - Assert.That(next, Is.TypeOf(), "next should be DateTime"); - Assert.That(next, Is.GreaterThan(current), "next should be greater than current"); - } - - [Test] - public async Task SeedAsync() - { - Assert.That(await (Type.SeedAsync(null, CancellationToken.None)), Is.TypeOf(), "seed should be DateTime"); - } - - [Test] - public async Task ComparerAsync() - { - var v1 = await (Type.SeedAsync(null, CancellationToken.None)); - var v2 = Now.Subtract(TimeSpan.FromTicks(DateAccuracyInTicks)); - Assert.That(() => Type.Comparator.Compare(v1, v2), Throws.Nothing); - } - [Test] [TestCase(DateTimeKind.Unspecified)] [TestCase(DateTimeKind.Local)] diff --git a/src/NHibernate.Test/Async/TypesTest/DateTimeOffsetTypeFixture.cs b/src/NHibernate.Test/Async/TypesTest/DateTimeOffsetTypeFixture.cs index 64e62c0e326..6855448b9c5 100644 --- a/src/NHibernate.Test/Async/TypesTest/DateTimeOffsetTypeFixture.cs +++ b/src/NHibernate.Test/Async/TypesTest/DateTimeOffsetTypeFixture.cs @@ -22,7 +22,6 @@ namespace NHibernate.Test.TypesTest { using System.Threading.Tasks; - using System.Threading; [TestFixture] public class DateTimeOffsetTypeFixtureAsync : TypeFixtureBase { @@ -87,22 +86,6 @@ protected override void DropSchema() base.DropSchema(); } - [Test] - public async Task NextAsync() - { - var current = DateTimeOffset.Parse("2004-01-01"); - var next = await (Type.NextAsync(current, null, CancellationToken.None)); - - Assert.That(next, Is.TypeOf(), "next should be DateTimeOffset"); - Assert.That(next, Is.GreaterThan(current), "next should be greater than current"); - } - - [Test] - public async Task SeedAsync() - { - Assert.That(await (Type.SeedAsync(null, CancellationToken.None)), Is.TypeOf(), "seed should be DateTime"); - } - [Test] public async Task ReadWriteAsync() { diff --git a/src/NHibernate.Test/Async/TypesTest/Int16TypeFixture.cs b/src/NHibernate.Test/Async/TypesTest/Int16TypeFixture.cs deleted file mode 100644 index 8983ffef5c3..00000000000 --- a/src/NHibernate.Test/Async/TypesTest/Int16TypeFixture.cs +++ /dev/null @@ -1,43 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using NHibernate.Type; -using NUnit.Framework; - -namespace NHibernate.Test.TypesTest -{ - using System.Threading.Tasks; - using System.Threading; - /// - /// Summary description for Int16TypeFixture. - /// - [TestFixture] - public class Int16TypeFixtureAsync - { - [Test] - public async Task NextAsync() - { - Int16Type type = (Int16Type) NHibernateUtil.Int16; - object current = (short) 1; - object next = await (type.NextAsync(current, null, CancellationToken.None)); - - Assert.IsTrue(next is Int16, "Next should be Int16"); - Assert.AreEqual((short) 2, (short) next, "current should have been incremented to 2"); - } - - [Test] - public async Task SeedAsync() - { - Int16Type type = (Int16Type) NHibernateUtil.Int16; - Assert.IsTrue(await (type.SeedAsync(null, CancellationToken.None)) is Int16, "seed should be int16"); - } - } -} \ No newline at end of file diff --git a/src/NHibernate.Test/Async/TypesTest/Int32TypeFixture.cs b/src/NHibernate.Test/Async/TypesTest/Int32TypeFixture.cs deleted file mode 100644 index ec6a264e176..00000000000 --- a/src/NHibernate.Test/Async/TypesTest/Int32TypeFixture.cs +++ /dev/null @@ -1,43 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using NHibernate.Type; -using NUnit.Framework; - -namespace NHibernate.Test.TypesTest -{ - using System.Threading.Tasks; - using System.Threading; - /// - /// Summary description for Int32TypeFixture. - /// - [TestFixture] - public class Int32TypeFixtureAsync - { - [Test] - public async Task NextAsync() - { - Int32Type type = (Int32Type) NHibernateUtil.Int32; - object current = (int) 1; - object next = await (type.NextAsync(current, null, CancellationToken.None)); - - Assert.IsTrue(next is Int32, "Next should be Int32"); - Assert.AreEqual((int) 2, (int) next, "current should have been incremented to 2"); - } - - [Test] - public async Task SeedAsync() - { - Int32Type type = (Int32Type) NHibernateUtil.Int32; - Assert.IsTrue(await (type.SeedAsync(null, CancellationToken.None)) is Int32, "seed should be Int32"); - } - } -} \ No newline at end of file diff --git a/src/NHibernate.Test/Async/TypesTest/Int64TypeFixture.cs b/src/NHibernate.Test/Async/TypesTest/Int64TypeFixture.cs deleted file mode 100644 index c0bf51f59cb..00000000000 --- a/src/NHibernate.Test/Async/TypesTest/Int64TypeFixture.cs +++ /dev/null @@ -1,61 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using NHibernate.Type; -using NUnit.Framework; -using NHibernate.Engine; - -namespace NHibernate.Test.TypesTest -{ - using System.Threading.Tasks; - using System.Threading; - /// - /// Summary description for Int64TypeFixture. - /// - [TestFixture] - public class Int64TypeFixtureAsync: TestCase - { - [Test] - public async Task NextAsync() - { - Int64Type type = NHibernateUtil.Int64; - object current = (long)1; - object next = await (type.NextAsync(current, null, CancellationToken.None)); - - Assert.IsTrue(next is Int64, "Next should be Int64"); - Assert.AreEqual((long)2, (long)next, "current should have been incremented to 2"); - } - - [Test] - public async Task SeedAsync() - { - Int64Type type = NHibernateUtil.Int64; - Assert.IsTrue(await (type.SeedAsync(null, CancellationToken.None)) is Int64, "seed should be int64"); - } - - [Test] - public async Task NullableWrapperDirtyAsync() - { - Int64Type type = NHibernateUtil.Int64; - - long? nullLong = null; - long? valueLong = 5; - long? fiveAgain = 5; - using (ISession s = OpenSession()) - { - Assert.IsTrue(await (type.IsDirtyAsync(nullLong, valueLong, (ISessionImplementor)s, CancellationToken.None)), "should be dirty - null to '5'"); - Assert.IsFalse(await (type.IsDirtyAsync(valueLong, fiveAgain, (ISessionImplementor)s, CancellationToken.None)), "should not be dirty - 5 to 5"); - } - } - - protected override string[] Mappings => Array.Empty(); - } -} diff --git a/src/NHibernate.Test/Async/TypesTest/TimeAsTimeSpanTypeFixture.cs b/src/NHibernate.Test/Async/TypesTest/TimeAsTimeSpanTypeFixture.cs index 134fdee1b32..f8e599ae4c9 100644 --- a/src/NHibernate.Test/Async/TypesTest/TimeAsTimeSpanTypeFixture.cs +++ b/src/NHibernate.Test/Async/TypesTest/TimeAsTimeSpanTypeFixture.cs @@ -15,32 +15,6 @@ namespace NHibernate.Test.TypesTest { using System.Threading.Tasks; - using System.Threading; - /// - /// Summary description for TimeAsTimeSpanTypeFixture. - /// - [TestFixture] - public class TimeAsTimeSpanTypeFixtureAsync - { - [Test] - public async Task NextAsync() - { - var type = (TimeAsTimeSpanType) NHibernateUtil.TimeAsTimeSpan; - object current = new TimeSpan(DateTime.Now.Ticks - 5); - object next = await (type.NextAsync(current, null, CancellationToken.None)); - - Assert.IsTrue(next is TimeSpan, "Next should be TimeSpan"); - Assert.IsTrue((TimeSpan) next > (TimeSpan) current, - "next should be greater than current (could be equal depending on how quickly this occurs)"); - } - - [Test] - public async Task SeedAsync() - { - var type = (TimeAsTimeSpanType) NHibernateUtil.TimeAsTimeSpan; - Assert.IsTrue(await (type.SeedAsync(null, CancellationToken.None)) is TimeSpan, "seed should be TimeSpan"); - } - } [TestFixture] public class TimeSpanFixture2Async : TypeFixtureBase diff --git a/src/NHibernate.Test/Async/TypesTest/TimeSpanTypeFixture.cs b/src/NHibernate.Test/Async/TypesTest/TimeSpanTypeFixture.cs index da729786501..4b32c30ada2 100644 --- a/src/NHibernate.Test/Async/TypesTest/TimeSpanTypeFixture.cs +++ b/src/NHibernate.Test/Async/TypesTest/TimeSpanTypeFixture.cs @@ -15,32 +15,6 @@ namespace NHibernate.Test.TypesTest { using System.Threading.Tasks; - using System.Threading; - /// - /// Summary description for TimeSpanTypeFixture. - /// - [TestFixture] - public class TimeSpanTypeFixtureAsync - { - [Test] - public async Task NextAsync() - { - var type = (TimeSpanType) NHibernateUtil.TimeSpan; - object current = new TimeSpan(DateTime.Now.Ticks - 5); - object next = await (type.NextAsync(current, null, CancellationToken.None)); - - Assert.IsTrue(next is TimeSpan, "Next should be TimeSpan"); - Assert.IsTrue((TimeSpan) next > (TimeSpan) current, - "next should be greater than current (could be equal depending on how quickly this occurs)"); - } - - [Test] - public async Task SeedAsync() - { - var type = (TimeSpanType) NHibernateUtil.TimeSpan; - Assert.IsTrue(await (type.SeedAsync(null, CancellationToken.None)) is TimeSpan, "seed should be TimeSpan"); - } - } [TestFixture] public class TimeSpanTypeFixture2Async : TypeFixtureBase diff --git a/src/NHibernate/Async/Collection/AbstractPersistentCollection.cs b/src/NHibernate/Async/Collection/AbstractPersistentCollection.cs index d3c2d48dc7e..df52ce29286 100644 --- a/src/NHibernate/Async/Collection/AbstractPersistentCollection.cs +++ b/src/NHibernate/Async/Collection/AbstractPersistentCollection.cs @@ -124,7 +124,7 @@ public async Task IdentityRemoveAsync(IList list, object obj, string entityName, { IType idType = session.Factory.GetEntityPersister(entityName).IdentifierType; - object idOfCurrent = await (ForeignKeys.GetEntityIdentifierIfNotUnsavedAsync(entityName, obj, session, cancellationToken)).ConfigureAwait(false); + object idOfCurrent = ForeignKeys.GetEntityIdentifierIfNotUnsaved(entityName, obj, session); List toRemove = new List(list.Count); foreach (object current in list) { @@ -132,7 +132,7 @@ public async Task IdentityRemoveAsync(IList list, object obj, string entityName, { continue; } - object idOfOld = await (ForeignKeys.GetEntityIdentifierIfNotUnsavedAsync(entityName, current, session, cancellationToken)).ConfigureAwait(false); + object idOfOld = ForeignKeys.GetEntityIdentifierIfNotUnsaved(entityName, current, session); if (idType.IsEqual(idOfCurrent, idOfOld, session.Factory)) { toRemove.Add(current); @@ -153,13 +153,6 @@ public async Task IdentityRemoveAsync(IList list, object obj, string entityName, /// public abstract Task DisassembleAsync(ICollectionPersister persister, CancellationToken cancellationToken); - /// - /// Get all the elements that need deleting - /// - public abstract Task GetDeletesAsync(ICollectionPersister persister, bool indexIsFormula, CancellationToken cancellationToken); - - public abstract Task EqualsSnapshotAsync(ICollectionPersister persister, CancellationToken cancellationToken); - /// /// Read the state of the collection from a disassembled cached value. /// @@ -169,16 +162,6 @@ public async Task IdentityRemoveAsync(IList list, object obj, string entityName, /// A cancellation token that can be used to cancel the work public abstract Task InitializeFromCacheAsync(ICollectionPersister persister, object disassembled, object owner, CancellationToken cancellationToken); - /// - /// Do we need to update this element? - /// - /// - /// - /// - /// A cancellation token that can be used to cancel the work - /// - public abstract Task NeedsUpdatingAsync(object entry, int i, IType elemType, CancellationToken cancellationToken); - /// /// Reads the row from the . /// @@ -190,15 +173,5 @@ public async Task IdentityRemoveAsync(IList list, object obj, string entityName, /// The object that was contained in the row. public abstract Task ReadFromAsync(DbDataReader reader, ICollectionPersister role, ICollectionAliases descriptor, object owner, CancellationToken cancellationToken); - - /// - /// Do we need to insert this element? - /// - /// - /// - /// - /// A cancellation token that can be used to cancel the work - /// - public abstract Task NeedsInsertingAsync(object entry, int i, IType elemType, CancellationToken cancellationToken); } } diff --git a/src/NHibernate/Async/Collection/Generic/PersistentGenericBag.cs b/src/NHibernate/Async/Collection/Generic/PersistentGenericBag.cs index 9707d1dbefa..e7d1f415d5f 100644 --- a/src/NHibernate/Async/Collection/Generic/PersistentGenericBag.cs +++ b/src/NHibernate/Async/Collection/Generic/PersistentGenericBag.cs @@ -44,38 +44,6 @@ public override async Task DisassembleAsync(ICollectionPersister persist return result; } - public override Task EqualsSnapshotAsync(ICollectionPersister persister, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(EqualsSnapshot(persister)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public override Task GetDeletesAsync(ICollectionPersister persister, bool indexIsFormula, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(GetDeletes(persister, indexIsFormula)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - //Since 5.3 /// [Obsolete("This method has no more usages and will be removed in a future version")] @@ -118,38 +86,6 @@ public override async Task InitializeFromCacheAsync(ICollectionPersister persist } } - public override Task NeedsInsertingAsync(object entry, int i, IType elemType, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(NeedsInserting(entry, i, elemType)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public override Task NeedsUpdatingAsync(object entry, int i, IType elemType, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(NeedsUpdating(entry, i, elemType)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - public override async Task ReadFromAsync(DbDataReader reader, ICollectionPersister role, ICollectionAliases descriptor, object owner, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); diff --git a/src/NHibernate/Async/Collection/Generic/PersistentGenericIdentifierBag.cs b/src/NHibernate/Async/Collection/Generic/PersistentGenericIdentifierBag.cs index 6e3ea111d01..62edcbc8ca2 100644 --- a/src/NHibernate/Async/Collection/Generic/PersistentGenericIdentifierBag.cs +++ b/src/NHibernate/Async/Collection/Generic/PersistentGenericIdentifierBag.cs @@ -67,80 +67,6 @@ public override async Task DisassembleAsync(ICollectionPersister persist return result; } - public override async Task EqualsSnapshotAsync(ICollectionPersister persister, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - IType elementType = persister.ElementType; - var snap = (ISet)GetSnapshot(); - if (snap.Count != _values.Count) - { - return false; - } - for (int i = 0; i < _values.Count; i++) - { - object val = _values[i]; - object id = GetIdentifier(i); - object old = snap.Where(x => Equals(x.Id, id)).Select(x => x.Value).FirstOrDefault(); - if (await (elementType.IsDirtyAsync(old, val, Session, cancellationToken)).ConfigureAwait(false)) - { - return false; - } - } - - return true; - } - - public override Task GetDeletesAsync(ICollectionPersister persister, bool indexIsFormula, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(GetDeletes(persister, indexIsFormula)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public override Task NeedsInsertingAsync(object entry, int i, IType elemType, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(NeedsInserting(entry, i, elemType)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public override async Task NeedsUpdatingAsync(object entry, int i, IType elemType, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - if (entry == null) - { - return false; - } - var snap = (ISet)GetSnapshot(); - - object id = GetIdentifier(i); - if (id == null) - { - return false; - } - - object old = snap.Where(x => Equals(x.Id, id)).Select(x => x.Value).FirstOrDefault(); - return old != null && await (elemType.IsDirtyAsync(old, entry, Session, cancellationToken)).ConfigureAwait(false); - } - public override async Task ReadFromAsync(DbDataReader reader, ICollectionPersister persister, ICollectionAliases descriptor, object owner, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); diff --git a/src/NHibernate/Async/Collection/Generic/PersistentGenericList.cs b/src/NHibernate/Async/Collection/Generic/PersistentGenericList.cs index 6b6e8126ffb..87d2a2163d8 100644 --- a/src/NHibernate/Async/Collection/Generic/PersistentGenericList.cs +++ b/src/NHibernate/Async/Collection/Generic/PersistentGenericList.cs @@ -49,25 +49,6 @@ public override Task GetOrphansAsync(object snapshot, string entity } } - public override async Task EqualsSnapshotAsync(ICollectionPersister persister, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - IType elementType = persister.ElementType; - var sn = (IList) GetSnapshot(); - if (sn.Count != WrappedList.Count) - { - return false; - } - for (int i = 0; i < WrappedList.Count; i++) - { - if (await (elementType.IsDirtyAsync(WrappedList[i], sn[i], Session, cancellationToken)).ConfigureAwait(false)) - { - return false; - } - } - return true; - } - public override async Task ReadFromAsync(DbDataReader rs, ICollectionPersister role, ICollectionAliases descriptor, object owner, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); @@ -115,44 +96,5 @@ public override async Task DisassembleAsync(ICollectionPersister persist } return result; } - - public override Task GetDeletesAsync(ICollectionPersister persister, bool indexIsFormula, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(GetDeletes(persister, indexIsFormula)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public override Task NeedsInsertingAsync(object entry, int i, IType elemType, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(NeedsInserting(entry, i, elemType)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public override async Task NeedsUpdatingAsync(object entry, int i, IType elemType, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - var sn = (IList)GetSnapshot(); - return i < sn.Count && sn[i] != null && WrappedList[i] != null && await (elemType.IsDirtyAsync(WrappedList[i], sn[i], Session, cancellationToken)).ConfigureAwait(false); - } } } diff --git a/src/NHibernate/Async/Collection/Generic/PersistentGenericMap.cs b/src/NHibernate/Async/Collection/Generic/PersistentGenericMap.cs index ccba8292fe4..872f0884a0a 100644 --- a/src/NHibernate/Async/Collection/Generic/PersistentGenericMap.cs +++ b/src/NHibernate/Async/Collection/Generic/PersistentGenericMap.cs @@ -49,27 +49,6 @@ public override Task GetOrphansAsync(object snapshot, string entity } } - public override async Task EqualsSnapshotAsync(ICollectionPersister persister, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - IType elementType = persister.ElementType; - var xmap = (IDictionary)GetSnapshot(); - if (xmap.Count != WrappedMap.Count) - { - return false; - } - foreach (KeyValuePair entry in WrappedMap) - { - // This method is not currently called if a key has been removed/added, but better be on the safe side. - if (!xmap.TryGetValue(entry.Key, out var value) || - await (elementType.IsDirtyAsync(value, entry.Value, Session, cancellationToken)).ConfigureAwait(false)) - { - return false; - } - } - return true; - } - public override async Task ReadFromAsync(DbDataReader rs, ICollectionPersister role, ICollectionAliases descriptor, object owner, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); @@ -112,48 +91,5 @@ public override async Task DisassembleAsync(ICollectionPersister persist } return result; } - - public override Task GetDeletesAsync(ICollectionPersister persister, bool indexIsFormula, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(GetDeletes(persister, indexIsFormula)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public override Task NeedsInsertingAsync(object entry, int i, IType elemType, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(NeedsInserting(entry, i, elemType)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public override async Task NeedsUpdatingAsync(object entry, int i, IType elemType, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - var sn = (IDictionary)GetSnapshot(); - var e = (KeyValuePair)entry; - var snValue = sn[e.Key]; - var isNew = !sn.Contains(e.Key); - return e.Value != null && snValue != null && await (elemType.IsDirtyAsync(snValue, e.Value, Session, cancellationToken)).ConfigureAwait(false) - || (!isNew && ((e.Value == null) != (snValue == null))); - } } } diff --git a/src/NHibernate/Async/Collection/Generic/PersistentGenericSet.cs b/src/NHibernate/Async/Collection/Generic/PersistentGenericSet.cs index e608a2ffae2..35d7a20d18d 100644 --- a/src/NHibernate/Async/Collection/Generic/PersistentGenericSet.cs +++ b/src/NHibernate/Async/Collection/Generic/PersistentGenericSet.cs @@ -50,26 +50,6 @@ public override Task GetOrphansAsync(object snapshot, string entity } } - public override async Task EqualsSnapshotAsync(ICollectionPersister persister, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - var elementType = persister.ElementType; - var snapshot = (ISetSnapshot)GetSnapshot(); - if (((ICollection)snapshot).Count != WrappedSet.Count) - { - return false; - } - - foreach (T obj in WrappedSet) - { - T oldValue; - if (!snapshot.TryGetValue(obj, out oldValue) || await (elementType.IsDirtyAsync(oldValue, obj, Session, cancellationToken)).ConfigureAwait(false)) - return false; - } - - return true; - } - /// /// Initializes this PersistentSet from the cached values. /// @@ -117,52 +97,5 @@ public override async Task DisassembleAsync(ICollectionPersister persist } return result; } - - public override async Task GetDeletesAsync(ICollectionPersister persister, bool indexIsFormula, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - IType elementType = persister.ElementType; - var sn = (ISetSnapshot)GetSnapshot(); - var deletes = new List(((ICollection)sn).Count); - - deletes.AddRange(sn.Where(obj => !WrappedSet.Contains(obj))); - - foreach (var obj in WrappedSet) - { - T oldValue; - if (sn.TryGetValue(obj, out oldValue) && await (elementType.IsDirtyAsync(obj, oldValue, Session, cancellationToken)).ConfigureAwait(false)) - deletes.Add(oldValue); - } - - return deletes; - } - - public override async Task NeedsInsertingAsync(object entry, int i, IType elemType, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - var sn = (ISetSnapshot)GetSnapshot(); - T oldKey; - - // note that it might be better to iterate the snapshot but this is safe, - // assuming the user implements equals() properly, as required by the PersistentSet - // contract! - return !sn.TryGetValue((T) entry, out oldKey) || await (elemType.IsDirtyAsync(oldKey, entry, Session, cancellationToken)).ConfigureAwait(false); - } - - public override Task NeedsUpdatingAsync(object entry, int i, IType elemType, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(NeedsUpdating(entry, i, elemType)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } } } diff --git a/src/NHibernate/Async/Collection/IPersistentCollection.cs b/src/NHibernate/Async/Collection/IPersistentCollection.cs index cd2bb132dcb..81dfd3f4b0f 100644 --- a/src/NHibernate/Async/Collection/IPersistentCollection.cs +++ b/src/NHibernate/Async/Collection/IPersistentCollection.cs @@ -47,18 +47,6 @@ public partial interface IPersistentCollection /// The object that was contained in the row. Task ReadFromAsync(DbDataReader reader, ICollectionPersister role, ICollectionAliases descriptor, object owner, CancellationToken cancellationToken); - /// - /// Does the current state exactly match the snapshot? - /// - /// The to compare the elements of the Collection. - /// A cancellation token that can be used to cancel the work - /// - /// if the wrapped collection is different than the snapshot - /// of the collection or if one of the elements in the collection is - /// dirty. - /// - Task EqualsSnapshotAsync(ICollectionPersister persister, CancellationToken cancellationToken); - /// /// Disassemble the collection, ready for the cache /// @@ -77,21 +65,6 @@ public partial interface IPersistentCollection /// Task ForceInitializationAsync(CancellationToken cancellationToken); - /// - /// Do we need to insert this element? - /// - Task NeedsInsertingAsync(object entry, int i, IType elemType, CancellationToken cancellationToken); - - /// - /// Do we need to update this element? - /// - Task NeedsUpdatingAsync(object entry, int i, IType elemType, CancellationToken cancellationToken); - - /// - /// Get all the elements that need deleting - /// - Task GetDeletesAsync(ICollectionPersister persister, bool indexIsFormula, CancellationToken cancellationToken); - /// /// Called before inserting rows, to ensure that any surrogate keys are fully generated /// diff --git a/src/NHibernate/Async/Collection/PersistentArrayHolder.cs b/src/NHibernate/Async/Collection/PersistentArrayHolder.cs index 448309f2f9e..4c6a93831c7 100644 --- a/src/NHibernate/Async/Collection/PersistentArrayHolder.cs +++ b/src/NHibernate/Async/Collection/PersistentArrayHolder.cs @@ -46,27 +46,6 @@ public override Task GetOrphansAsync(object snapshot, string entity } } - public override async Task EqualsSnapshotAsync(ICollectionPersister persister, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - IType elementType = persister.ElementType; - Array snapshot = (Array) GetSnapshot(); - - int xlen = snapshot.Length; - if (xlen != array.Length) - { - return false; - } - for (int i = 0; i < xlen; i++) - { - if (await (elementType.IsDirtyAsync(snapshot.GetValue(i), array.GetValue(i), Session, cancellationToken)).ConfigureAwait(false)) - { - return false; - } - } - return true; - } - public override async Task ReadFromAsync(DbDataReader rs, ICollectionPersister role, ICollectionAliases descriptor, object owner, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); @@ -111,46 +90,5 @@ public override async Task DisassembleAsync(ICollectionPersister persist } return result; } - - public override Task GetDeletesAsync(ICollectionPersister persister, bool indexIsFormula, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(GetDeletes(persister, indexIsFormula)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public override Task NeedsInsertingAsync(object entry, int i, IType elemType, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(NeedsInserting(entry, i, elemType)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public override async Task NeedsUpdatingAsync(object entry, int i, IType elemType, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - Array sn = (Array) GetSnapshot(); - return - i < sn.Length && sn.GetValue(i) != null && array.GetValue(i) != null - && await (elemType.IsDirtyAsync(array.GetValue(i), sn.GetValue(i), Session, cancellationToken)).ConfigureAwait(false); - } } } diff --git a/src/NHibernate/Async/Dialect/Lock/SelectLockingStrategy.cs b/src/NHibernate/Async/Dialect/Lock/SelectLockingStrategy.cs index 1aaf3f93250..1baf93897c5 100644 --- a/src/NHibernate/Async/Dialect/Lock/SelectLockingStrategy.cs +++ b/src/NHibernate/Async/Dialect/Lock/SelectLockingStrategy.cs @@ -36,10 +36,10 @@ public async Task LockAsync(object id, object version, object obj, ISessionImple DbDataReader rs = null; try { - await (lockable.IdentifierType.NullSafeSetAsync(st, id, 0, session, cancellationToken)).ConfigureAwait(false); + lockable.IdentifierType.NullSafeSet(st, id, 0, session); if (lockable.IsVersioned) { - await (lockable.VersionType.NullSafeSetAsync(st, version, lockable.IdentifierType.GetColumnSpan(factory), session, cancellationToken)).ConfigureAwait(false); + lockable.VersionType.NullSafeSet(st, version, lockable.IdentifierType.GetColumnSpan(factory), session); } rs = await (session.Batcher.ExecuteReaderAsync(st, cancellationToken)).ConfigureAwait(false); diff --git a/src/NHibernate/Async/Dialect/Lock/UpdateLockingStrategy.cs b/src/NHibernate/Async/Dialect/Lock/UpdateLockingStrategy.cs index 4487f5944b4..61d028f75a5 100644 --- a/src/NHibernate/Async/Dialect/Lock/UpdateLockingStrategy.cs +++ b/src/NHibernate/Async/Dialect/Lock/UpdateLockingStrategy.cs @@ -47,15 +47,15 @@ async Task InternalLockAsync() var st = await (session.Batcher.PrepareCommandAsync(CommandType.Text, sql, lockable.IdAndVersionSqlTypes, cancellationToken)).ConfigureAwait(false); try { - await (lockable.VersionType.NullSafeSetAsync(st, version, 1, session, cancellationToken)).ConfigureAwait(false); + lockable.VersionType.NullSafeSet(st, version, 1, session); int offset = 2; - await (lockable.IdentifierType.NullSafeSetAsync(st, id, offset, session, cancellationToken)).ConfigureAwait(false); + lockable.IdentifierType.NullSafeSet(st, id, offset, session); offset += lockable.IdentifierType.GetColumnSpan(factory); if (lockable.IsVersioned) { - await (lockable.VersionType.NullSafeSetAsync(st, version, offset, session, cancellationToken)).ConfigureAwait(false); + lockable.VersionType.NullSafeSet(st, version, offset, session); } int affected = await (session.Batcher.ExecuteNonQueryAsync(st, cancellationToken)).ConfigureAwait(false); diff --git a/src/NHibernate/Async/Engine/Cascade.cs b/src/NHibernate/Async/Engine/Cascade.cs index c0165e5cf66..6469d2f6fae 100644 --- a/src/NHibernate/Async/Engine/Cascade.cs +++ b/src/NHibernate/Async/Engine/Cascade.cs @@ -163,7 +163,7 @@ private async Task CascadeComponentAsync(object parent, object child, IAbstractC { cancellationToken.ThrowIfCancellationRequested(); componentPathStack.Push(componentPropertyName); - object[] children = await (componentType.GetPropertyValuesAsync(child, eventSource, cancellationToken)).ConfigureAwait(false); + object[] children = componentType.GetPropertyValues(child, eventSource); IType[] types = componentType.Subtypes; for (int i = 0; i < types.Length; i++) { diff --git a/src/NHibernate/Async/Engine/CollectionEntry.cs b/src/NHibernate/Async/Engine/CollectionEntry.cs deleted file mode 100644 index ea5694df0fd..00000000000 --- a/src/NHibernate/Async/Engine/CollectionEntry.cs +++ /dev/null @@ -1,74 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Collections; -using System.Threading; -using System.Threading.Tasks; -using NHibernate.Action; -using NHibernate.Collection; -using NHibernate.Impl; -using NHibernate.Persister.Collection; - -namespace NHibernate.Engine -{ - public partial class CollectionEntry - { - - /// - /// Determine if the collection is "really" dirty, by checking dirtiness - /// of the collection elements, if necessary - /// - private async Task DirtyAsync(IPersistentCollection collection, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - // if the collection is initialized and it was previously persistent - // initialize the dirty flag - bool forceDirty = collection.WasInitialized && !collection.IsDirty && LoadedPersister != null - && LoadedPersister.IsMutable - && (collection.IsDirectlyAccessible || LoadedPersister.ElementType.IsMutable) - && !await (collection.EqualsSnapshotAsync(LoadedPersister, cancellationToken)).ConfigureAwait(false); - - if (forceDirty) - { - collection.Dirty(); - } - } - - /// - /// Prepares this CollectionEntry for the Flush process. - /// - /// The that this CollectionEntry will be responsible for flushing. - /// A cancellation token that can be used to cancel the work - public async Task PreFlushAsync(IPersistentCollection collection, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - bool nonMutableChange = collection.IsDirty && LoadedPersister != null && !LoadedPersister.IsMutable; - if (nonMutableChange) - { - throw new HibernateException("changed an immutable collection instance: " + MessageHelper.InfoString(LoadedPersister.Role, LoadedKey)); - } - await (DirtyAsync(collection, cancellationToken)).ConfigureAwait(false); - - if (log.IsDebugEnabled() && collection.IsDirty && loadedPersister != null) - { - log.Debug("Collection dirty: {0}", MessageHelper.CollectionInfoString(loadedPersister, loadedKey)); - } - - // reset all of these values so any previous flush status - // information is cleared from this CollectionEntry - doupdate = false; - doremove = false; - dorecreate = false; - reached = false; - processed = false; - } - } -} diff --git a/src/NHibernate/Async/Engine/ForeignKeys.cs b/src/NHibernate/Async/Engine/ForeignKeys.cs index 8185a996af4..1a32475070a 100644 --- a/src/NHibernate/Async/Engine/ForeignKeys.cs +++ b/src/NHibernate/Async/Engine/ForeignKeys.cs @@ -70,7 +70,7 @@ private async Task NullifyTransientReferencesAsync(object value, IType t else if (type.IsComponentType) { IAbstractComponentType actype = (IAbstractComponentType)type; - object[] subvalues = await (actype.GetPropertyValuesAsync(value, session, cancellationToken)).ConfigureAwait(false); + object[] subvalues = actype.GetPropertyValues(value, session); IType[] subtypes = actype.Subtypes; bool substitute = false; for (int i = 0; i < subvalues.Length; i++) @@ -160,120 +160,46 @@ public static async Task IsNotTransientSlowAsync(string entityName, object /// /// Is this instance, which we know is not persistent, actually transient? - /// Don't hit the database to make the determination, instead return null; /// /// - /// Don't hit the database to make the determination, instead return null; + /// Hit the database to make the determination. /// - public static async Task IsTransientFastAsync(string entityName, object entity, ISessionImplementor session, CancellationToken cancellationToken) + public static async Task IsTransientSlowAsync(string entityName, object entity, ISessionImplementor session, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - if (Equals(Intercept.LazyPropertyInitializer.UnfetchedProperty, entity)) - { - // an unfetched association can only point to - // an entity that already exists in the db - return false; - } + bool? isTransient = IsTransientFast(entityName, entity, session); + if (isTransient.HasValue) + return isTransient.Value; - var proxy = entity as INHibernateProxy; - if (proxy?.HibernateLazyInitializer.IsUninitialized == true) - { - return false; - } - - // let the interceptor inspect the instance to decide - var interceptorResult = session.Interceptor.IsTransient(entity); - if (interceptorResult.HasValue) - return interceptorResult; + var persister = session.GetEntityPersister(entityName, entity); + var id = persister.GetIdentifier(entity); - // let the persister inspect the instance to decide - if (proxy != null) + // check to see if it is in the second-level cache + if (persister.HasCache && session.CacheMode.HasFlag(CacheMode.Get)) { - // The persister only deals with unproxied entities. - entity = await (proxy.HibernateLazyInitializer.GetImplementationAsync(cancellationToken)).ConfigureAwait(false); + var ck = session.GenerateCacheKey(id, persister.IdentifierType, persister.RootEntityName); + if (await (persister.Cache.GetAsync(ck, session.Timestamp, cancellationToken)).ConfigureAwait(false) != null) + return false; } - return await (session - .GetEntityPersister( - entityName, - entity) - .IsTransientAsync(entity, session, cancellationToken)).ConfigureAwait(false); - } - - /// - /// Is this instance, which we know is not persistent, actually transient? - /// - /// - /// Hit the database to make the determination. - /// - public static async Task IsTransientSlowAsync(string entityName, object entity, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - return await (IsTransientFastAsync(entityName, entity, session, cancellationToken)).ConfigureAwait(false) ?? - await (HasDbSnapshotAsync(entityName, entity, session, cancellationToken)).ConfigureAwait(false); + return await (HasDbSnapshotAsync(persister, id, session, cancellationToken)).ConfigureAwait(false); } - static async Task HasDbSnapshotAsync(string entityName, object entity, ISessionImplementor session, CancellationToken cancellationToken) + static async Task HasDbSnapshotAsync(IEntityPersister persister, object identifier, ISessionImplementor session, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); - IEntityPersister persister = session.GetEntityPersister(entityName, entity); if (persister.IdentifierGenerator is Assigned) { // When using assigned identifiers we cannot tell if an entity // is transient or detached without querying the database. // This could potentially cause Select N+1 in cascaded saves, so warn the user. log.Warn("Unable to determine if {0} with assigned identifier {1} is transient or detached; querying the database. Use explicit Save() or Update() in session to prevent this.", - entity, persister.GetIdentifier(entity)); + persister.EntityName, identifier); } // hit the database, after checking the session cache for a snapshot - System.Object[] snapshot = - await (session.PersistenceContext.GetDatabaseSnapshotAsync(persister.GetIdentifier(entity), persister, cancellationToken)).ConfigureAwait(false); + System.Object[] snapshot = await (session.PersistenceContext.GetDatabaseSnapshotAsync(identifier, persister, cancellationToken)).ConfigureAwait(false); return snapshot == null; } - - /// - /// Return the identifier of the persistent or transient object, or throw - /// an exception if the instance is "unsaved" - /// - /// - /// Used by OneToOneType and ManyToOneType to determine what id value should - /// be used for an object that may or may not be associated with the session. - /// This does a "best guess" using any/all info available to use (not just the - /// EntityEntry). - /// - public static async Task GetEntityIdentifierIfNotUnsavedAsync(string entityName, object entity, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - if (entity == null) - { - return null; - } - else - { - object id = session.GetContextEntityIdentifier(entity); - if (id == null) - { - // context-entity-identifier returns null explicitly if the entity - // is not associated with the persistence context; so make some deeper checks... - - /***********************************************/ - // NH-479 (very dirty patch) - if (entity.GetType().IsPrimitive) - return entity; - /**********************************************/ - - if ((await (IsTransientFastAsync(entityName, entity, session, cancellationToken)).ConfigureAwait(false)).GetValueOrDefault()) - { - entityName = entityName ?? session.GuessEntityName(entity); - string entityString = entity.ToString(); - throw new TransientObjectException( - string.Format("object references an unsaved transient instance - save the transient instance before flushing or set cascade action for the property to something that would make it autosave. Type: {0}, Entity: {1}", entityName, entityString)); - } - id = session.GetEntityPersister(entityName, entity).GetIdentifier(entity); - } - return id; - } - } } } diff --git a/src/NHibernate/Async/Engine/Query/NativeSQLQueryPlan.cs b/src/NHibernate/Async/Engine/Query/NativeSQLQueryPlan.cs index fec9a6ef7a6..fb8f7e80076 100644 --- a/src/NHibernate/Async/Engine/Query/NativeSQLQueryPlan.cs +++ b/src/NHibernate/Async/Engine/Query/NativeSQLQueryPlan.cs @@ -70,7 +70,7 @@ public async Task PerformExecuteUpdateAsync(QueryParameters queryParameters foreach (IParameterSpecification parameterSpecification in parametersSpecifications) { - await (parameterSpecification.BindAsync(ps, sqlParametersList, queryParameters, session, cancellationToken)).ConfigureAwait(false); + parameterSpecification.Bind(ps, sqlParametersList, queryParameters, session); } result = await (session.Batcher.ExecuteNonQueryAsync(ps, cancellationToken)).ConfigureAwait(false); diff --git a/src/NHibernate/Async/Engine/Versioning.cs b/src/NHibernate/Async/Engine/Versioning.cs deleted file mode 100644 index 061f598a9b8..00000000000 --- a/src/NHibernate/Async/Engine/Versioning.cs +++ /dev/null @@ -1,90 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using NHibernate.Persister.Entity; -using NHibernate.Type; - -namespace NHibernate.Engine -{ - using System.Threading.Tasks; - using System.Threading; - public partial class Versioning - { - - /// - /// Increment the given version number - /// - /// The value of the current version. - /// The of the versioned property. - /// The current . - /// A cancellation token that can be used to cancel the work - /// Returns the next value for the version. - public static async Task IncrementAsync(object version, IVersionType versionType, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - object next = await (versionType.NextAsync(version, session, cancellationToken)).ConfigureAwait(false); - if (log.IsDebugEnabled()) - { - log.Debug("Incrementing: {0} to {1}", - versionType.ToLoggableString(version, session.Factory), - versionType.ToLoggableString(next, session.Factory)); - } - return next; - } - - /// - /// Create an initial version number - /// - /// The of the versioned property. - /// The current . - /// A cancellation token that can be used to cancel the work - /// A seed value to initialize the versioned property with. - public static async Task SeedAsync(IVersionType versionType, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - object seed = await (versionType.SeedAsync(session, cancellationToken)).ConfigureAwait(false); - if (log.IsDebugEnabled()) - { - log.Debug("Seeding: {0}", seed); - } - return seed; - } - - /// - /// Seed the given instance state snapshot with an initial version number - /// - /// An array of objects that contains a snapshot of a persistent object. - /// The index of the version property in the fields parameter. - /// The of the versioned property. - /// Force the version to initialize - /// The current session, if any. - /// A cancellation token that can be used to cancel the work - /// if the version property needs to be seeded with an initial value. - public static async Task SeedVersionAsync(object[] fields, int versionProperty, IVersionType versionType, bool? force, - ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - object initialVersion = fields[versionProperty]; - if (initialVersion == null || !force.HasValue || force.Value) - { - fields[versionProperty] = await (SeedAsync(versionType, session, cancellationToken)).ConfigureAwait(false); - return true; - } - else - { - if (log.IsDebugEnabled()) - { - log.Debug("using initial version: {0}", initialVersion); - } - return false; - } - } - } -} diff --git a/src/NHibernate/Async/Event/Default/AbstractFlushingEventListener.cs b/src/NHibernate/Async/Event/Default/AbstractFlushingEventListener.cs index dcea3f46739..431fef6c1f8 100644 --- a/src/NHibernate/Async/Event/Default/AbstractFlushingEventListener.cs +++ b/src/NHibernate/Async/Event/Default/AbstractFlushingEventListener.cs @@ -49,7 +49,7 @@ protected virtual async Task FlushEverythingToExecutionsAsync(FlushEvent @event, // we could move this inside if we wanted to // tolerate collection initializations during // collection dirty checking: - await (PrepareCollectionFlushesAsync(session, cancellationToken)).ConfigureAwait(false); + PrepareCollectionFlushes(session); // now, any collections that are initialized // inside this block do not get updated - they // are ignored until the next flush @@ -168,21 +168,6 @@ protected virtual async Task FlushEntitiesAsync(FlushEvent @event, CancellationT source.ActionQueue.SortActions(); } - // Initialize the flags of the CollectionEntry, including the dirty check. - protected virtual async Task PrepareCollectionFlushesAsync(ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - // Initialize dirty flags for arrays + collections with composite elements - // and reset reached, doupdate, etc. - log.Debug("dirty checking collections"); - - ICollection list = IdentityMap.Entries(session.PersistenceContext.CollectionEntries); - foreach (DictionaryEntry entry in list) - { - await (((CollectionEntry) entry.Value).PreFlushAsync((IPersistentCollection) entry.Key, cancellationToken)).ConfigureAwait(false); - } - } - //process cascade save/update at the start of a flush to discover //any newly referenced entity that must be passed to saveOrUpdate(), //and also apply orphan delete diff --git a/src/NHibernate/Async/Event/Default/AbstractSaveEventListener.cs b/src/NHibernate/Async/Event/Default/AbstractSaveEventListener.cs index 985ead87deb..50f7516e64b 100644 --- a/src/NHibernate/Async/Event/Default/AbstractSaveEventListener.cs +++ b/src/NHibernate/Async/Event/Default/AbstractSaveEventListener.cs @@ -205,7 +205,7 @@ protected virtual async Task PerformSaveOrReplicateAsync(object entity, object[] values = persister.GetPropertyValuesToInsert(entity, GetMergeMap(anything), source); IType[] types = persister.PropertyTypes; - bool substitute = await (SubstituteValuesIfNecessaryAsync(entity, id, values, persister, source, cancellationToken)).ConfigureAwait(false); + bool substitute = SubstituteValuesIfNecessary(entity, id, values, persister, source); if (persister.HasCollections) { @@ -277,35 +277,6 @@ protected virtual async Task VisitCollectionsBeforeSaveAsync(object entity return visitor.SubstitutionRequired; } - /// - /// Perform any property value substitution that is necessary - /// (interceptor callback, version initialization...) - /// - /// The entity - /// The entity identifier - /// The snapshot entity state - /// The entity persister - /// The originating session - /// A cancellation token that can be used to cancel the work - /// - /// True if the snapshot state changed such that - /// reinjection of the values into the entity is required. - /// - protected virtual async Task SubstituteValuesIfNecessaryAsync(object entity, object id, object[] values, IEntityPersister persister, ISessionImplementor source, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - bool substitute = source.Interceptor.OnSave(entity, id, values, persister.PropertyNames, persister.PropertyTypes); - - //keep the existing version number in the case of replicate! - if (persister.IsVersioned) - { - // NH Specific feature (H3.2 use null value for versionProperty; NH ask to persister to know if a valueType mean unversioned) - object versionValue = values[persister.VersionProperty]; - substitute |= await (Versioning.SeedVersionAsync(values, persister.VersionProperty, persister.VersionType, persister.IsUnsavedVersion(versionValue), source, cancellationToken)).ConfigureAwait(false); - } - return substitute; - } - /// Handles the calls needed to perform pre-save cascades for the given entity. /// The session from which the save event originated. /// The entity's persister instance. @@ -390,7 +361,7 @@ protected virtual async Task GetEntityStateAsync(object entity, str //try interceptor and unsaved-value var assumed = AssumedUnsaved; if (assumed.HasValue - ? (await (ForeignKeys.IsTransientFastAsync(entityName, entity, source, cancellationToken)).ConfigureAwait(false)).GetValueOrDefault(assumed.Value) + ? ForeignKeys.IsTransientFast(entityName, entity, source).GetValueOrDefault(assumed.Value) : await (ForeignKeys.IsTransientSlowAsync(entityName, entity, source, cancellationToken)).ConfigureAwait(false)) { if (log.IsDebugEnabled()) diff --git a/src/NHibernate/Async/Event/Default/AbstractVisitor.cs b/src/NHibernate/Async/Event/Default/AbstractVisitor.cs index ac40e1dc682..9442059bbc7 100644 --- a/src/NHibernate/Async/Event/Default/AbstractVisitor.cs +++ b/src/NHibernate/Async/Event/Default/AbstractVisitor.cs @@ -98,7 +98,7 @@ internal virtual async Task ProcessComponentAsync(object component, IAbs cancellationToken.ThrowIfCancellationRequested(); if (component != null) { - await (ProcessValuesAsync(await (componentType.GetPropertyValuesAsync(component, session, cancellationToken)).ConfigureAwait(false), componentType.Subtypes, cancellationToken)).ConfigureAwait(false); + await (ProcessValuesAsync(componentType.GetPropertyValues(component, session), componentType.Subtypes, cancellationToken)).ConfigureAwait(false); } return null; } diff --git a/src/NHibernate/Async/Event/Default/DefaultFlushEntityEventListener.cs b/src/NHibernate/Async/Event/Default/DefaultFlushEntityEventListener.cs index d70bbb4b562..01282bcdea8 100644 --- a/src/NHibernate/Async/Event/Default/DefaultFlushEntityEventListener.cs +++ b/src/NHibernate/Async/Event/Default/DefaultFlushEntityEventListener.cs @@ -49,7 +49,7 @@ public virtual async Task OnFlushEntityAsync(FlushEntityEvent @event, Cancellati if (await (IsUpdateNecessaryAsync(@event, mightBeDirty, cancellationToken)).ConfigureAwait(false)) { - substitute = await (ScheduleUpdateAsync(@event, cancellationToken)).ConfigureAwait(false) || substitute; + substitute = ScheduleUpdate(@event) || substitute; } if (status != Status.Deleted) @@ -182,155 +182,6 @@ private async Task IsUpdateNecessaryAsync(FlushEntityEvent @event, bool mi } } - private async Task ScheduleUpdateAsync(FlushEntityEvent @event, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - EntityEntry entry = @event.EntityEntry; - IEventSource session = @event.Session; - object entity = @event.Entity; - Status status = entry.Status; - IEntityPersister persister = entry.Persister; - object[] values = @event.PropertyValues; - - if (log.IsDebugEnabled()) - { - if (status == Status.Deleted) - { - if (!persister.IsMutable) - { - log.Debug("Updating immutable, deleted entity: {0}", MessageHelper.InfoString(persister, entry.Id, session.Factory)); - } - else if (!entry.IsModifiableEntity()) - { - log.Debug("Updating non-modifiable, deleted entity: {0}", MessageHelper.InfoString(persister, entry.Id, session.Factory)); - } - else - { - log.Debug("Updating deleted entity: {0}", MessageHelper.InfoString(persister, entry.Id, session.Factory)); - } - } - else - { - log.Debug("Updating entity: {0}", MessageHelper.InfoString(persister, entry.Id, session.Factory)); - } - } - - bool intercepted; - - if (!entry.IsBeingReplicated) - { - // give the Interceptor a chance to process property values, if the properties - // were modified by the Interceptor, we need to set them back to the object - intercepted = await (HandleInterceptionAsync(@event, cancellationToken)).ConfigureAwait(false); - } - else - { - intercepted = false; - } - - Validate(entity, persister, status); - - // increment the version number (if necessary) - object nextVersion = await (GetNextVersionAsync(@event, cancellationToken)).ConfigureAwait(false); - - // if it was dirtied by a collection only - int[] dirtyProperties = @event.DirtyProperties; - if (@event.DirtyCheckPossible && dirtyProperties == null) - { - if (!intercepted && !@event.HasDirtyCollection) - { - throw new AssertionFailure("dirty, but no dirty properties"); - } - dirtyProperties = Array.Empty(); - } - - // check nullability but do not perform command execute - // we'll use scheduled updates for that. - new Nullability(session).CheckNullability(values, persister, true); - - // schedule the update - // note that we intentionally do _not_ pass in currentPersistentState! - session.ActionQueue.AddAction( - new EntityUpdateAction( - entry.Id, - values, - dirtyProperties, - @event.HasDirtyCollection, - status == Status.Deleted && !entry.IsModifiableEntity() ? persister.GetPropertyValues(entity) : entry.LoadedState, - entry.Version, - nextVersion, - entity, - persister, - session)); - - return intercepted; - } - - protected virtual async Task HandleInterceptionAsync(FlushEntityEvent @event, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - ISessionImplementor session = @event.Session; - EntityEntry entry = @event.EntityEntry; - IEntityPersister persister = entry.Persister; - object entity = @event.Entity; - - //give the Interceptor a chance to modify property values - object[] values = @event.PropertyValues; - bool intercepted = InvokeInterceptor(session, entity, entry, values, persister); - - //now we might need to recalculate the dirtyProperties array - if (intercepted && @event.DirtyCheckPossible && !@event.DirtyCheckHandledByInterceptor) - { - int[] dirtyProperties; - if (@event.HasDatabaseSnapshot) - { - dirtyProperties = await (persister.FindModifiedAsync(@event.DatabaseSnapshot, values, entity, session, cancellationToken)).ConfigureAwait(false); - } - else - { - dirtyProperties = await (persister.FindDirtyAsync(values, entry.LoadedState, entity, session, cancellationToken)).ConfigureAwait(false); - } - @event.DirtyProperties = dirtyProperties; - } - - return intercepted; - } - - private async Task GetNextVersionAsync(FlushEntityEvent @event, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - // Convience method to retrieve an entities next version value - EntityEntry entry = @event.EntityEntry; - IEntityPersister persister = entry.Persister; - if (persister.IsVersioned) - { - object[] values = @event.PropertyValues; - - if (entry.IsBeingReplicated) - { - return Versioning.GetVersion(values, persister); - } - else - { - int[] dirtyProperties = @event.DirtyProperties; - - bool isVersionIncrementRequired = IsVersionIncrementRequired(@event, entry, persister, dirtyProperties); - - object nextVersion = isVersionIncrementRequired ? - await (Versioning.IncrementAsync(entry.Version, persister.VersionType, @event.Session, cancellationToken)).ConfigureAwait(false) : - entry.Version; //use the current version - - Versioning.SetVersion(values, nextVersion, persister); - - return nextVersion; - } - } - else - { - return null; - } - } - /// /// Performs all necessary checking to determine if an entity needs an SQL update /// to synchronize its state to the database. Modifies the event by side-effect! @@ -408,7 +259,7 @@ protected virtual async Task DirtyCheckAsync(FlushEntityEvent @event, Cancellati if (!cannotDirtyCheck) { // dirty check against the usual snapshot of the entity - dirtyProperties = await (persister.FindDirtyAsync(values, loadedState, entity, session, cancellationToken)).ConfigureAwait(false); + dirtyProperties = persister.FindDirty(values, loadedState, entity, session); } else if (entry.Status == Status.Deleted && !@event.EntityEntry.IsModifiableEntity()) { @@ -427,7 +278,7 @@ protected virtual async Task DirtyCheckAsync(FlushEntityEvent @event, Cancellati // references to transient entities set to null. // - dirtyProperties will only contain properties that refer to transient entities object[] currentState = persister.GetPropertyValues(@event.Entity); - dirtyProperties = await (persister.FindDirtyAsync(entry.DeletedState, currentState, entity, session, cancellationToken)).ConfigureAwait(false); + dirtyProperties = persister.FindDirty(entry.DeletedState, currentState, entity, session); cannotDirtyCheck = false; } else @@ -436,7 +287,7 @@ protected virtual async Task DirtyCheckAsync(FlushEntityEvent @event, Cancellati object[] databaseSnapshot = await (GetDatabaseSnapshotAsync(session, persister, id, cancellationToken)).ConfigureAwait(false); if (databaseSnapshot != null) { - dirtyProperties = await (persister.FindModifiedAsync(databaseSnapshot, values, entity, session, cancellationToken)).ConfigureAwait(false); + dirtyProperties = persister.FindModified(databaseSnapshot, values, entity, session); cannotDirtyCheck = false; @event.DatabaseSnapshot = databaseSnapshot; } diff --git a/src/NHibernate/Async/Event/Default/DefaultLockEventListener.cs b/src/NHibernate/Async/Event/Default/DefaultLockEventListener.cs index 931d9fd1fab..2a423ee08e0 100644 --- a/src/NHibernate/Async/Event/Default/DefaultLockEventListener.cs +++ b/src/NHibernate/Async/Event/Default/DefaultLockEventListener.cs @@ -57,7 +57,7 @@ async Task InternalOnLockAsync() { IEntityPersister persister = source.GetEntityPersister(@event.EntityName, entity); object id = persister.GetIdentifier(entity); - if ((await (ForeignKeys.IsTransientFastAsync(@event.EntityName, entity, source, cancellationToken)).ConfigureAwait(false)).GetValueOrDefault()) + if (ForeignKeys.IsTransientFast(@event.EntityName, entity, source).GetValueOrDefault()) { throw new TransientObjectException("cannot lock an unsaved transient instance: " + persister.EntityName); } diff --git a/src/NHibernate/Async/Event/Default/DefaultRefreshEventListener.cs b/src/NHibernate/Async/Event/Default/DefaultRefreshEventListener.cs index 7d745ec2fa3..b9e4e7778da 100644 --- a/src/NHibernate/Async/Event/Default/DefaultRefreshEventListener.cs +++ b/src/NHibernate/Async/Event/Default/DefaultRefreshEventListener.cs @@ -135,7 +135,7 @@ public virtual async Task OnRefreshAsync(RefreshEvent @event, IDictionary refres // NH Different behavior : we are ignoring transient entities without throw any kind of exception // because a transient entity is "self refreshed" - if (!(await (ForeignKeys.IsTransientFastAsync(persister.EntityName, obj, @event.Session, cancellationToken)).ConfigureAwait(false)).GetValueOrDefault(result == null)) + if (!ForeignKeys.IsTransientFast(persister.EntityName, obj, @event.Session).GetValueOrDefault(result == null)) UnresolvableObjectException.ThrowIfNull(result, id, persister.EntityName); } diff --git a/src/NHibernate/Async/Event/Default/DefaultReplicateEventListener.cs b/src/NHibernate/Async/Event/Default/DefaultReplicateEventListener.cs index 124f45d1755..00865e3f2b0 100644 --- a/src/NHibernate/Async/Event/Default/DefaultReplicateEventListener.cs +++ b/src/NHibernate/Async/Event/Default/DefaultReplicateEventListener.cs @@ -146,22 +146,6 @@ private async Task CascadeAfterReplicateAsync(object entity, IEntityPersister pe } } - protected override Task SubstituteValuesIfNecessaryAsync(object entity, object id, object[] values, IEntityPersister persister, ISessionImplementor source, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(SubstituteValuesIfNecessary(entity, id, values, persister, source)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - protected override async Task VisitCollectionsBeforeSaveAsync(object entity, object id, object[] values, Type.IType[] types, IEventSource source, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); diff --git a/src/NHibernate/Async/Event/Default/WrapVisitor.cs b/src/NHibernate/Async/Event/Default/WrapVisitor.cs index 8423f1a2d43..cc39938481d 100644 --- a/src/NHibernate/Async/Event/Default/WrapVisitor.cs +++ b/src/NHibernate/Async/Event/Default/WrapVisitor.cs @@ -65,7 +65,7 @@ internal override async Task ProcessComponentAsync(object component, IAb cancellationToken.ThrowIfCancellationRequested(); if (component != null) { - object[] values = await (componentType.GetPropertyValuesAsync(component, Session, cancellationToken)).ConfigureAwait(false); + object[] values = componentType.GetPropertyValues(component, Session); IType[] types = componentType.Subtypes; bool substituteComponent = false; for (int i = 0; i < types.Length; i++) diff --git a/src/NHibernate/Async/Hql/Ast/ANTLR/Exec/BasicExecutor.cs b/src/NHibernate/Async/Hql/Ast/ANTLR/Exec/BasicExecutor.cs index 01c445dc51a..8eb91359bc9 100644 --- a/src/NHibernate/Async/Hql/Ast/ANTLR/Exec/BasicExecutor.cs +++ b/src/NHibernate/Async/Hql/Ast/ANTLR/Exec/BasicExecutor.cs @@ -53,7 +53,7 @@ public override async Task ExecuteAsync(QueryParameters parameters, ISessio st = await (session.Batcher.PrepareCommandAsync(CommandType.Text, sqlString, parameterTypes, cancellationToken)).ConfigureAwait(false); foreach (var parameterSpecification in Parameters) { - await (parameterSpecification.BindAsync(st, sqlQueryParametersList, parameters, session, cancellationToken)).ConfigureAwait(false); + parameterSpecification.Bind(st, sqlQueryParametersList, parameters, session); } if (selection != null) diff --git a/src/NHibernate/Async/Hql/Ast/ANTLR/Exec/MultiTableDeleteExecutor.cs b/src/NHibernate/Async/Hql/Ast/ANTLR/Exec/MultiTableDeleteExecutor.cs index b00757ffec0..d7d63785464 100644 --- a/src/NHibernate/Async/Hql/Ast/ANTLR/Exec/MultiTableDeleteExecutor.cs +++ b/src/NHibernate/Async/Hql/Ast/ANTLR/Exec/MultiTableDeleteExecutor.cs @@ -52,7 +52,7 @@ public override async Task ExecuteAsync(QueryParameters parameters, ISessio ps = await (session.Batcher.PrepareCommandAsync(CommandType.Text, sqlString, parameterTypes, cancellationToken)).ConfigureAwait(false); foreach (var parameterSpecification in paramsSpec) { - await (parameterSpecification.BindAsync(ps, sqlQueryParametersList, parameters, session, cancellationToken)).ConfigureAwait(false); + parameterSpecification.Bind(ps, sqlQueryParametersList, parameters, session); } resultCount = await (session.Batcher.ExecuteNonQueryAsync(ps, cancellationToken)).ConfigureAwait(false); diff --git a/src/NHibernate/Async/Hql/Ast/ANTLR/Exec/MultiTableUpdateExecutor.cs b/src/NHibernate/Async/Hql/Ast/ANTLR/Exec/MultiTableUpdateExecutor.cs index 30401c83829..3bc7d825c6f 100644 --- a/src/NHibernate/Async/Hql/Ast/ANTLR/Exec/MultiTableUpdateExecutor.cs +++ b/src/NHibernate/Async/Hql/Ast/ANTLR/Exec/MultiTableUpdateExecutor.cs @@ -60,7 +60,7 @@ public override async Task ExecuteAsync(QueryParameters parameters, ISessio ps = await (session.Batcher.PrepareCommandAsync(CommandType.Text, sqlString, parameterTypes, cancellationToken)).ConfigureAwait(false); foreach (var parameterSpecification in whereParams) { - await (parameterSpecification.BindAsync(ps, sqlQueryParametersList, parameters, session, cancellationToken)).ConfigureAwait(false); + parameterSpecification.Bind(ps, sqlQueryParametersList, parameters, session); } resultCount = await (session.Batcher.ExecuteNonQueryAsync(ps, cancellationToken)).ConfigureAwait(false); @@ -97,7 +97,7 @@ public override async Task ExecuteAsync(QueryParameters parameters, ISessio ps = await (session.Batcher.PrepareCommandAsync(CommandType.Text, updates[i], parameterTypes, cancellationToken)).ConfigureAwait(false); foreach (var parameterSpecification in paramsSpec) { - await (parameterSpecification.BindAsync(ps, sqlQueryParametersList, parameters, session, cancellationToken)).ConfigureAwait(false); + parameterSpecification.Bind(ps, sqlQueryParametersList, parameters, session); } await (session.Batcher.ExecuteNonQueryAsync(ps, cancellationToken)).ConfigureAwait(false); diff --git a/src/NHibernate/Async/Id/ForeignGenerator.cs b/src/NHibernate/Async/Id/ForeignGenerator.cs index 85181bd024b..0e37eafa7ed 100644 --- a/src/NHibernate/Async/Id/ForeignGenerator.cs +++ b/src/NHibernate/Async/Id/ForeignGenerator.cs @@ -61,10 +61,10 @@ public async Task GenerateAsync(ISessionImplementor sessionImplementor, object id; try { - id = await (ForeignKeys.GetEntityIdentifierIfNotUnsavedAsync( + id = ForeignKeys.GetEntityIdentifierIfNotUnsaved( foreignValueSourceType.GetAssociatedEntityName(), associatedObject, - sessionImplementor, cancellationToken)).ConfigureAwait(false); + sessionImplementor); } catch (TransientObjectException) { diff --git a/src/NHibernate/Async/Id/IPostInsertIdentityPersister.cs b/src/NHibernate/Async/Id/IPostInsertIdentityPersister.cs deleted file mode 100644 index 886bee0cf25..00000000000 --- a/src/NHibernate/Async/Id/IPostInsertIdentityPersister.cs +++ /dev/null @@ -1,48 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Data.Common; -using System.Linq; -using NHibernate.Engine; -using NHibernate.Id.Insert; -using NHibernate.Persister.Collection; -using NHibernate.Persister.Entity; -using NHibernate.SqlCommand; -using NHibernate.Type; -using NHibernate.Util; - -namespace NHibernate.Id -{ - using System.Threading.Tasks; - using System.Threading; - - public partial interface ICompositeKeyPostInsertIdentityPersister - { - - /// - /// Bind the parameter values of a SQL select command that performs a select based on an unique key. - /// - /// The current . - /// The command. - /// The id insertion binder. - /// The names of the properties which map to the column(s) to use - /// in the select statement restriction. If supplied, they override the persister logic for determining - /// them. - /// A cancellation token that can be used to cancel the work - /// thrown if are - /// specified on a persister which does not allow a custom key. - Task BindSelectByUniqueKeyAsync( - ISessionImplementor session, - DbCommand selectCommand, - IBinder binder, - string[] suppliedPropertyNames, CancellationToken cancellationToken); - } -} diff --git a/src/NHibernate/Async/Id/Insert/AbstractReturningDelegate.cs b/src/NHibernate/Async/Id/Insert/AbstractReturningDelegate.cs index 2e9ecc6cfbf..0e6a57d9389 100644 --- a/src/NHibernate/Async/Id/Insert/AbstractReturningDelegate.cs +++ b/src/NHibernate/Async/Id/Insert/AbstractReturningDelegate.cs @@ -31,7 +31,7 @@ public async Task PerformInsertAsync(SqlCommandInfo insertSQL, ISessionI var insert = await (PrepareAsync(insertSQL, session, cancellationToken)).ConfigureAwait(false); try { - await (binder.BindValuesAsync(insert, cancellationToken)).ConfigureAwait(false); + binder.BindValues(insert); return await (ExecuteAndExtractAsync(insert, session, cancellationToken)).ConfigureAwait(false); } finally diff --git a/src/NHibernate/Async/Id/Insert/AbstractSelectingDelegate.cs b/src/NHibernate/Async/Id/Insert/AbstractSelectingDelegate.cs index 9c668f5cf40..db428953712 100644 --- a/src/NHibernate/Async/Id/Insert/AbstractSelectingDelegate.cs +++ b/src/NHibernate/Async/Id/Insert/AbstractSelectingDelegate.cs @@ -40,7 +40,7 @@ public async Task PerformInsertAsync(SqlCommandInfo insertSql, ISessionI var insert = await (session.Batcher.PrepareCommandAsync(insertSql.CommandType, insertSql.Text, insertSql.ParameterTypes, cancellationToken)).ConfigureAwait(false); try { - await (binder.BindValuesAsync(insert, cancellationToken)).ConfigureAwait(false); + binder.BindValues(insert); await (session.Batcher.ExecuteNonQueryAsync(insert, cancellationToken)).ConfigureAwait(false); } finally @@ -63,7 +63,7 @@ public async Task PerformInsertAsync(SqlCommandInfo insertSql, ISessionI var idSelect = await (session.Batcher.PrepareCommandAsync(CommandType.Text, selectSql, ParametersTypes, cancellationToken)).ConfigureAwait(false); try { - await (BindParametersAsync(session, idSelect, binder, cancellationToken)).ConfigureAwait(false); + BindParameters(session, idSelect, binder); var rs = await (session.Batcher.ExecuteReaderAsync(idSelect, cancellationToken)).ConfigureAwait(false); try { @@ -102,46 +102,5 @@ public async Task PerformInsertAsync(SqlCommandInfo insertSql, ISessionI /// A cancellation token that can be used to cancel the work /// The generated identifier protected internal abstract Task GetResultAsync(ISessionImplementor session, DbDataReader rs, object entity, CancellationToken cancellationToken); - - /// Bind any required parameter values into the SQL command . - /// The session - /// The prepared command - /// The entity being saved. - /// A cancellation token that can be used to cancel the work - // Since 5.2 - [Obsolete("Use or override BindParameters(ISessionImplementor session, DbCommand ps, IBinder binder) instead.")] - protected internal virtual Task BindParametersAsync(ISessionImplementor session, DbCommand ps, object entity, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - BindParameters(session, ps, entity); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// Bind any required parameter values into the SQL command . - /// The session. - /// The prepared command. - /// The binder for the entity or collection being saved. - /// A cancellation token that can be used to cancel the work - protected internal virtual Task BindParametersAsync(ISessionImplementor session, DbCommand ps, IBinder binder, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - // 6.0 TODO: remove the call to the obsoleted method. -#pragma warning disable 618 - return BindParametersAsync(session, ps, binder.Entity, cancellationToken); -#pragma warning restore 618 - } } } diff --git a/src/NHibernate/Async/Id/Insert/IBinder.cs b/src/NHibernate/Async/Id/Insert/IBinder.cs deleted file mode 100644 index 18a008641e6..00000000000 --- a/src/NHibernate/Async/Id/Insert/IBinder.cs +++ /dev/null @@ -1,21 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System.Data.Common; - -namespace NHibernate.Id.Insert -{ - using System.Threading.Tasks; - using System.Threading; - public partial interface IBinder - { - Task BindValuesAsync(DbCommand cm, CancellationToken cancellationToken); - } -} diff --git a/src/NHibernate/Async/Id/SelectGenerator.cs b/src/NHibernate/Async/Id/SelectGenerator.cs index 5e52da2d44f..5ab93025079 100644 --- a/src/NHibernate/Async/Id/SelectGenerator.cs +++ b/src/NHibernate/Async/Id/SelectGenerator.cs @@ -32,43 +32,6 @@ public partial class SelectGenerator : AbstractPostInsertGenerator, IConfigurabl public partial class SelectGeneratorDelegate : AbstractSelectingDelegate { - // Since 5.2 - [Obsolete("Use or override BindParameters(ISessionImplementor session, DbCommand ps, IBinder binder) instead.")] - protected internal override async Task BindParametersAsync(ISessionImplementor session, DbCommand ps, object entity, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - var entityPersister = (IEntityPersister) persister; - var uniqueKeyPropertyNames = uniqueKeySuppliedPropertyNames ?? - PostInsertIdentityPersisterExtension.DetermineNameOfPropertiesToUse(entityPersister); - for (var i = 0; i < uniqueKeyPropertyNames.Length; i++) - { - var uniqueKeyValue = entityPersister.GetPropertyValue(entity, uniqueKeyPropertyNames[i]); - await (uniqueKeyTypes[i].NullSafeSetAsync(ps, uniqueKeyValue, i, session, cancellationToken)).ConfigureAwait(false); - } - } - - protected internal override async Task BindParametersAsync(ISessionImplementor session, DbCommand ps, IBinder binder, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - // 6.0 TODO: remove the "if" block and do the other TODO of this method - if (persister is IEntityPersister) - { -#pragma warning disable 618 - await (BindParametersAsync(session, ps, binder.Entity, cancellationToken)).ConfigureAwait(false); -#pragma warning restore 618 - return; - } - - if (persister is ICompositeKeyPostInsertIdentityPersister compositeKeyPersister) - { - await (compositeKeyPersister.BindSelectByUniqueKeyAsync(session, ps, binder, uniqueKeySuppliedPropertyNames, cancellationToken)).ConfigureAwait(false); - return; - } - - // 6.0 TODO: remove by merging ICompositeKeyPostInsertIdentityPersister in IPostInsertIdentityPersister - await (binder.BindValuesAsync(ps, cancellationToken)).ConfigureAwait(false); - } - protected internal override async Task GetResultAsync(ISessionImplementor session, DbDataReader rs, object entity, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); diff --git a/src/NHibernate/Async/Impl/StatelessSessionImpl.cs b/src/NHibernate/Async/Impl/StatelessSessionImpl.cs index 162baafddc2..a7bd68e4188 100644 --- a/src/NHibernate/Async/Impl/StatelessSessionImpl.cs +++ b/src/NHibernate/Async/Impl/StatelessSessionImpl.cs @@ -351,8 +351,8 @@ public async Task ManagedFlushAsync(CancellationToken cancellationToken) if (persister.IsVersioned) { object versionValue = state[persister.VersionProperty]; - bool substitute = await (Versioning.SeedVersionAsync(state, persister.VersionProperty, persister.VersionType, - persister.IsUnsavedVersion(versionValue), this, cancellationToken)).ConfigureAwait(false); + bool substitute = Versioning.SeedVersion(state, persister.VersionProperty, persister.VersionType, + persister.IsUnsavedVersion(versionValue), this); if (substitute) { persister.SetPropertyValues(entity, state); @@ -399,7 +399,7 @@ public async Task ManagedFlushAsync(CancellationToken cancellationToken) if (persister.IsVersioned) { oldVersion = persister.GetVersion(entity); - object newVersion = await (Versioning.IncrementAsync(oldVersion, persister.VersionType, this, cancellationToken)).ConfigureAwait(false); + object newVersion = Versioning.Increment(oldVersion, persister.VersionType, this); Versioning.SetVersion(state, newVersion, persister); persister.SetPropertyValues(entity, state); } diff --git a/src/NHibernate/Async/Loader/Hql/QueryLoader.cs b/src/NHibernate/Async/Loader/Hql/QueryLoader.cs index 83832ddf38b..35b235e318c 100644 --- a/src/NHibernate/Async/Loader/Hql/QueryLoader.cs +++ b/src/NHibernate/Async/Loader/Hql/QueryLoader.cs @@ -99,7 +99,7 @@ internal async Task GetEnumerableAsync(QueryParameters queryParamet stopWatch = Stopwatch.StartNew(); } - var cmd = await (PrepareQueryCommandAsync(queryParameters, false, session, cancellationToken)).ConfigureAwait(false); + var cmd = PrepareQueryCommand(queryParameters, false, session); // This DbDataReader is disposed of in EnumerableImpl.Dispose var rs = await (GetResultSetAsync(cmd, queryParameters, session, null, cancellationToken)).ConfigureAwait(false); diff --git a/src/NHibernate/Async/Loader/Loader.cs b/src/NHibernate/Async/Loader/Loader.cs index a8a235d48c3..170c4eb9bb4 100644 --- a/src/NHibernate/Async/Loader/Loader.cs +++ b/src/NHibernate/Async/Loader/Loader.cs @@ -265,7 +265,7 @@ private async Task DoQueryAsync(ISessionImplementor session, QueryParamet List hydratedObjects = entitySpan == 0 ? null : new List(entitySpan*10); - var st = await (PrepareQueryCommandAsync(queryParameters, false, session, cancellationToken)).ConfigureAwait(false); + var st = PrepareQueryCommand(queryParameters, false, session); var rs = await (GetResultSetAsync(st, queryParameters, session, forcedResultTransformer, cancellationToken)).ConfigureAwait(false); // would be great to move all this below here into another method that could also be used @@ -951,57 +951,6 @@ internal static async Task AdvanceAsync(DbDataReader rs, RowSelection selection, } } - /// - /// Obtain an DbCommand with all parameters pre-bound. Bind positional parameters, - /// named parameters, and limit parameters. - /// - /// - /// Creates an DbCommand object and populates it with the values necessary to execute it against the - /// database to Load an Entity. - /// - /// The to use for the DbCommand. - /// TODO: find out where this is used... - /// The SessionImpl this Command is being prepared in. - /// A cancellation token that can be used to cancel the work - /// A CommandWrapper wrapping an DbCommand that is ready to be executed. - protected internal virtual async Task PrepareQueryCommandAsync(QueryParameters queryParameters, bool scroll, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - ISqlCommand sqlCommand = CreateSqlCommand(queryParameters, session); - SqlString sqlString = sqlCommand.Query; - - sqlCommand.ResetParametersIndexesForTheCommand(0); - var command = session.Batcher.PrepareQueryCommand(CommandType.Text, sqlString, sqlCommand.ParameterTypes); - - try - { - RowSelection selection = queryParameters.RowSelection; - if (selection != null && selection.Timeout != RowSelection.NoValue) - { - command.CommandTimeout = selection.Timeout; - } - - await (sqlCommand.BindAsync(command, session, cancellationToken)).ConfigureAwait(false); - - IDriver driver = _factory.ConnectionProvider.Driver; - driver.RemoveUnusedCommandParameters(command, sqlString); - driver.ExpandQueryParameters(command, sqlString, sqlCommand.ParameterTypes); - } - catch (OperationCanceledException) { throw; } - catch (HibernateException) - { - session.Batcher.CloseCommand(command, null); - throw; - } - catch (Exception sqle) - { - session.Batcher.CloseCommand(command, null); - ADOExceptionReporter.LogExceptions(sqle); - throw; - } - return command; - } - /// /// Fetch a DbCommand, call SetMaxRows and then execute it, /// advance to the first result and return an SQL DbDataReader diff --git a/src/NHibernate/Async/Param/AbstractExplicitParameterSpecification.cs b/src/NHibernate/Async/Param/AbstractExplicitParameterSpecification.cs deleted file mode 100644 index 9655969d35c..00000000000 --- a/src/NHibernate/Async/Param/AbstractExplicitParameterSpecification.cs +++ /dev/null @@ -1,31 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Collections.Generic; -using System.Data.Common; -using NHibernate.Engine; -using NHibernate.SqlCommand; -using NHibernate.Type; - -namespace NHibernate.Param -{ - using System.Threading.Tasks; - using System.Threading; - public abstract partial class AbstractExplicitParameterSpecification : IPageableParameterSpecification - { - - #region IExplicitParameterSpecification Members - public abstract Task BindAsync(DbCommand command, IList sqlQueryParametersList, QueryParameters queryParameters, ISessionImplementor session, CancellationToken cancellationToken); - public abstract Task BindAsync(DbCommand command, IList multiSqlQueryParametersList, int singleSqlParametersOffset, IList sqlQueryParametersList, QueryParameters queryParameters, ISessionImplementor session, CancellationToken cancellationToken); - - #endregion - } -} diff --git a/src/NHibernate/Async/Param/AggregatedIndexCollectionSelectorParameterSpecifications.cs b/src/NHibernate/Async/Param/AggregatedIndexCollectionSelectorParameterSpecifications.cs deleted file mode 100644 index 57893dade62..00000000000 --- a/src/NHibernate/Async/Param/AggregatedIndexCollectionSelectorParameterSpecifications.cs +++ /dev/null @@ -1,47 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Collections.Generic; -using System.Data.Common; -using System.Text; -using NHibernate.Engine; -using NHibernate.SqlCommand; -using NHibernate.Type; - -namespace NHibernate.Param -{ - using System.Threading.Tasks; - using System.Threading; - public partial class AggregatedIndexCollectionSelectorParameterSpecifications : IParameterSpecification - { - - //public int Bind(DbCommand statement, QueryParameters qp, ISessionImplementor session, int position) - //{ - // int bindCount = 0; - - // foreach (IParameterSpecification spec in _paramSpecs) - // { - // bindCount += spec.Bind(statement, qp, session, position + bindCount); - // } - // return bindCount; - //} - - public Task BindAsync(DbCommand command, IList sqlQueryParametersList, QueryParameters queryParameters, ISessionImplementor session, CancellationToken cancellationToken) - { - throw new NotImplementedException(); - } - - public Task BindAsync(DbCommand command, IList multiSqlQueryParametersList, int singleSqlParametersOffset, IList sqlQueryParametersList, QueryParameters queryParameters, ISessionImplementor session, CancellationToken cancellationToken) - { - throw new NotImplementedException(); - } - } -} diff --git a/src/NHibernate/Async/Param/CollectionFilterKeyParameterSpecification.cs b/src/NHibernate/Async/Param/CollectionFilterKeyParameterSpecification.cs deleted file mode 100644 index fb1305c2a52..00000000000 --- a/src/NHibernate/Async/Param/CollectionFilterKeyParameterSpecification.cs +++ /dev/null @@ -1,60 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Collections.Generic; -using System.Data.Common; -using System.Linq; -using NHibernate.Engine; -using NHibernate.SqlCommand; -using NHibernate.Type; - -namespace NHibernate.Param -{ - using System.Threading.Tasks; - using System.Threading; - public partial class CollectionFilterKeyParameterSpecification : IParameterSpecification - { - - #region IParameterSpecification Members - - public Task BindAsync(DbCommand command, IList multiSqlQueryParametersList, int singleSqlParametersOffset, IList sqlQueryParametersList, QueryParameters queryParameters, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - IType type = keyType; - object value = queryParameters.PositionalParameterValues[queryParameterPosition]; - - string backTrackId = GetIdsForBackTrack(session.Factory).First(); // just the first because IType suppose the oders in certain sequence - int position = sqlQueryParametersList.GetEffectiveParameterLocations(backTrackId).Single(); // an HQL positional parameter can't appear more than once - return type.NullSafeSetAsync(command, value, position + singleSqlParametersOffset, session, cancellationToken); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public Task BindAsync(DbCommand command, IList sqlQueryParametersList, QueryParameters queryParameters, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - return BindAsync(command, sqlQueryParametersList, 0, sqlQueryParametersList, queryParameters, session, cancellationToken); - } - - #endregion - } -} \ No newline at end of file diff --git a/src/NHibernate/Async/Param/CriteriaNamedParameterSpecification.cs b/src/NHibernate/Async/Param/CriteriaNamedParameterSpecification.cs deleted file mode 100644 index 8716facfcb0..00000000000 --- a/src/NHibernate/Async/Param/CriteriaNamedParameterSpecification.cs +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Collections.Generic; -using System.Data.Common; -using System.Linq; -using NHibernate.Engine; -using NHibernate.SqlCommand; -using NHibernate.Type; - -namespace NHibernate.Param -{ - using System.Threading.Tasks; - using System.Threading; - public partial class CriteriaNamedParameterSpecification : IParameterSpecification - { - - #region IParameterSpecification Members - - public Task BindAsync(DbCommand command, IList sqlQueryParametersList, QueryParameters queryParameters, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - return BindAsync(command, sqlQueryParametersList, 0, sqlQueryParametersList, queryParameters, session, cancellationToken); - } - - public async Task BindAsync(DbCommand command, IList multiSqlQueryParametersList, int singleSqlParametersOffset, IList sqlQueryParametersList, QueryParameters queryParameters, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - TypedValue typedValue = queryParameters.NamedParameters[name]; - string backTrackId = GetIdsForBackTrack(session.Factory).First(); - foreach (int position in sqlQueryParametersList.GetEffectiveParameterLocations(backTrackId)) - { - await (ExpectedType.NullSafeSetAsync(command, typedValue.Value, position + singleSqlParametersOffset, session, cancellationToken)).ConfigureAwait(false); - } - } - - #endregion - } -} \ No newline at end of file diff --git a/src/NHibernate/Async/Param/DynamicFilterParameterSpecification.cs b/src/NHibernate/Async/Param/DynamicFilterParameterSpecification.cs index 4972332ea52..1022c8943df 100644 --- a/src/NHibernate/Async/Param/DynamicFilterParameterSpecification.cs +++ b/src/NHibernate/Async/Param/DynamicFilterParameterSpecification.cs @@ -24,32 +24,6 @@ namespace NHibernate.Param using System.Threading; public partial class DynamicFilterParameterSpecification : IParameterSpecification { - - #region IParameterSpecification Members - - public Task BindAsync(DbCommand command, IList sqlQueryParametersList, QueryParameters queryParameters, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - return BindAsync(command, sqlQueryParametersList, 0, sqlQueryParametersList, queryParameters, session, cancellationToken); - } - - public async Task BindAsync(DbCommand command, IList multiSqlQueryParametersList, int singleSqlParametersOffset, IList sqlQueryParametersList, QueryParameters queryParameters, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - string backTrackId = GetIdsForBackTrack(session.Factory).First(); // just the first because IType suppose the oders in certain sequence - - // The same filterName-parameterName can appear more than once in the whole query - object value = session.GetFilterParameterValue(filterParameterFullName); - foreach (int position in multiSqlQueryParametersList.GetEffectiveParameterLocations(backTrackId)) - { - await (ExpectedType.NullSafeSetAsync(command, value, position, session, cancellationToken)).ConfigureAwait(false); - } - } - - #endregion private partial class CollectionOfValuesType : IType { @@ -80,54 +54,6 @@ public Task BeforeAssembleAsync(object cached, ISessionImplementor session, Canc } } - public Task IsDirtyAsync(object old, object current, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(IsDirty(old, current, session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public Task IsDirtyAsync(object old, object current, bool[] checkable, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(IsDirty(old, current, checkable, session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public Task IsModifiedAsync(object oldHydratedState, object currentState, bool[] checkable, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(IsModified(oldHydratedState, currentState, checkable, session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - public Task NullSafeGetAsync(DbDataReader rs, string[] names, ISessionImplementor session, object owner, CancellationToken cancellationToken) { throw new InvalidOperationException(); @@ -138,26 +64,6 @@ public Task NullSafeGetAsync(DbDataReader rs, string name, ISessionImple throw new InvalidOperationException(); } - public Task NullSafeSetAsync(DbCommand st, object value, int index, bool[] settable, ISessionImplementor session, CancellationToken cancellationToken) - { - throw new InvalidOperationException(); - } - - public async Task NullSafeSetAsync(DbCommand st, object value, int index, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - var start = index; - var positions = 0; - var singleParameterColumnSpan = elementType.GetColumnSpan(session.Factory); - - var collection = (IEnumerable) value; - foreach (var element in collection) - { - await (elementType.NullSafeSetAsync(st, element, start + positions, session, cancellationToken)).ConfigureAwait(false); - positions += singleParameterColumnSpan; - } - } - public Task HydrateAsync(DbDataReader rs, string[] names, ISessionImplementor session, object owner, CancellationToken cancellationToken) { throw new InvalidOperationException(); diff --git a/src/NHibernate/Async/Param/IParameterSpecification.cs b/src/NHibernate/Async/Param/IParameterSpecification.cs deleted file mode 100644 index 15d097bb2cd..00000000000 --- a/src/NHibernate/Async/Param/IParameterSpecification.cs +++ /dev/null @@ -1,50 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System.Collections.Generic; -using System.Data.Common; -using NHibernate.Engine; -using NHibernate.SqlCommand; -using NHibernate.Type; - -namespace NHibernate.Param -{ - using System.Threading.Tasks; - using System.Threading; - public partial interface IParameterSpecification - { - /// - /// Bind the appropriate value into the given command. - /// - /// The command into which the value should be bound. - /// The list of Sql query parameter in the exact sequence they are present in the query. - /// The defined values for the current query execution. - /// The session against which the current execution is occuring. - /// A cancellation token that can be used to cancel the work - Task BindAsync(DbCommand command, IList sqlQueryParametersList, QueryParameters queryParameters, ISessionImplementor session, CancellationToken cancellationToken); - - /// - /// Bind the appropriate value into the given command. - /// - /// The command into which the value should be bound. - /// The parameter-list of the whole query of the command. - /// The offset from where start the list of in the given for the query where this was used. - /// The list of Sql query parameter in the exact sequence they are present in the query where this was used. - /// The defined values for the query where this was used. - /// The session against which the current execution is occuring. - /// A cancellation token that can be used to cancel the work - /// - /// Suppose the is composed by two queries. The for the first query is zero. - /// If the first query in has 12 parameters (size of its SqlType array) the offset to bind all s of the second query in the - /// is 12 (for the first query we are using from 0 to 11). - /// - Task BindAsync(DbCommand command, IList multiSqlQueryParametersList, int singleSqlParametersOffset, IList sqlQueryParametersList, QueryParameters queryParameters, ISessionImplementor session, CancellationToken cancellationToken); - } -} \ No newline at end of file diff --git a/src/NHibernate/Async/Param/NamedParameterSpecification.cs b/src/NHibernate/Async/Param/NamedParameterSpecification.cs deleted file mode 100644 index 49a4a669367..00000000000 --- a/src/NHibernate/Async/Param/NamedParameterSpecification.cs +++ /dev/null @@ -1,45 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Collections.Generic; -using System.Data.Common; -using System.Linq; -using NHibernate.Engine; -using NHibernate.SqlCommand; - -namespace NHibernate.Param -{ - using System.Threading.Tasks; - using System.Threading; - public partial class NamedParameterSpecification : AbstractExplicitParameterSpecification - { - - public override Task BindAsync(DbCommand command, IList sqlQueryParametersList, QueryParameters queryParameters, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - return BindAsync(command, sqlQueryParametersList, 0, sqlQueryParametersList, queryParameters, session, cancellationToken); - } - - public override async Task BindAsync(DbCommand command, IList multiSqlQueryParametersList, int singleSqlParametersOffset, IList sqlQueryParametersList, QueryParameters queryParameters, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - TypedValue typedValue = queryParameters.NamedParameters[name]; - string backTrackId = GetIdsForBackTrack(session.Factory).First(); // just the first because IType suppose the oders in certain sequence - foreach (int position in sqlQueryParametersList.GetEffectiveParameterLocations(backTrackId)) - { - await (ExpectedType.NullSafeSetAsync(command, GetPagingValue(typedValue.Value, session.Factory.Dialect, queryParameters), position + singleSqlParametersOffset, session, cancellationToken)).ConfigureAwait(false); - } - } - } -} \ No newline at end of file diff --git a/src/NHibernate/Async/Param/PositionalParameterSpecification.cs b/src/NHibernate/Async/Param/PositionalParameterSpecification.cs deleted file mode 100644 index 97d1bcb08cd..00000000000 --- a/src/NHibernate/Async/Param/PositionalParameterSpecification.cs +++ /dev/null @@ -1,49 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Collections.Generic; -using System.Data.Common; -using System.Linq; -using NHibernate.Engine; -using NHibernate.SqlCommand; -using NHibernate.Type; - -namespace NHibernate.Param -{ - using System.Threading.Tasks; - using System.Threading; - public partial class PositionalParameterSpecification : AbstractExplicitParameterSpecification - { - - public override Task BindAsync(DbCommand command, IList sqlQueryParametersList, QueryParameters queryParameters, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - return BindAsync(command, sqlQueryParametersList, 0, sqlQueryParametersList, queryParameters, session, cancellationToken); - } - - public override async Task BindAsync(DbCommand command, IList multiSqlQueryParametersList, int singleSqlParametersOffset, IList sqlQueryParametersList, QueryParameters queryParameters, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - IType type = ExpectedType; - object value = queryParameters.PositionalParameterValues[hqlPosition]; - - string backTrackId = GetIdsForBackTrack(session.Factory).First(); // just the first because IType suppose the oders in certain sequence - // an HQL positional parameter can appear more than once because a custom HQL-Function can duplicate it - foreach (int position in sqlQueryParametersList.GetEffectiveParameterLocations(backTrackId)) - { - await (type.NullSafeSetAsync(command, GetPagingValue(value, session.Factory.Dialect, queryParameters), position + singleSqlParametersOffset, session, cancellationToken)).ConfigureAwait(false); - } - } - } -} \ No newline at end of file diff --git a/src/NHibernate/Async/Param/QuerySkipParameterSpecification.cs b/src/NHibernate/Async/Param/QuerySkipParameterSpecification.cs deleted file mode 100644 index 3deb0711df4..00000000000 --- a/src/NHibernate/Async/Param/QuerySkipParameterSpecification.cs +++ /dev/null @@ -1,64 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Collections.Generic; -using System.Data.Common; -using System.Linq; -using NHibernate.Engine; -using NHibernate.SqlCommand; -using NHibernate.Type; - -namespace NHibernate.Param -{ - using System.Threading.Tasks; - using System.Threading; - public partial class QuerySkipParameterSpecification : IParameterSpecification - { - - #region IParameterSpecification Members - - public Task BindAsync(DbCommand command, IList sqlQueryParametersList, QueryParameters queryParameters, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - return BindAsync(command, sqlQueryParametersList, 0, sqlQueryParametersList, queryParameters, session, cancellationToken); - } - - public Task BindAsync(DbCommand command, IList multiSqlQueryParametersList, int singleSqlParametersOffset, IList sqlQueryParametersList, QueryParameters queryParameters, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - // The QuerySkipParameterSpecification is unique so we can use multiSqlQueryParametersList - var effectiveParameterLocations = multiSqlQueryParametersList.GetEffectiveParameterLocations(limitParametersNameForThisQuery).ToArray(); - if (effectiveParameterLocations.Length > 0) - { - // if the dialect does not support variable limits the parameter may was removed - int value = Loader.Loader.GetOffsetUsingDialect(queryParameters.RowSelection, session.Factory.Dialect) ?? queryParameters.RowSelection.FirstRow; - int position = effectiveParameterLocations[0]; - return type.NullSafeSetAsync(command, value, position, session, cancellationToken); - } - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - #endregion - } -} \ No newline at end of file diff --git a/src/NHibernate/Async/Param/QueryTakeParameterSpecification.cs b/src/NHibernate/Async/Param/QueryTakeParameterSpecification.cs deleted file mode 100644 index 2f2976db1eb..00000000000 --- a/src/NHibernate/Async/Param/QueryTakeParameterSpecification.cs +++ /dev/null @@ -1,64 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Collections.Generic; -using System.Data.Common; -using System.Linq; -using NHibernate.Engine; -using NHibernate.SqlCommand; -using NHibernate.Type; - -namespace NHibernate.Param -{ - using System.Threading.Tasks; - using System.Threading; - public partial class QueryTakeParameterSpecification : IParameterSpecification - { - - #region IParameterSpecification Members - - public Task BindAsync(DbCommand command, IList sqlQueryParametersList, QueryParameters queryParameters, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - return BindAsync(command, sqlQueryParametersList, 0, sqlQueryParametersList, queryParameters, session, cancellationToken); - } - - public Task BindAsync(DbCommand command, IList multiSqlQueryParametersList, int singleSqlParametersOffset, IList sqlQueryParametersList, QueryParameters queryParameters, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - // The QueryTakeParameterSpecification is unique so we can use multiSqlQueryParametersList - var effectiveParameterLocations = multiSqlQueryParametersList.GetEffectiveParameterLocations(limitParametersNameForThisQuery).ToArray(); - if (effectiveParameterLocations.Any()) - { - // if the dialect does not support variable limits the parameter may was removed - int value = Loader.Loader.GetLimitUsingDialect(queryParameters.RowSelection, session.Factory.Dialect) ?? queryParameters.RowSelection.MaxRows; - int position = effectiveParameterLocations.Single(); - return type.NullSafeSetAsync(command, value, position, session, cancellationToken); - } - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - #endregion - } -} \ No newline at end of file diff --git a/src/NHibernate/Async/Param/VersionTypeSeedParameterSpecification.cs b/src/NHibernate/Async/Param/VersionTypeSeedParameterSpecification.cs deleted file mode 100644 index 56bdd82c0c4..00000000000 --- a/src/NHibernate/Async/Param/VersionTypeSeedParameterSpecification.cs +++ /dev/null @@ -1,42 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Collections.Generic; -using System.Data.Common; -using System.Linq; -using NHibernate.Engine; -using NHibernate.SqlCommand; -using NHibernate.Type; - -namespace NHibernate.Param -{ - using System.Threading.Tasks; - using System.Threading; - public partial class VersionTypeSeedParameterSpecification : IParameterSpecification - { - - #region IParameterSpecification Members - - public async Task BindAsync(DbCommand command, IList sqlQueryParametersList, QueryParameters queryParameters, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - int position = sqlQueryParametersList.GetEffectiveParameterLocations(IdBackTrack).Single(); // version parameter can't appear more than once - await (type.NullSafeSetAsync(command, await (type.SeedAsync(session, cancellationToken)).ConfigureAwait(false), position, session, cancellationToken)).ConfigureAwait(false); - } - - public Task BindAsync(DbCommand command, IList multiSqlQueryParametersList, int singleSqlParametersOffset, IList sqlQueryParametersList, QueryParameters queryParameters, ISessionImplementor session, CancellationToken cancellationToken) - { - throw new NotSupportedException("Not supported for multiquery loader."); - } - - #endregion - } -} \ No newline at end of file diff --git a/src/NHibernate/Async/Persister/Collection/AbstractCollectionPersister.cs b/src/NHibernate/Async/Persister/Collection/AbstractCollectionPersister.cs index da37c811661..bd1732cbc70 100644 --- a/src/NHibernate/Async/Persister/Collection/AbstractCollectionPersister.cs +++ b/src/NHibernate/Async/Persister/Collection/AbstractCollectionPersister.cs @@ -106,99 +106,6 @@ public Task ReadKeyAsync(DbDataReader dr, string[] aliases, ISessionImpl return KeyType.NullSafeGetAsync(dr, aliases, session, null, cancellationToken); } - protected Task WriteKeyAsync(DbCommand st, object id, int i, ISessionImplementor session, CancellationToken cancellationToken) - { - if (id == null) - { - throw new ArgumentNullException("id", "Null key for collection: " + role); - } - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - return InternalWriteKeyAsync(); - async Task InternalWriteKeyAsync() - { - - await (KeyType.NullSafeSetAsync(st, id, i, session, cancellationToken)).ConfigureAwait(false); - return i + keyColumnAliases.Length; - } - } - - protected async Task WriteElementAsync(DbCommand st, object elt, int i, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - await (ElementType.NullSafeSetAsync(st, elt, i, elementColumnIsSettable, session, cancellationToken)).ConfigureAwait(false); - return i + ArrayHelper.CountTrue(elementColumnIsSettable); - } - - protected async Task WriteIndexAsync(DbCommand st, object idx, int i, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - await (IndexType.NullSafeSetAsync(st, IncrementIndexByBase(idx), i, indexColumnIsSettable, session, cancellationToken)).ConfigureAwait(false); - return i + ArrayHelper.CountTrue(indexColumnIsSettable); - } - - protected Task WriteElementToWhereAsync(DbCommand st, object elt, bool[] columnNullness, int i, ISessionImplementor session, CancellationToken cancellationToken) - { - if (elementIsPureFormula) - { - throw new AssertionFailure("cannot use a formula-based element in the where condition"); - } - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - return InternalWriteElementToWhereAsync(); - async Task InternalWriteElementToWhereAsync() - { - - var settable = Combine(elementColumnIsInPrimaryKey, columnNullness); - - await (ElementType.NullSafeSetAsync(st, elt, i, settable, session, cancellationToken)).ConfigureAwait(false); - return i + settable.Count(s => s); - } - } - - // Since v5.2 - [Obsolete("Use overload with columnNullness instead")] - protected Task WriteElementToWhereAsync(DbCommand st, object elt, int i, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - return WriteElementToWhereAsync(st, elt, null, i, session, cancellationToken); - } - - // No column nullness handling here: although a composite index could have null columns, the mapping - // current implementation forbirds this by forcing not-null to true on all columns. - protected Task WriteIndexToWhereAsync(DbCommand st, object index, int i, ISessionImplementor session, CancellationToken cancellationToken) - { - if (indexContainsFormula) - { - throw new AssertionFailure("cannot use a formula-based index in the where condition"); - } - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - return InternalWriteIndexToWhereAsync(); - async Task InternalWriteIndexToWhereAsync() - { - - await (IndexType.NullSafeSetAsync(st, IncrementIndexByBase(index), i, session, cancellationToken)).ConfigureAwait(false); - return i + indexColumnAliases.Length; - } - } - - protected async Task WriteIdentifierAsync(DbCommand st, object idx, int i, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - await (IdentifierType.NullSafeSetAsync(st, idx, i, session, cancellationToken)).ConfigureAwait(false); - return i + 1; - } - public async Task RemoveAsync(object id, ISessionImplementor session, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); @@ -223,7 +130,7 @@ public async Task RemoveAsync(object id, ISessionImplementor session, Cancellati try { //offset += expectation.Prepare(st, factory.ConnectionProvider.Driver); - await (WriteKeyAsync(st, id, offset, session, cancellationToken)).ConfigureAwait(false); + WriteKey(st, id, offset, session); if (useBatch) { await (session.Batcher.AddToBatchAsync(expectation, cancellationToken)).ConfigureAwait(false); @@ -344,7 +251,7 @@ public async Task DeleteRowsAsync(IPersistentCollection collection, object id, I var offset = 0; var count = 0; - foreach (var entry in await (collection.GetDeletesAsync(this, !deleteByIndex, cancellationToken)).ConfigureAwait(false)) + foreach (var entry in collection.GetDeletes(this, !deleteByIndex)) { DbCommand st; var expectation = Expectations.AppropriateExpectation(deleteCheckStyle); @@ -367,19 +274,19 @@ public async Task DeleteRowsAsync(IPersistentCollection collection, object id, I var loc = offset; if (hasIdentifier) { - await (WriteIdentifierAsync(st, entry, loc, session, cancellationToken)).ConfigureAwait(false); + WriteIdentifier(st, entry, loc, session); } else { - loc = await (WriteKeyAsync(st, id, loc, session, cancellationToken)).ConfigureAwait(false); + loc = WriteKey(st, id, loc, session); if (deleteByIndex) { - await (WriteIndexToWhereAsync(st, entry, loc, session, cancellationToken)).ConfigureAwait(false); + WriteIndexToWhere(st, entry, loc, session); } else { - await (WriteElementToWhereAsync(st, entry, columnNullness, loc, session, cancellationToken)).ConfigureAwait(false); + WriteElementToWhere(st, entry, columnNullness, loc, session); } } if (useBatch) @@ -449,7 +356,7 @@ public async Task InsertRowsAsync(IPersistentCollection collection, object id, I IEnumerable entries = collection.Entries(this); foreach (object entry in entries) { - if (await (collection.NeedsInsertingAsync(entry, i, elementType, cancellationToken)).ConfigureAwait(false)) + if (collection.NeedsInserting(entry, i, elementType)) { object entryId; if (!IsIdentifierAssignedByInsert) @@ -514,17 +421,17 @@ protected async Task PerformInsertAsync(object ownerId, IPersistentColle try { //offset += expectation.Prepare(st, factory.ConnectionProvider.Driver); - offset = await (WriteKeyAsync(st, ownerId, offset, session, cancellationToken)).ConfigureAwait(false); + offset = WriteKey(st, ownerId, offset, session); if (hasIdentifier) { entryId = collection.GetIdentifier(entry, index); - offset = await (WriteIdentifierAsync(st, entryId, offset, session, cancellationToken)).ConfigureAwait(false); + offset = WriteIdentifier(st, entryId, offset, session); } if (hasIndex) { - offset = await (WriteIndexAsync(st, collection.GetIndex(entry, index, this), offset, session, cancellationToken)).ConfigureAwait(false); + offset = WriteIndex(st, collection.GetIndex(entry, index, this), offset, session); } - await (WriteElementAsync(st, collection.GetElement(entry), offset, session, cancellationToken)).ConfigureAwait(false); + WriteElement(st, collection.GetElement(entry), offset, session); if (useBatch) { await (session.Batcher.AddToBatchAsync(expectation, cancellationToken)).ConfigureAwait(false); @@ -555,21 +462,6 @@ protected async Task PerformInsertAsync(object ownerId, IPersistentColle #region NH specific - #region IPostInsertIdentityPersister Members - - public Task BindSelectByUniqueKeyAsync( - ISessionImplementor session, - DbCommand selectCommand, - IBinder binder, - string[] suppliedPropertyNames, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - return binder.BindValuesAsync(selectCommand, cancellationToken); - } - #endregion /// /// Perform an SQL INSERT, and then retrieve a generated identifier. @@ -589,22 +481,6 @@ protected Task PerformInsertAsync(object ownerId, IPersistentCollection return identityDelegate.PerformInsertAsync(SqlInsertRowString, session, binder, cancellationToken); } - protected partial class GeneratedIdentifierBinder : IBinder - { - - public async Task BindValuesAsync(DbCommand cm, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - int offset = 0; - offset = await (persister.WriteKeyAsync(cm, ownerId, offset, session, cancellationToken)).ConfigureAwait(false); - if (persister.HasIndex) - { - offset = await (persister.WriteIndexAsync(cm, collection.GetIndex(entry, index, persister), offset, session, cancellationToken)).ConfigureAwait(false); - } - await (persister.WriteElementAsync(cm, collection.GetElement(entry), offset, session, cancellationToken)).ConfigureAwait(false); - } - } - #endregion } } diff --git a/src/NHibernate/Async/Persister/Collection/BasicCollectionPersister.cs b/src/NHibernate/Async/Persister/Collection/BasicCollectionPersister.cs index 01aee90c2c0..edd0ecb7f19 100644 --- a/src/NHibernate/Async/Persister/Collection/BasicCollectionPersister.cs +++ b/src/NHibernate/Async/Persister/Collection/BasicCollectionPersister.cs @@ -48,7 +48,7 @@ protected override async Task DoUpdateRowsAsync(object id, IPersistentColle int count = 0; foreach (object entry in entries) { - if (await (collection.NeedsUpdatingAsync(entry, i, ElementType, cancellationToken)).ConfigureAwait(false)) + if (collection.NeedsUpdating(entry, i, ElementType)) { int offset = 0; if (useBatch) @@ -71,24 +71,24 @@ protected override async Task DoUpdateRowsAsync(object id, IPersistentColle { //offset += expectation.Prepare(st, Factory.ConnectionProvider.Driver); - int loc = await (WriteElementAsync(st, collection.GetElement(entry), offset, session, cancellationToken)).ConfigureAwait(false); + int loc = WriteElement(st, collection.GetElement(entry), offset, session); if (hasIdentifier) { - await (WriteIdentifierAsync(st, collection.GetIdentifier(entry, i), loc, session, cancellationToken)).ConfigureAwait(false); + WriteIdentifier(st, collection.GetIdentifier(entry, i), loc, session); } else { - loc = await (WriteKeyAsync(st, id, loc, session, cancellationToken)).ConfigureAwait(false); + loc = WriteKey(st, id, loc, session); if (HasIndex && !indexContainsFormula) { - await (WriteIndexToWhereAsync(st, collection.GetIndex(entry, i, this), loc, session, cancellationToken)).ConfigureAwait(false); + WriteIndexToWhere(st, collection.GetIndex(entry, i, this), loc, session); } else { // No nullness handled on update: updates does not occurs with sets or bags, and // indexed collections allowing formula (maps) force their element columns to // not-nullable. - await (WriteElementToWhereAsync(st, collection.GetSnapshotElement(entry, i), null, loc, session, cancellationToken)).ConfigureAwait(false); + WriteElementToWhere(st, collection.GetSnapshotElement(entry, i), null, loc, session); } } diff --git a/src/NHibernate/Async/Persister/Collection/OneToManyPersister.cs b/src/NHibernate/Async/Persister/Collection/OneToManyPersister.cs index 16ebcbe9834..d12aa93a8df 100644 --- a/src/NHibernate/Async/Persister/Collection/OneToManyPersister.cs +++ b/src/NHibernate/Async/Persister/Collection/OneToManyPersister.cs @@ -53,7 +53,7 @@ protected override async Task DoUpdateRowsAsync(object id, IPersistentColle foreach (object entry in entries) { - if (await (collection.NeedsUpdatingAsync(entry, i, ElementType, cancellationToken)).ConfigureAwait(false)) + if (collection.NeedsUpdating(entry, i, ElementType)) { DbCommand st; // will still be issued when it used to be null @@ -70,10 +70,10 @@ protected override async Task DoUpdateRowsAsync(object id, IPersistentColle try { - int loc = await (WriteKeyAsync(st, id, offset, session, cancellationToken)).ConfigureAwait(false); + int loc = WriteKey(st, id, offset, session); // No columnNullness handling: the element is the entity key and should not contain null // values. - await (WriteElementToWhereAsync(st, collection.GetSnapshotElement(entry, i), null, loc, session, cancellationToken)).ConfigureAwait(false); + WriteElementToWhere(st, collection.GetSnapshotElement(entry, i), null, loc, session); if (useBatch) { await (session.Batcher.AddToBatchAsync(deleteExpectation, cancellationToken)).ConfigureAwait(false); @@ -117,7 +117,7 @@ protected override async Task DoUpdateRowsAsync(object id, IPersistentColle IEnumerable entries = collection.Entries(this); foreach (object entry in entries) { - if (await (collection.NeedsUpdatingAsync(entry, i, ElementType, cancellationToken)).ConfigureAwait(false)) + if (collection.NeedsUpdating(entry, i, ElementType)) { DbCommand st; if (useBatch) @@ -134,14 +134,14 @@ protected override async Task DoUpdateRowsAsync(object id, IPersistentColle try { //offset += insertExpectation.Prepare(st, Factory.ConnectionProvider.Driver); - int loc = await (WriteKeyAsync(st, id, offset, session, cancellationToken)).ConfigureAwait(false); + int loc = WriteKey(st, id, offset, session); if (HasIndex && !indexContainsFormula) { - loc = await (WriteIndexToWhereAsync(st, collection.GetIndex(entry, i, this), loc, session, cancellationToken)).ConfigureAwait(false); + loc = WriteIndexToWhere(st, collection.GetIndex(entry, i, this), loc, session); } // No columnNullness handling: the element is the entity key and should not contain null // values. - await (WriteElementToWhereAsync(st, collection.GetElement(entry), null, loc, session, cancellationToken)).ConfigureAwait(false); + WriteElementToWhere(st, collection.GetElement(entry), null, loc, session); if (useBatch) { await (session.Batcher.AddToBatchAsync(insertExpectation, cancellationToken)).ConfigureAwait(false); diff --git a/src/NHibernate/Async/Persister/Entity/AbstractEntityPersister.cs b/src/NHibernate/Async/Persister/Entity/AbstractEntityPersister.cs index 1d466b213e6..00e80c36bd5 100644 --- a/src/NHibernate/Async/Persister/Entity/AbstractEntityPersister.cs +++ b/src/NHibernate/Async/Persister/Entity/AbstractEntityPersister.cs @@ -48,19 +48,6 @@ public abstract partial class AbstractEntityPersister : IOuterJoinLoadable, IQue ISupportSelectModeJoinable, ICompositeKeyPostInsertIdentityPersister, ISupportLazyPropsJoinable { - private partial class GeneratedIdentifierBinder : IBinder - { - - public virtual Task BindValuesAsync(DbCommand ps, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - return entityPersister.DehydrateAsync(null, fields, notNull, entityPersister.propertyColumnInsertable, 0, ps, session, cancellationToken); - } - } - public Task InitializeLazyPropertiesAsync( DbDataReader rs, object id, object entity, string[][] suffixedPropertyColumns, string[] uninitializedLazyProperties, bool allLazyProperties, ISessionImplementor session, CancellationToken cancellationToken) @@ -137,7 +124,7 @@ public async Task GetDatabaseSnapshotAsync(object id, ISessionImplemen DbDataReader rs = null; try { - await (IdentifierType.NullSafeSetAsync(st, id, 0, session, cancellationToken)).ConfigureAwait(false); + IdentifierType.NullSafeSet(st, id, 0, session); rs = await (session.Batcher.ExecuteReaderAsync(st, cancellationToken)).ConfigureAwait(false); if (!await (rs.ReadAsync(cancellationToken)).ConfigureAwait(false)) @@ -197,7 +184,7 @@ public Task ForceVersionIncrementAsync(object id, object currentVersion, async Task InternalForceVersionIncrementAsync() { - object nextVersion = await (VersionType.NextAsync(currentVersion, session, cancellationToken)).ConfigureAwait(false); + object nextVersion = VersionType.Next(currentVersion, session); if (log.IsDebugEnabled()) { log.Debug("Forcing version increment [{0}; {1} -> {2}]", @@ -214,9 +201,9 @@ async Task InternalForceVersionIncrementAsync() var st = await (session.Batcher.PrepareCommandAsync(versionIncrementCommand.CommandType, versionIncrementCommand.Text, versionIncrementCommand.ParameterTypes, cancellationToken)).ConfigureAwait(false); try { - await (VersionType.NullSafeSetAsync(st, nextVersion, 0, session, cancellationToken)).ConfigureAwait(false); - await (IdentifierType.NullSafeSetAsync(st, id, 1, session, cancellationToken)).ConfigureAwait(false); - await (VersionType.NullSafeSetAsync(st, currentVersion, 1 + IdentifierColumnSpan, session, cancellationToken)).ConfigureAwait(false); + VersionType.NullSafeSet(st, nextVersion, 0, session); + IdentifierType.NullSafeSet(st, id, 1, session); + VersionType.NullSafeSet(st, currentVersion, 1 + IdentifierColumnSpan, session); Check(await (session.Batcher.ExecuteNonQueryAsync(st, cancellationToken)).ConfigureAwait(false), id, 0, expectation, st); } finally @@ -257,7 +244,7 @@ public async Task GetCurrentVersionAsync(object id, ISessionImplementor DbDataReader rs = null; try { - await (IdentifierType.NullSafeSetAsync(st, id, 0, session, cancellationToken)).ConfigureAwait(false); + IdentifierType.NullSafeSet(st, id, 0, session); rs = await (session.Batcher.ExecuteReaderAsync(st, cancellationToken)).ConfigureAwait(false); if (!await (rs.ReadAsync(cancellationToken)).ConfigureAwait(false)) { @@ -341,62 +328,6 @@ public async Task CacheByUniqueKeysAsync(object entity, ISessionImplementor sess } } - protected Task DehydrateAsync(object id, object[] fields, bool[] includeProperty, bool[][] includeColumns, int j, DbCommand st, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - return DehydrateAsync(id, fields, null, includeProperty, includeColumns, j, st, session, 0, cancellationToken); - } - - /// Marshall the fields of a persistent instance to a prepared statement - protected async Task DehydrateAsync(object id, object[] fields, object rowId, bool[] includeProperty, bool[][] includeColumns, int table, - DbCommand statement, ISessionImplementor session, int index, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - if (log.IsDebugEnabled()) - { - log.Debug("Dehydrating entity: {0}", MessageHelper.InfoString(this, id, Factory)); - } - - // there's a pretty strong coupling between the order of the SQL parameter - // construction and the actual order of the parameter collection. - - for (int i = 0; i < entityMetamodel.PropertySpan; i++) - { - if (includeProperty[i] && IsPropertyOfTable(i, table)) - { - try - { - await (PropertyTypes[i].NullSafeSetAsync(statement, fields[i], index, includeColumns[i], session, cancellationToken)).ConfigureAwait(false); - index += ArrayHelper.CountTrue(includeColumns[i]); //TODO: this is kinda slow... - } - catch (OperationCanceledException) { throw; } - catch (Exception ex) - { - throw new PropertyValueException("Error dehydrating property value for", EntityName, entityMetamodel.PropertyNames[i], ex); - } - } - } - - if (rowId != null) - { - // TODO H3.2 : support to set the rowId - // TransactionManager.manager.SetObject(ps, index, rowId); - // index += 1; - throw new NotImplementedException("support to set the rowId"); - } - else if (id != null) - { - var property = GetIdentiferProperty(table); - await (property.Type.NullSafeSetAsync(statement, id, index, session, cancellationToken)).ConfigureAwait(false); - index += property.Type.GetColumnSpan(factory); - } - - return index; - } - /// /// Unmarshall the fields of a persistent instance from a result set, /// without resolving associations or collections @@ -451,7 +382,7 @@ private async Task HydrateAsync(DbDataReader rs, object id, object obj { //TODO: I am not so sure about the exception handling in this bit! sequentialSelect = await (session.Batcher.PrepareCommandAsync(CommandType.Text, sequentialSql, IdentifierType.SqlTypes(factory), cancellationToken)).ConfigureAwait(false); - await (IdentifierType.NullSafeSetAsync(sequentialSelect, id, 0, session, cancellationToken)).ConfigureAwait(false); + IdentifierType.NullSafeSet(sequentialSelect, id, 0, session); sequentialResultSet = await (session.Batcher.ExecuteReaderAsync(sequentialSelect, cancellationToken)).ConfigureAwait(false); if (!await (sequentialResultSet.ReadAsync(cancellationToken)).ConfigureAwait(false)) { @@ -558,23 +489,6 @@ protected Task InsertAsync(object[] fields, bool[] notNull, SqlCommandIn } } - public async Task BindSelectByUniqueKeyAsync( - ISessionImplementor session, - DbCommand selectCommand, - IBinder binder, - string[] suppliedPropertyNames, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - var propertyNames = GetUniqueKeyPropertyNames(suppliedPropertyNames); - var parameterTypes = propertyNames.ToArray(p => GetPropertyType(p)); - var entity = binder.Entity; - for (var i = 0; i < propertyNames.Length; i++) - { - var uniqueKeyValue = GetPropertyValue(entity, propertyNames[i]); - await (parameterTypes[i].NullSafeSetAsync(selectCommand, uniqueKeyValue, i, session, cancellationToken)).ConfigureAwait(false); - } - } - /// /// Perform an SQL INSERT. /// @@ -632,7 +546,7 @@ protected async Task InsertAsync(object id, object[] fields, bool[] notNull, int // state at the time the insert was issued (cos of foreign key constraints). // Not necessarily the obect's current state - await (DehydrateAsync(tableId, fields, null, notNull, propertyColumnInsertable, j, insertCmd, session, index, cancellationToken)).ConfigureAwait(false); + Dehydrate(tableId, fields, null, notNull, propertyColumnInsertable, j, insertCmd, session, index); if (useBatch) { @@ -742,13 +656,13 @@ protected async Task UpdateAsync(object id, object[] fields, object[] oldF //index += expectation.Prepare(statement, factory.ConnectionProvider.Driver); //Now write the values of fields onto the prepared statement - index = await (DehydrateAsync(id, fields, rowId, includeProperty, propertyColumnUpdateable, j, statement, session, index, cancellationToken)).ConfigureAwait(false); + index = Dehydrate(id, fields, rowId, includeProperty, propertyColumnUpdateable, j, statement, session, index); // Write any appropriate versioning conditional parameters if (useVersion && Versioning.OptimisticLock.Version == entityMetamodel.OptimisticLockMode) { if (CheckVersion(includeProperty)) - await (VersionType.NullSafeSetAsync(statement, oldVersion, index, session, cancellationToken)).ConfigureAwait(false); + VersionType.NullSafeSet(statement, oldVersion, index, session); } else if (entityMetamodel.OptimisticLockMode > Versioning.OptimisticLock.Version && oldFields != null) { @@ -766,7 +680,7 @@ protected async Task UpdateAsync(object id, object[] fields, object[] oldF if (include) { bool[] settable = types[i].ToColumnNullness(oldFields[i], Factory); - await (types[i].NullSafeSetAsync(statement, oldFields[i], index, settable, session, cancellationToken)).ConfigureAwait(false); + types[i].NullSafeSet(statement, oldFields[i], index, settable, session); index += ArrayHelper.CountTrue(settable); } } @@ -877,13 +791,13 @@ public async Task DeleteAsync(object id, object version, int j, object obj, SqlC // Do the key. The key is immutable so we can use the _current_ object state - not necessarily // the state at the time the delete was issued var property = GetIdentiferProperty(j); - await (property.Type.NullSafeSetAsync(statement, tableId, index, session, cancellationToken)).ConfigureAwait(false); + property.Type.NullSafeSet(statement, tableId, index, session); index += property.Type.GetColumnSpan(factory); // We should use the _current_ object state (ie. after any updates that occurred during flush) if (useVersion) { - await (VersionType.NullSafeSetAsync(statement, version, index, session, cancellationToken)).ConfigureAwait(false); + VersionType.NullSafeSet(statement, version, index, session); } else if (entityMetamodel.OptimisticLockMode > Versioning.OptimisticLock.Version && loadedState != null) { @@ -897,7 +811,7 @@ public async Task DeleteAsync(object id, object version, int j, object obj, SqlC // excluded from optimistic locking by optimistic-lock="false" bool[] settable = types[i].ToColumnNullness(loadedState[i], Factory); - await (types[i].NullSafeSetAsync(statement, loadedState[i], index, settable, session, cancellationToken)).ConfigureAwait(false); + types[i].NullSafeSet(statement, loadedState[i], index, settable, session); index += ArrayHelper.CountTrue(settable); } } @@ -1127,88 +1041,6 @@ public Task LoadAsync(object id, object optionalObject, LockMode lockMod } } - public virtual async Task FindDirtyAsync(object[] currentState, object[] previousState, object entity, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - int[] props = await (TypeHelper.FindDirtyAsync( - entityMetamodel.Properties, currentState, previousState, propertyColumnUpdateable, session, cancellationToken)).ConfigureAwait(false); - - if (props == null) - { - return null; - } - else - { - LogDirtyProperties(props); - return props; - } - } - - public virtual async Task FindModifiedAsync(object[] old, object[] current, object entity, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - int[] props = await (TypeHelper.FindModifiedAsync( - entityMetamodel.Properties, current, old, propertyColumnUpdateable, session, cancellationToken)).ConfigureAwait(false); - if (props == null) - { - return null; - } - else - { - LogDirtyProperties(props); - return props; - } - } - - public virtual async Task IsTransientAsync(object entity, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - object id; - if (CanExtractIdOutOfEntity) - { - id = GetIdentifier(entity); - } - else - { - id = null; - } - // we *always* assume an instance with a null - // identifier or no identifier property is unsaved! - if (id == null) - { - return true; - } - - // check the id unsaved-value - // We do this first so we don't have to hydrate the version property if the id property already gives us the info we need (NH-3505). - bool? result2 = entityMetamodel.IdentifierProperty.UnsavedValue.IsUnsaved(id); - if (result2.HasValue) - { - return result2; - } - - // check the version unsaved-value, if appropriate - if (IsVersioned) - { - object version = GetVersion(entity); - bool? result = entityMetamodel.VersionProperty.UnsavedValue.IsUnsaved(version); - if (result.HasValue) - { - return result; - } - } - - // check to see if it is in the second-level cache - if (HasCache && session.CacheMode.HasFlag(CacheMode.Get)) - { - CacheKey ck = session.GenerateCacheKey(id, IdentifierType, RootEntityName); - if (await (Cache.GetAsync(ck, session.Timestamp, cancellationToken)).ConfigureAwait(false) != null) - return false; - } - - return null; - } - public Task ProcessInsertGeneratedPropertiesAsync(object id, object entity, object[] state, ISessionImplementor session, CancellationToken cancellationToken) { if (!HasInsertGeneratedProperties) @@ -1283,7 +1115,7 @@ private async Task ProcessGeneratedPropertiesWithGeneratedSqlAsync(object id, ob DbDataReader rs = null; try { - await (IdentifierType.NullSafeSetAsync(cmd, id, 0, session, cancellationToken)).ConfigureAwait(false); + IdentifierType.NullSafeSet(cmd, id, 0, session); rs = await (session.Batcher.ExecuteReaderAsync(cmd, cancellationToken)).ConfigureAwait(false); if (!await (rs.ReadAsync(cancellationToken)).ConfigureAwait(false)) { @@ -1403,7 +1235,7 @@ async Task InternalGetNaturalIdentifierSnapshotAsync() DbDataReader rs = null; try { - await (IdentifierType.NullSafeSetAsync(ps, id, 0, session, cancellationToken)).ConfigureAwait(false); + IdentifierType.NullSafeSet(ps, id, 0, session); rs = await (session.Batcher.ExecuteReaderAsync(ps, cancellationToken)).ConfigureAwait(false); //if there is no resulting row, return null if (!await (rs.ReadAsync(cancellationToken)).ConfigureAwait(false)) diff --git a/src/NHibernate/Async/Persister/Entity/IEntityPersister.cs b/src/NHibernate/Async/Persister/Entity/IEntityPersister.cs index db1e4a16c1c..78786f86309 100644 --- a/src/NHibernate/Async/Persister/Entity/IEntityPersister.cs +++ b/src/NHibernate/Async/Persister/Entity/IEntityPersister.cs @@ -31,24 +31,6 @@ public partial interface IEntityPersister : IOptimisticCacheSource #region stuff that is persister-centric and/or EntityInfo-centric - /// Locate the property-indices of all properties considered to be dirty. - /// The current state of the entity (the state to be checked). - /// The previous state of the entity (the state to be checked against). - /// The entity for which we are checking state dirtiness. - /// The session in which the check is occurring. - /// A cancellation token that can be used to cancel the work - /// or the indices of the dirty properties - Task FindDirtyAsync(object[] currentState, object[] previousState, object entity, ISessionImplementor session, CancellationToken cancellationToken); - - /// Locate the property-indices of all properties considered to be dirty. - /// The old state of the entity. - /// The current state of the entity. - /// The entity for which we are checking state modification. - /// The session in which the check is occurring. - /// A cancellation token that can be used to cancel the work - /// return or the indicies of the modified properties - Task FindModifiedAsync(object[] old, object[] current, object entity, ISessionImplementor session, CancellationToken cancellationToken); - /// /// Retrieve the current state of the natural-id properties from the database. /// @@ -136,9 +118,6 @@ Task UpdateAsync( #endregion #region stuff that is tuplizer-centric, but is passed a session - /// Is this a new transient instance? - Task IsTransientAsync(object obj, ISessionImplementor session, CancellationToken cancellationToken); - /// /// Perform a select to retrieve the values of any generated properties /// back from the database, injecting these generated values into the diff --git a/src/NHibernate/Async/SqlCommand/SqlCommandImpl.cs b/src/NHibernate/Async/SqlCommand/SqlCommandImpl.cs deleted file mode 100644 index 073d12c405f..00000000000 --- a/src/NHibernate/Async/SqlCommand/SqlCommandImpl.cs +++ /dev/null @@ -1,93 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Collections.Generic; -using System.Data.Common; -using System.Linq; -using NHibernate.Engine; -using NHibernate.Param; -using NHibernate.SqlTypes; - -namespace NHibernate.SqlCommand -{ - using System.Threading.Tasks; - using System.Threading; - public partial interface ISqlCommand - { - - /// - /// Bind the appropriate value into the given command. - /// - /// The command into which the value should be bound. - /// The parameter-list of the whole query of the command. - /// The offset from where start the list of , in the given , for the this . - /// The session against which the current execution is occurring. - /// A cancellation token that can be used to cancel the work - /// - /// Suppose the is composed by two queries. The for the first query is zero. - /// If the first query in has 12 parameters (size of its SqlType array) the offset to bind all s, of the second query in the - /// , is 12 (for the first query we are using from 0 to 11). - /// - Task BindAsync(DbCommand command, IList commandQueryParametersList, int singleSqlParametersOffset, ISessionImplementor session, CancellationToken cancellationToken); - - /// - /// Bind the appropriate value into the given command. - /// - /// The command into which the value should be bound. - /// The session against which the current execution is occurring. - /// A cancellation token that can be used to cancel the work - /// - /// Use this method when the contains just 'this' instance of . - /// Use the overload when the contains more instances of . - /// - Task BindAsync(DbCommand command, ISessionImplementor session, CancellationToken cancellationToken); - } - - public partial class SqlCommandImpl : ISqlCommand - { - - /// - /// Bind the appropriate value into the given command. - /// - /// The command into which the value should be bound. - /// The parameter-list of the whole query of the command. - /// The offset from where start the list of , in the given , for the this . - /// The session against which the current execution is occuring. - /// A cancellation token that can be used to cancel the work - public async Task BindAsync(DbCommand command, IList commandQueryParametersList, int singleSqlParametersOffset, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - foreach (IParameterSpecification parameterSpecification in Specifications) - { - await (parameterSpecification.BindAsync(command, commandQueryParametersList, singleSqlParametersOffset, SqlQueryParametersList, QueryParameters, session, cancellationToken)).ConfigureAwait(false); - } - } - - /// - /// Bind the appropriate value into the given command. - /// - /// The command into which the value should be bound. - /// The session against which the current execution is occuring. - /// A cancellation token that can be used to cancel the work - /// - /// Use this method when the contains just 'this' instance of . - /// Use the overload when the contains more instances of . - /// - public async Task BindAsync(DbCommand command, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - foreach (IParameterSpecification parameterSpecification in Specifications) - { - await (parameterSpecification.BindAsync(command, SqlQueryParametersList, QueryParameters, session, cancellationToken)).ConfigureAwait(false); - } - } - } -} \ No newline at end of file diff --git a/src/NHibernate/Async/Type/AbstractBinaryType.cs b/src/NHibernate/Async/Type/AbstractBinaryType.cs deleted file mode 100644 index ebe6d864485..00000000000 --- a/src/NHibernate/Async/Type/AbstractBinaryType.cs +++ /dev/null @@ -1,67 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Collections; -using System.Data.Common; -using System.Text; -using NHibernate.Engine; -using NHibernate.SqlTypes; -using NHibernate.Util; - -namespace NHibernate.Type -{ - using System.Threading.Tasks; - using System.Threading; - public abstract partial class AbstractBinaryType : MutableType, IVersionType, IComparer - { - - #region IVersionType Members - - // Note : simply returns null for seed() and next() as the only known - // application of binary types for versioning is for use with the - // TIMESTAMP datatype supported by Sybase and SQL Server, which - // are completely db-generated values... - - public Task NextAsync(object current, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Next(current, session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public Task SeedAsync(ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Seed(session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - #endregion - } -} diff --git a/src/NHibernate/Async/Type/AbstractDateTimeType.cs b/src/NHibernate/Async/Type/AbstractDateTimeType.cs deleted file mode 100644 index 827ac034995..00000000000 --- a/src/NHibernate/Async/Type/AbstractDateTimeType.cs +++ /dev/null @@ -1,51 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Data.Common; -using System.Globalization; -using NHibernate.Engine; -using NHibernate.SqlTypes; - -namespace NHibernate.Type -{ - using System.Threading.Tasks; - using System.Threading; - public abstract partial class AbstractDateTimeType : PrimitiveType, IIdentifierType, ILiteralType, IVersionType - { - - #region IVersionType Members - - /// - public Task NextAsync(object current, ISessionImplementor session, CancellationToken cancellationToken) => - SeedAsync(session, cancellationToken); - - /// - public virtual Task SeedAsync(ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Seed(session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - #endregion - } -} diff --git a/src/NHibernate/Async/Type/AbstractType.cs b/src/NHibernate/Async/Type/AbstractType.cs index 25c02b7c6c2..cb64b78fcf7 100644 --- a/src/NHibernate/Async/Type/AbstractType.cs +++ b/src/NHibernate/Async/Type/AbstractType.cs @@ -93,32 +93,6 @@ public virtual Task BeforeAssembleAsync(object cached, ISessionImplementor sessi } } - /// - /// Should the parent be considered dirty, given both the old and current - /// field or element value? - /// - /// The old value - /// The current value - /// The is not used by this method. - /// A cancellation token that can be used to cancel the work - /// true if the field is dirty - /// This method uses IType.Equals(object, object) to determine the value of IsDirty. - public virtual Task IsDirtyAsync(object old, object current, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(IsDirty(old, current, session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - /// /// Retrieves an instance of the mapped class, or the identifier of an entity /// or collection from a . @@ -188,22 +162,6 @@ public virtual Task SemiResolveAsync(object value, ISessionImplementor s } } - /// - /// Says whether the value has been modified - /// - public virtual Task IsModifiedAsync( - object old, - object current, - bool[] checkable, - ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - return IsDirtyAsync(old, current, session, cancellationToken); - } - public virtual Task ReplaceAsync(object original, object target, ISessionImplementor session, object owner, IDictionary copyCache, ForeignKeyDirection foreignKeyDirection, CancellationToken cancellationToken) { @@ -239,13 +197,5 @@ public abstract Task ReplaceAsync(object original, object current, ISess /// public abstract Task NullSafeGetAsync(DbDataReader rs, string name, ISessionImplementor session, Object owner, CancellationToken cancellationToken); - - /// - public abstract Task NullSafeSetAsync(DbCommand st, object value, int index, bool[] settable, ISessionImplementor session, CancellationToken cancellationToken); - - /// - public abstract Task NullSafeSetAsync(DbCommand st, object value, int index, ISessionImplementor session, CancellationToken cancellationToken); - - public abstract Task IsDirtyAsync(object old, object current, bool[] checkable, ISessionImplementor session, CancellationToken cancellationToken); } } diff --git a/src/NHibernate/Async/Type/AnyType.cs b/src/NHibernate/Async/Type/AnyType.cs index ff030de2f1a..bc4d5abe3f0 100644 --- a/src/NHibernate/Async/Type/AnyType.cs +++ b/src/NHibernate/Async/Type/AnyType.cs @@ -71,48 +71,6 @@ public override Task SemiResolveAsync(object value, ISessionImplementor throw new NotSupportedException("any mappings may not form part of a property-ref"); } - public override async Task NullSafeSetAsync(DbCommand st, object value, int index, bool[] settable, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - object id; - string entityName; - if (value == null) - { - id = null; - entityName = null; - } - else - { - entityName = session.BestGuessEntityName(value); - id = await (ForeignKeys.GetEntityIdentifierIfNotUnsavedAsync(entityName, value, session, cancellationToken)).ConfigureAwait(false); - } - - // metaType is assumed to be single-column type - if (settable == null || settable[0]) - { - await (metaType.NullSafeSetAsync(st, entityName, index, session, cancellationToken)).ConfigureAwait(false); - } - if (settable == null) - { - await (identifierType.NullSafeSetAsync(st, id, index + 1, session, cancellationToken)).ConfigureAwait(false); - } - else - { - bool[] idsettable = new bool[settable.Length - 1]; - Array.Copy(settable, 1, idsettable, 0, idsettable.Length); - await (identifierType.NullSafeSetAsync(st, id, index + 1, idsettable, session, cancellationToken)).ConfigureAwait(false); - } - } - - public override Task NullSafeSetAsync(DbCommand st, object value, int index, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - return NullSafeSetAsync(st, value, index, null, session, cancellationToken); - } - public override Task AssembleAsync(object cached, ISessionImplementor session, object owner, CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) @@ -123,35 +81,7 @@ public override Task AssembleAsync(object cached, ISessionImplementor se return (e == null) ? Task.FromResult(null ): session.InternalLoadAsync(e.EntityName, e.Id, false, false, cancellationToken); } - public override async Task DisassembleAsync(object value, ISessionImplementor session, object owner, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - return value == null - ? null - : new ObjectTypeCacheEntry - { - EntityName = session.BestGuessEntityName(value), - Id = await (ForeignKeys.GetEntityIdentifierIfNotUnsavedAsync(session.BestGuessEntityName(value), value, session, cancellationToken)).ConfigureAwait(false) - }; - } - - public override async Task ReplaceAsync(object original, object current, ISessionImplementor session, object owner, - IDictionary copiedAlready, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - if (original == null) - { - return null; - } - else - { - string entityName = session.BestGuessEntityName(original); - object id = await (ForeignKeys.GetEntityIdentifierIfNotUnsavedAsync(entityName, original, session, cancellationToken)).ConfigureAwait(false); - return await (session.InternalLoadAsync(entityName, id, false, false, cancellationToken)).ConfigureAwait(false); - } - } - - public Task GetPropertyValueAsync(Object component, int i, ISessionImplementor session, CancellationToken cancellationToken) + public override Task DisassembleAsync(object value, ISessionImplementor session, object owner, CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) { @@ -159,7 +89,7 @@ public Task GetPropertyValueAsync(Object component, int i, ISessionImple } try { - return i == 0 ? Task.FromResult(session.BestGuessEntityName(component) ): IdAsync(component, session, cancellationToken); + return Task.FromResult(Disassemble(value, session, owner)); } catch (Exception ex) { @@ -167,47 +97,30 @@ public Task GetPropertyValueAsync(Object component, int i, ISessionImple } } - public async Task GetPropertyValuesAsync(object component, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - return new object[] { session.BestGuessEntityName(component), await (IdAsync(component, session, cancellationToken)).ConfigureAwait(false) }; - } - - private static async Task IdAsync(object component, ISessionImplementor session, CancellationToken cancellationToken) + public override Task ReplaceAsync(object original, object current, ISessionImplementor session, object owner, + IDictionary copiedAlready, CancellationToken cancellationToken) { - cancellationToken.ThrowIfCancellationRequested(); - try + if (cancellationToken.IsCancellationRequested) { - return await (ForeignKeys.GetEntityIdentifierIfNotUnsavedAsync(session.BestGuessEntityName(component), component, session, cancellationToken)).ConfigureAwait(false); + return Task.FromCanceled(cancellationToken); } - catch (TransientObjectException) + try { - return null; + if (original == null) + { + return Task.FromResult(null); + } + else + { + string entityName = session.BestGuessEntityName(original); + object id = ForeignKeys.GetEntityIdentifierIfNotUnsaved(entityName, original, session); + return session.InternalLoadAsync(entityName, id, false, false, cancellationToken); + } } - } - - public override Task IsDirtyAsync(object old, object current, bool[] checkable, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) + catch (Exception ex) { - return Task.FromCanceled(cancellationToken); + return Task.FromException(ex); } - //TODO!!! - return IsDirtyAsync(old, current, session, cancellationToken); - } - - public override async Task IsModifiedAsync(object old, object current, bool[] checkable, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - if (current == null) - return old != null; - if (old == null) - return current != null; - ObjectTypeCacheEntry holder = (ObjectTypeCacheEntry)old; - bool[] idcheckable = new bool[checkable.Length - 1]; - Array.Copy(checkable, 1, idcheckable, 0, idcheckable.Length); - return (checkable[0] && !holder.EntityName.Equals(session.BestGuessEntityName(current))) || - await (identifierType.IsModifiedAsync(holder.Id, await (IdAsync(current, session, cancellationToken)).ConfigureAwait(false), idcheckable, session, cancellationToken)).ConfigureAwait(false); } private Task ResolveAnyAsync(string entityName, object id, ISessionImplementor session, CancellationToken cancellationToken) diff --git a/src/NHibernate/Async/Type/ArrayType.cs b/src/NHibernate/Async/Type/ArrayType.cs index e3c4fcb9d2c..ef629ef0135 100644 --- a/src/NHibernate/Async/Type/ArrayType.cs +++ b/src/NHibernate/Async/Type/ArrayType.cs @@ -24,30 +24,6 @@ namespace NHibernate.Type public partial class ArrayType : CollectionType { - /// - /// - /// - /// - /// - /// - /// - /// A cancellation token that can be used to cancel the work - public override Task NullSafeSetAsync(DbCommand st, object value, int index, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return base.NullSafeSetAsync(st, session.PersistenceContext.GetCollectionHolder(value), index, session, cancellationToken); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - public override async Task ReplaceElementsAsync(object original, object target, object owner, IDictionary copyCache, ISessionImplementor session, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); diff --git a/src/NHibernate/Async/Type/ByteType.cs b/src/NHibernate/Async/Type/ByteType.cs deleted file mode 100644 index c908d33432e..00000000000 --- a/src/NHibernate/Async/Type/ByteType.cs +++ /dev/null @@ -1,57 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Collections; -using System.Data; -using System.Data.Common; -using NHibernate.Engine; -using NHibernate.SqlTypes; - -namespace NHibernate.Type -{ - using System.Threading.Tasks; - using System.Threading; - public partial class ByteType : PrimitiveType, IDiscriminatorType, IVersionType - { - - public virtual Task NextAsync(object current, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Next(current, session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public virtual Task SeedAsync(ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Seed(session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - } -} diff --git a/src/NHibernate/Async/Type/ClassMetaType.cs b/src/NHibernate/Async/Type/ClassMetaType.cs index 71dab9deb5b..1a078045dae 100644 --- a/src/NHibernate/Async/Type/ClassMetaType.cs +++ b/src/NHibernate/Async/Type/ClassMetaType.cs @@ -52,46 +52,6 @@ public override Task NullSafeGetAsync(DbDataReader rs,string name,ISessi } } - public override Task NullSafeSetAsync(DbCommand st, object value, int index, bool[] settable, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - if (settable[0]) return NullSafeSetAsync(st, value, index, session, cancellationToken); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public override Task NullSafeSetAsync(DbCommand st,object value,int index,ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - NullSafeSet(st, value, index, session); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public override async Task IsDirtyAsync(object old, object current, bool[] checkable, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - return checkable[0] && await (IsDirtyAsync(old, current, session, cancellationToken)).ConfigureAwait(false); - } - public override Task ReplaceAsync(object original, object current, ISessionImplementor session, object owner, System.Collections.IDictionary copiedAlready, CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) diff --git a/src/NHibernate/Async/Type/CollectionType.cs b/src/NHibernate/Async/Type/CollectionType.cs index b103b445c22..68a9e55142d 100644 --- a/src/NHibernate/Async/Type/CollectionType.cs +++ b/src/NHibernate/Async/Type/CollectionType.cs @@ -47,40 +47,6 @@ public override Task NullSafeGetAsync(DbDataReader rs, string[] name, IS return ResolveIdentifierAsync(null, session, owner, cancellationToken); } - public override Task NullSafeSetAsync(DbCommand st, object value, int index, bool[] settable, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - NullSafeSet(st, value, index, settable, session); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public override Task NullSafeSetAsync(DbCommand cmd, object value, int index, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - NullSafeSet(cmd, value, index, session); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - public override async Task DisassembleAsync(object value, ISessionImplementor session, object owner, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); @@ -131,15 +97,6 @@ public override async Task AssembleAsync(object cached, ISessionImplemen } } - public override async Task IsDirtyAsync(object old, object current, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - // collections don't dirty an unversioned parent entity - - // TODO: I don't like this implementation; it would be better if this was handled by SearchForDirtyCollections(); - return IsOwnerVersioned(session) && await (base.IsDirtyAsync(old, current, session, cancellationToken)).ConfigureAwait(false); - } - public override Task HydrateAsync(DbDataReader rs, string[] name, ISessionImplementor session, object owner, CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) @@ -279,32 +236,6 @@ public virtual async Task ReplaceElementsAsync(object original, object t return target; } - public override Task IsDirtyAsync(object old, object current, bool[] checkable, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - return IsDirtyAsync(old, current, session, cancellationToken); - } - - public override Task IsModifiedAsync(object oldHydratedState, object currentState, bool[] checkable, - ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(IsModified(oldHydratedState, currentState, checkable, session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - /// /// Get the key value from the owning entity instance. It is usually the identifier, but it might be some /// other unique key, in the case of a property-ref. diff --git a/src/NHibernate/Async/Type/ComponentType.cs b/src/NHibernate/Async/Type/ComponentType.cs index 999852e447b..1aa095d095f 100644 --- a/src/NHibernate/Async/Type/ComponentType.cs +++ b/src/NHibernate/Async/Type/ComponentType.cs @@ -26,136 +26,12 @@ namespace NHibernate.Type public partial class ComponentType : AbstractType, IAbstractComponentType { - public override async Task IsDirtyAsync(object x, object y, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - if (x == y) - { - return false; - } - /* - * NH Different behavior : we don't use the shortcut because NH-1101 - * let the tuplizer choose how cosiderer properties when the component is null. - */ - if (EntityMode != EntityMode.Poco && (x == null || y == null)) - { - return true; - } - object[] xvalues = GetPropertyValues(x); - object[] yvalues = GetPropertyValues(y); - for (int i = 0; i < xvalues.Length; i++) - { - if (await (propertyTypes[i].IsDirtyAsync(xvalues[i], yvalues[i], session, cancellationToken)).ConfigureAwait(false)) - { - return true; - } - } - return false; - } - - public override async Task IsDirtyAsync(object x, object y, bool[] checkable, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - if (x == y) - { - return false; - } - /* - * NH Different behavior : we don't use the shortcut because NH-1101 - * let the tuplizer choose how cosiderer properties when the component is null. - */ - if (EntityMode != EntityMode.Poco && (x == null || y == null)) - { - return true; - } - object[] xvalues = GetPropertyValues(x); - object[] yvalues = GetPropertyValues(y); - int loc = 0; - for (int i = 0; i < xvalues.Length; i++) - { - int len = propertyTypes[i].GetColumnSpan(session.Factory); - if (len <= 1) - { - bool dirty = (len == 0 || checkable[loc]) && - await (propertyTypes[i].IsDirtyAsync(xvalues[i], yvalues[i], session, cancellationToken)).ConfigureAwait(false); - if (dirty) - { - return true; - } - } - else - { - bool[] subcheckable = new bool[len]; - Array.Copy(checkable, loc, subcheckable, 0, len); - bool dirty = await (propertyTypes[i].IsDirtyAsync(xvalues[i], yvalues[i], subcheckable, session, cancellationToken)).ConfigureAwait(false); - if (dirty) - { - return true; - } - } - loc += len; - } - return false; - } - public override async Task NullSafeGetAsync(DbDataReader rs, string[] names, ISessionImplementor session, object owner, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); return await (ResolveIdentifierAsync(await (HydrateAsync(rs, names, session, owner, cancellationToken)).ConfigureAwait(false), session, owner, cancellationToken)).ConfigureAwait(false); } - /// - /// - /// - /// - /// - /// - /// - /// A cancellation token that can be used to cancel the work - public override async Task NullSafeSetAsync(DbCommand st, object value, int begin, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - object[] subvalues = NullSafeGetValues(value); - - for (int i = 0; i < propertySpan; i++) - { - await (propertyTypes[i].NullSafeSetAsync(st, subvalues[i], begin, session, cancellationToken)).ConfigureAwait(false); - begin += propertyTypes[i].GetColumnSpan(session.Factory); - } - } - - public override async Task NullSafeSetAsync(DbCommand st, object value, int begin, bool[] settable, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - object[] subvalues = NullSafeGetValues(value); - - int loc = 0; - for (int i = 0; i < propertySpan; i++) - { - int len = propertyTypes[i].GetColumnSpan(session.Factory); - if (len == 0) - { - //noop - } - else if (len == 1) - { - if (settable[loc]) - { - await (propertyTypes[i].NullSafeSetAsync(st, subvalues[i], begin, session, cancellationToken)).ConfigureAwait(false); - begin++; - } - } - else - { - bool[] subsettable = new bool[len]; - Array.Copy(settable, loc, subsettable, 0, len); - await (propertyTypes[i].NullSafeSetAsync(st, subvalues[i], begin, subsettable, session, cancellationToken)).ConfigureAwait(false); - begin += ArrayHelper.CountTrue(subsettable); - } - loc += len; - } - } - public override Task NullSafeGetAsync(DbDataReader rs, string name, ISessionImplementor session, object owner, CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) @@ -165,38 +41,6 @@ public override Task NullSafeGetAsync(DbDataReader rs, string name, ISes return NullSafeGetAsync(rs, new string[] {name}, session, owner, cancellationToken); } - public Task GetPropertyValueAsync(object component, int i, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(GetPropertyValue(component, i, session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public Task GetPropertyValuesAsync(object component, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(GetPropertyValues(component, session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - public override async Task ReplaceAsync(object original, object target, ISessionImplementor session, object owner, IDictionary copiedAlready, CancellationToken cancellationToken) { @@ -328,29 +172,5 @@ public override Task SemiResolveAsync(object value, ISessionImplementor //for components with many-to-one associations return ResolveIdentifierAsync(value, session, owner, cancellationToken); } - - public override async Task IsModifiedAsync(object old, object current, bool[] checkable, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - if (old == current) - { - return false; - } - object[] currentValues = await (GetPropertyValuesAsync(current, session, cancellationToken)).ConfigureAwait(false); - var oldValues = old is object[] objects ? objects : await (GetPropertyValuesAsync(old, session, cancellationToken)).ConfigureAwait(false); - int loc = 0; - for (int i = 0; i < currentValues.Length; i++) - { - int len = propertyTypes[i].GetColumnSpan(session.Factory); - bool[] subcheckable = new bool[len]; - Array.Copy(checkable, loc, subcheckable, 0, len); - if (await (propertyTypes[i].IsModifiedAsync(oldValues[i], currentValues[i], subcheckable, session, cancellationToken)).ConfigureAwait(false)) - { - return true; - } - loc += len; - } - return false; - } } } diff --git a/src/NHibernate/Async/Type/CompositeCustomType.cs b/src/NHibernate/Async/Type/CompositeCustomType.cs index 0fffef1b131..37796abbf50 100644 --- a/src/NHibernate/Async/Type/CompositeCustomType.cs +++ b/src/NHibernate/Async/Type/CompositeCustomType.cs @@ -26,38 +26,6 @@ namespace NHibernate.Type public partial class CompositeCustomType : AbstractType, IAbstractComponentType { - public virtual Task GetPropertyValuesAsync(object component, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(GetPropertyValues(component, session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public virtual Task GetPropertyValueAsync(object component, int i, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(GetPropertyValue(component, i, session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - public override Task AssembleAsync(object cached, ISessionImplementor session, object owner, CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) @@ -122,49 +90,6 @@ public override Task NullSafeGetAsync(DbDataReader rs, string[] names, I } } - public override Task NullSafeSetAsync(DbCommand st, object value, int index, bool[] settable, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - NullSafeSet(st, value, index, settable, session); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public override Task NullSafeSetAsync(DbCommand cmd, object value, int index, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - NullSafeSet(cmd, value, index, session); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public override Task IsDirtyAsync(object old, object current, bool[] checkable, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - return IsDirtyAsync(old, current, session, cancellationToken); - } - public override Task ReplaceAsync(object original, object current, ISessionImplementor session, object owner, IDictionary copiedAlready, CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) diff --git a/src/NHibernate/Async/Type/CustomType.cs b/src/NHibernate/Async/Type/CustomType.cs index ca1483b29fb..19b16f2b57c 100644 --- a/src/NHibernate/Async/Type/CustomType.cs +++ b/src/NHibernate/Async/Type/CustomType.cs @@ -50,86 +50,6 @@ public override Task NullSafeGetAsync(DbDataReader rs, string name, ISes return NullSafeGetAsync(rs, new[] { name }, session, owner, cancellationToken); } - public override Task NullSafeSetAsync(DbCommand st, object value, int index, bool[] settable, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - NullSafeSet(st, value, index, settable, session); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public override Task NullSafeSetAsync(DbCommand cmd, object value, int index, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - NullSafeSet(cmd, value, index, session); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public override async Task IsDirtyAsync(object old, object current, bool[] checkable, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - return checkable[0] && await (IsDirtyAsync(old, current, session, cancellationToken)).ConfigureAwait(false); - } - - public Task NextAsync(object current, ISessionImplementor session, CancellationToken cancellationToken) - { - if (!(userType is IUserVersionType userVersionType)) - throw new InvalidOperationException( - $"User type {userType} does not implement {nameof(IUserVersionType)}, Either implement it, or " + - $"avoid using this user type as a version type."); - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Next(current, session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public Task SeedAsync(ISessionImplementor session, CancellationToken cancellationToken) - { - if (!(userType is IUserVersionType userVersionType)) - throw new InvalidOperationException( - $"User type {userType} does not implement {nameof(IUserVersionType)}, Either implement it, or " + - $"avoid using this user type as a version type."); - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Seed(session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - public override Task ReplaceAsync(object original, object current, ISessionImplementor session, object owner, IDictionary copiedAlready, CancellationToken cancellationToken) { diff --git a/src/NHibernate/Async/Type/DateTimeNoMsType.cs b/src/NHibernate/Async/Type/DateTimeNoMsType.cs deleted file mode 100644 index 6a8276e1b39..00000000000 --- a/src/NHibernate/Async/Type/DateTimeNoMsType.cs +++ /dev/null @@ -1,42 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using NHibernate.Engine; -using System.Data; - -namespace NHibernate.Type -{ - using System.Threading.Tasks; - using System.Threading; - public partial class DateTimeNoMsType : AbstractDateTimeType - { - - #region IVersionType Members - - public override Task SeedAsync(ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Seed(session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - #endregion - } -} diff --git a/src/NHibernate/Async/Type/DateTimeOffSetType.cs b/src/NHibernate/Async/Type/DateTimeOffSetType.cs deleted file mode 100644 index 2eedce9041f..00000000000 --- a/src/NHibernate/Async/Type/DateTimeOffSetType.cs +++ /dev/null @@ -1,52 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Data; -using System.Data.Common; -using NHibernate.Engine; -using NHibernate.SqlTypes; - -namespace NHibernate.Type -{ - using System.Threading.Tasks; - using System.Threading; - public partial class DateTimeOffsetType : PrimitiveType, IIdentifierType, ILiteralType, IVersionType - { - - public Task NextAsync(object current, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - return SeedAsync(session, cancellationToken); - } - - /// - public virtual Task SeedAsync(ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Seed(session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - } -} diff --git a/src/NHibernate/Async/Type/DbTimestampType.cs b/src/NHibernate/Async/Type/DbTimestampType.cs deleted file mode 100644 index cfa172aeca9..00000000000 --- a/src/NHibernate/Async/Type/DbTimestampType.cs +++ /dev/null @@ -1,103 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Data; -using System.Data.Common; -using NHibernate.Engine; -using NHibernate.Exceptions; -using NHibernate.Impl; -using NHibernate.SqlCommand; -using NHibernate.SqlTypes; - -namespace NHibernate.Type -{ - using System.Threading.Tasks; - using System.Threading; - public partial class DbTimestampType : AbstractDateTimeType - { - - /// - public override async Task SeedAsync(ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - if (session == null) - { - log.Debug("incoming session was null; using current application host time"); - return await (base.SeedAsync(null, cancellationToken)).ConfigureAwait(false); - } - if (!SupportsCurrentTimestampSelection(session.Factory.Dialect)) - { - log.Info("falling back to application host based timestamp, as dialect does not support current timestamp selection"); - return await (base.SeedAsync(session, cancellationToken)).ConfigureAwait(false); - } - return await (GetCurrentTimestampAsync(session, cancellationToken)).ConfigureAwait(false); - } - - /// - /// Retrieves the current timestamp in database. - /// - /// The session to use for retrieving the timestamp. - /// A cancellation token that can be used to cancel the work - /// A datetime. - protected virtual async Task GetCurrentTimestampAsync(ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - var dialect = session.Factory.Dialect; - // Need to round notably for Sql Server DateTime with Odbc, which has a 3.33ms resolution, - // causing stale data update failure 2/3 of times if not rounded to 10ms. - return Round( - await (UsePreparedStatementAsync(GetCurrentTimestampSelectString(dialect), session, cancellationToken)).ConfigureAwait(false), - dialect.TimestampResolutionInTicks); - } - - protected virtual async Task UsePreparedStatementAsync(string timestampSelectString, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - var tsSelect = new SqlString(timestampSelectString); - DbCommand ps = null; - DbDataReader rs = null; - using (session.BeginProcess()) - { - try - { - ps = await (session.Batcher.PrepareCommandAsync(CommandType.Text, tsSelect, EmptyParams, cancellationToken)).ConfigureAwait(false); - rs = await (session.Batcher.ExecuteReaderAsync(ps, cancellationToken)).ConfigureAwait(false); - await (rs.ReadAsync(cancellationToken)).ConfigureAwait(false); - var ts = rs.GetDateTime(0); - log.Debug("current timestamp retrieved from db : {0} (ticks={1})", ts, ts.Ticks); - return AdjustDateTime(ts); - } - catch (DbException sqle) - { - throw ADOExceptionHelper.Convert( - session.Factory.SQLExceptionConverter, - sqle, - "could not select current db timestamp", - tsSelect); - } - finally - { - if (ps != null) - { - try - { - session.Batcher.CloseCommand(ps, rs); - } - catch (DbException sqle) - { - log.Warn(sqle, "unable to clean up prepared statement"); - } - } - } - } - } - } -} diff --git a/src/NHibernate/Async/Type/EntityType.cs b/src/NHibernate/Async/Type/EntityType.cs index 95fa8eaa2bb..abdbdb14491 100644 --- a/src/NHibernate/Async/Type/EntityType.cs +++ b/src/NHibernate/Async/Type/EntityType.cs @@ -35,51 +35,6 @@ public override Task NullSafeGetAsync(DbDataReader rs, string name, ISes return NullSafeGetAsync(rs, new string[] {name}, session, owner, cancellationToken); } - protected internal Task GetIdentifierAsync(object value, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return ForeignKeys.GetEntityIdentifierIfNotUnsavedAsync(GetAssociatedEntityName(), value, session, cancellationToken); //tolerates nulls - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - protected internal async Task GetReferenceValueAsync(object value, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - if (value == null) - { - return null; - } - else if (IsReferenceToPrimaryKey) - { - return await (ForeignKeys.GetEntityIdentifierIfNotUnsavedAsync(GetAssociatedEntityName(), value, session, cancellationToken)).ConfigureAwait(false); //tolerates nulls - } - else - { - IEntityPersister entityPersister = session.Factory.GetEntityPersister(GetAssociatedEntityName()); - object propertyValue = entityPersister.GetPropertyValue(value, uniqueKeyPropertyName); - - // We now have the value of the property-ref we reference. However, - // we need to dig a little deeper, as that property might also be - // an entity type, in which case we need to resolve its identitifier - IType type = entityPersister.GetPropertyType(uniqueKeyPropertyName); - if (type.IsEntityType) - { - propertyValue = await (((EntityType) type).GetReferenceValueAsync(propertyValue, session, cancellationToken)).ConfigureAwait(false); - } - - return propertyValue; - } - } - public override async Task ReplaceAsync(object original, object target, ISessionImplementor session, object owner, IDictionary copyCache, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); @@ -98,7 +53,7 @@ public override async Task ReplaceAsync(object original, object target, { return target; } - if (session.GetContextEntityIdentifier(original) == null && (await (ForeignKeys.IsTransientFastAsync(associatedEntityName, original, session, cancellationToken)).ConfigureAwait(false)).GetValueOrDefault()) + if (session.GetContextEntityIdentifier(original) == null && ForeignKeys.IsTransientFast(associatedEntityName, original, session).GetValueOrDefault()) { object copy = session.Factory.GetEntityPersister(associatedEntityName).Instantiate(null); //TODO: should this be Session.instantiate(Persister, ...)? @@ -107,7 +62,7 @@ public override async Task ReplaceAsync(object original, object target, } else { - object id = await (GetReferenceValueAsync(original, session, cancellationToken)).ConfigureAwait(false); + object id = GetReferenceValue(original, session); if (id == null) { throw new AssertionFailure("non-transient entity has a null id"); diff --git a/src/NHibernate/Async/Type/IAbstractComponentType.cs b/src/NHibernate/Async/Type/IAbstractComponentType.cs deleted file mode 100644 index fe6de170698..00000000000 --- a/src/NHibernate/Async/Type/IAbstractComponentType.cs +++ /dev/null @@ -1,29 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System.Reflection; -using NHibernate.Engine; - -namespace NHibernate.Type -{ - using System.Threading.Tasks; - using System.Threading; - public partial interface IAbstractComponentType : IType - { - - /// - /// Get the values of the component properties of - /// a component instance - /// - Task GetPropertyValuesAsync(object component, ISessionImplementor session, CancellationToken cancellationToken); - - Task GetPropertyValueAsync(object component, int i, ISessionImplementor session, CancellationToken cancellationToken); - } -} diff --git a/src/NHibernate/Async/Type/IType.cs b/src/NHibernate/Async/Type/IType.cs index 4b439734786..a0ef4ff139b 100644 --- a/src/NHibernate/Async/Type/IType.cs +++ b/src/NHibernate/Async/Type/IType.cs @@ -21,31 +21,6 @@ namespace NHibernate.Type public partial interface IType : ICacheAssembler { - /// - /// When implemented by a class, should the parent be considered dirty, - /// given both the old and current field or element value? - /// - /// The old value - /// The current value - /// The - /// A cancellation token that can be used to cancel the work - /// true if the field is dirty - Task IsDirtyAsync(object old, object current, ISessionImplementor session, CancellationToken cancellationToken); - - /// - /// When implemented by a class, should the parent be considered dirty, - /// given both the old and current field or element value? - /// - /// The old value - /// The current value - /// Indicates which columns are to be checked. - /// The - /// A cancellation token that can be used to cancel the work - /// true if the field is dirty - Task IsDirtyAsync(object old, object current, bool[] checkable, ISessionImplementor session, CancellationToken cancellationToken); - - Task IsModifiedAsync(object oldHydratedState, object currentState, bool[] checkable, ISessionImplementor session, CancellationToken cancellationToken); - /// /// When implemented by a class, gets an instance of the object mapped by /// this IType from the . @@ -81,41 +56,6 @@ public partial interface IType : ICacheAssembler /// Task NullSafeGetAsync(DbDataReader rs, string name, ISessionImplementor session, object owner, CancellationToken cancellationToken); - /// - /// When implemented by a class, puts the value/values from the mapped - /// class into the . - /// - /// The to put the values into. - /// The object that contains the values. - /// The index of the to start writing the values to. - /// Indicates which columns are to be set. - /// - /// A cancellation token that can be used to cancel the work - /// - /// Implementors should handle possibility of null values. - /// A multi-column type should be written to parameters starting from . - /// - Task NullSafeSetAsync(DbCommand st, object value, int index, bool[] settable, ISessionImplementor session, CancellationToken cancellationToken); - - /// - /// When implemented by a class, puts the value/values from the mapped - /// class into the . - /// - /// - /// The to put the values into. - /// - /// The object that contains the values. - /// - /// The index of the to start writing the values to. - /// - /// - /// A cancellation token that can be used to cancel the work - /// - /// Implementors should handle possibility of null values. - /// A multi-column type should be written to parameters starting from . - /// - Task NullSafeSetAsync(DbCommand st, object value, int index, ISessionImplementor session, CancellationToken cancellationToken); - /// /// When implemented by a class, retrieves an instance of the mapped class, /// or the identifier of an entity or collection from a . diff --git a/src/NHibernate/Async/Type/IVersionType.cs b/src/NHibernate/Async/Type/IVersionType.cs deleted file mode 100644 index f4a17f28986..00000000000 --- a/src/NHibernate/Async/Type/IVersionType.cs +++ /dev/null @@ -1,37 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System.Collections; -using NHibernate.Engine; - -namespace NHibernate.Type -{ - using System.Threading.Tasks; - using System.Threading; - public partial interface IVersionType : IType - { - /// - /// When implemented by a class, increments the version. - /// - /// The current version - /// The current session, if available. - /// A cancellation token that can be used to cancel the work - /// an instance of the that has been incremented. - Task NextAsync(object current, ISessionImplementor session, CancellationToken cancellationToken); - - /// - /// When implemented by a class, gets an initial version. - /// - /// The current session, if available. - /// A cancellation token that can be used to cancel the work - /// An instance of the type. - Task SeedAsync(ISessionImplementor session, CancellationToken cancellationToken); - } -} diff --git a/src/NHibernate/Async/Type/Int16Type.cs b/src/NHibernate/Async/Type/Int16Type.cs deleted file mode 100644 index 95cec493791..00000000000 --- a/src/NHibernate/Async/Type/Int16Type.cs +++ /dev/null @@ -1,62 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Collections; -using System.Data.Common; -using NHibernate.Engine; -using NHibernate.SqlTypes; -using System.Collections.Generic; -using System.Data; - -namespace NHibernate.Type -{ - using System.Threading.Tasks; - using System.Threading; - public partial class Int16Type : PrimitiveType, IDiscriminatorType, IVersionType - { - - #region IVersionType Members - - public virtual Task NextAsync(object current, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Next(current, session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public virtual Task SeedAsync(ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Seed(session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - #endregion - } -} diff --git a/src/NHibernate/Async/Type/Int32Type.cs b/src/NHibernate/Async/Type/Int32Type.cs deleted file mode 100644 index e7897e1eafc..00000000000 --- a/src/NHibernate/Async/Type/Int32Type.cs +++ /dev/null @@ -1,62 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Collections; -using System.Data.Common; -using NHibernate.Engine; -using NHibernate.SqlTypes; -using System.Collections.Generic; -using System.Data; - -namespace NHibernate.Type -{ - using System.Threading.Tasks; - using System.Threading; - public partial class Int32Type : PrimitiveType, IDiscriminatorType, IVersionType - { - - #region IVersionType Members - - public virtual Task NextAsync(object current, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Next(current, session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public virtual Task SeedAsync(ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Seed(session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - #endregion - } -} diff --git a/src/NHibernate/Async/Type/Int64Type.cs b/src/NHibernate/Async/Type/Int64Type.cs deleted file mode 100644 index a4dae360662..00000000000 --- a/src/NHibernate/Async/Type/Int64Type.cs +++ /dev/null @@ -1,62 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Data; -using System.Data.Common; -using NHibernate.Engine; -using NHibernate.SqlTypes; - -namespace NHibernate.Type -{ - using System.Threading.Tasks; - using System.Threading; - public partial class Int64Type : PrimitiveType, IDiscriminatorType, IVersionType - { - - #region IVersionType Members - - public virtual Task NextAsync(object current, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Next(current, session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public virtual Task SeedAsync(ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Seed(session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - #endregion - } -} diff --git a/src/NHibernate/Async/Type/ManyToOneType.cs b/src/NHibernate/Async/Type/ManyToOneType.cs index e288555bddb..9d36be67809 100644 --- a/src/NHibernate/Async/Type/ManyToOneType.cs +++ b/src/NHibernate/Async/Type/ManyToOneType.cs @@ -22,20 +22,6 @@ namespace NHibernate.Type public partial class ManyToOneType : EntityType { - public override async Task NullSafeSetAsync(DbCommand st, object value, int index, bool[] settable, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - await (GetIdentifierOrUniqueKeyType(session.Factory) - .NullSafeSetAsync(st, await (GetReferenceValueAsync(value, session, cancellationToken)).ConfigureAwait(false), index, settable, session, cancellationToken)).ConfigureAwait(false); - } - - public override async Task NullSafeSetAsync(DbCommand cmd, object value, int index, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - await (GetIdentifierOrUniqueKeyType(session.Factory) - .NullSafeSetAsync(cmd, await (GetReferenceValueAsync(value, session, cancellationToken)).ConfigureAwait(false), index, session, cancellationToken)).ConfigureAwait(false); - } - /// /// Hydrates the Identifier from . /// @@ -59,40 +45,33 @@ public override async Task HydrateAsync(DbDataReader rs, string[] names, return id; } - public override async Task IsModifiedAsync(object old, object current, bool[] checkable, ISessionImplementor session, CancellationToken cancellationToken) + public override Task DisassembleAsync(object value, ISessionImplementor session, object owner, CancellationToken cancellationToken) { - cancellationToken.ThrowIfCancellationRequested(); - if (current == null) - { - return old != null; - } - if (old == null) - { - return true; - } - var oldIdentifier = IsIdentifier(old, session) ? old : await (GetIdentifierAsync(old, session, cancellationToken)).ConfigureAwait(false); - var currentIdentifier = await (GetIdentifierAsync(current, session, cancellationToken)).ConfigureAwait(false); - // the ids are fully resolved, so compare them with isDirty(), not isModified() - return await (GetIdentifierOrUniqueKeyType(session.Factory).IsDirtyAsync(oldIdentifier, currentIdentifier, session, cancellationToken)).ConfigureAwait(false); - } - - public override async Task DisassembleAsync(object value, ISessionImplementor session, object owner, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - if (value == null) + if (cancellationToken.IsCancellationRequested) { - return null; + return Task.FromCanceled(cancellationToken); } - else + try { - // cache the actual id of the object, not the value of the - // property-ref, which might not be initialized - object id = await (ForeignKeys.GetEntityIdentifierIfNotUnsavedAsync(GetAssociatedEntityName(), value, session, cancellationToken)).ConfigureAwait(false); - if (id == null) + if (value == null) + { + return Task.FromResult(null); + } + else { - throw new AssertionFailure("cannot cache a reference to an object with a null id: " + GetAssociatedEntityName()); + // cache the actual id of the object, not the value of the + // property-ref, which might not be initialized + object id = ForeignKeys.GetEntityIdentifierIfNotUnsaved(GetAssociatedEntityName(), value, session); + if (id == null) + { + return Task.FromException(new AssertionFailure("cannot cache a reference to an object with a null id: " + GetAssociatedEntityName())); + } + return GetIdentifierType(session).DisassembleAsync(id, session, owner, cancellationToken); } - return await (GetIdentifierType(session).DisassembleAsync(id, session, owner, cancellationToken)).ConfigureAwait(false); + } + catch (Exception ex) + { + return Task.FromException(ex); } } @@ -136,50 +115,5 @@ private Task AssembleIdAsync(object oid, ISessionImplementor session, Ca return Task.FromException(ex); } } - - public override Task IsDirtyAsync(object old, object current, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - return IsDirtyManyToOneAsync(old, current, null, session, cancellationToken); - } - - public override Task IsDirtyAsync(object old, object current, bool[] checkable, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - return IsDirtyManyToOneAsync(old, current, IsAlwaysDirtyChecked ? null : checkable, session, cancellationToken); - } - - private async Task IsDirtyManyToOneAsync(object old, object current, bool[] checkable, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - if (IsSame(old, current)) - { - return false; - } - - if (old == null || current == null) - { - return true; - } - - if ((await (ForeignKeys.IsTransientFastAsync(GetAssociatedEntityName(), current, session, cancellationToken)).ConfigureAwait(false)).GetValueOrDefault()) - { - return true; - } - - object oldid = await (GetIdentifierAsync(old, session, cancellationToken)).ConfigureAwait(false); - object newid = await (GetIdentifierAsync(current, session, cancellationToken)).ConfigureAwait(false); - IType identifierType = GetIdentifierType(session); - - return checkable == null - ? await (identifierType.IsDirtyAsync(oldid, newid, session, cancellationToken)).ConfigureAwait(false) - : await (identifierType.IsDirtyAsync(oldid, newid, checkable, session, cancellationToken)).ConfigureAwait(false); - } } } diff --git a/src/NHibernate/Async/Type/MetaType.cs b/src/NHibernate/Async/Type/MetaType.cs index f112e5fc648..bc06f8cdebe 100644 --- a/src/NHibernate/Async/Type/MetaType.cs +++ b/src/NHibernate/Async/Type/MetaType.cs @@ -33,50 +33,6 @@ public override async Task NullSafeGetAsync(DbDataReader rs, string name return GetValueForKey(await (_baseType.NullSafeGetAsync(rs, name, session, owner, cancellationToken)).ConfigureAwait(false)); } - public override Task NullSafeSetAsync(DbCommand st, object value, int index, bool[] settable, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - if (settable[0]) return NullSafeSetAsync(st, value, index, session, cancellationToken); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public override Task NullSafeSetAsync(DbCommand st, object value, int index, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - // "_keys?[(string) value]" is valid code provided "_keys[(string) value]" can never yield null. It is the - // case because we use a dictionary interface which throws in case of missing key, and because it is not - // possible to have a value associated to a null key since generic dictionaries do not support null keys. - var key = value == null ? null : _keys?[(string) value] ?? value; - - return _baseType.NullSafeSetAsync(st, key, index, session, cancellationToken); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public override async Task IsDirtyAsync(object old, object current, bool[] checkable, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - return checkable[0] && await (IsDirtyAsync(old, current, session, cancellationToken)).ConfigureAwait(false); - } - public override Task ReplaceAsync(object original, object current, ISessionImplementor session, object owner, System.Collections.IDictionary copiedAlready, CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) diff --git a/src/NHibernate/Async/Type/NullableType.cs b/src/NHibernate/Async/Type/NullableType.cs index 02eb315a461..81b3ebdc192 100644 --- a/src/NHibernate/Async/Type/NullableType.cs +++ b/src/NHibernate/Async/Type/NullableType.cs @@ -21,55 +21,6 @@ namespace NHibernate.Type public abstract partial class NullableType : AbstractType { - public override Task NullSafeSetAsync(DbCommand st, object value, int index, bool[] settable, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - if (settable[0]) return NullSafeSetAsync(st, value, index, session, cancellationToken); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - /// - /// - /// - /// This method has been "sealed" because the Types inheriting from - /// do not need to and should not override this method. - /// - /// - /// This method checks to see if value is null, if it is then the value of - /// is written to the . - /// - /// - /// If the value is not null, then the method - /// is called and that method is responsible for setting the value. - /// - /// - public sealed override Task NullSafeSetAsync(DbCommand st, object value, int index, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - NullSafeSet(st, value, index, session); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - /// /// /// This has been sealed because no other class should override it. This @@ -119,11 +70,5 @@ public sealed override Task NullSafeGetAsync(DbDataReader rs, string nam return Task.FromException(ex); } } - - public override async Task IsDirtyAsync(object old, object current, bool[] checkable, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - return checkable[0] && await (IsDirtyAsync(old, current, session, cancellationToken)).ConfigureAwait(false); - } } } diff --git a/src/NHibernate/Async/Type/OneToOneType.cs b/src/NHibernate/Async/Type/OneToOneType.cs index d53f9c968d2..d4e534ef62f 100644 --- a/src/NHibernate/Async/Type/OneToOneType.cs +++ b/src/NHibernate/Async/Type/OneToOneType.cs @@ -22,78 +22,6 @@ namespace NHibernate.Type public partial class OneToOneType : EntityType, IAssociationType { - public override Task NullSafeSetAsync(DbCommand st, object value, int index, bool[] settable, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - NullSafeSet(st, value, index, settable, session); - return Task.CompletedTask; - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public override async Task NullSafeSetAsync(DbCommand cmd, object value, int index, ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - await (GetIdentifierOrUniqueKeyType(session.Factory) - .NullSafeSetAsync(cmd, await (GetReferenceValueAsync(value, session, cancellationToken)).ConfigureAwait(false), index, session, cancellationToken)).ConfigureAwait(false); - } - - public override Task IsDirtyAsync(object old, object current, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(IsDirty(old, current, session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public override Task IsDirtyAsync(object old, object current, bool[] checkable, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(IsDirty(old, current, checkable, session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public override Task IsModifiedAsync(object old, object current, bool[] checkable, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(IsModified(old, current, checkable, session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - public override async Task HydrateAsync(DbDataReader rs, string[] names, ISessionImplementor session, object owner, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); @@ -113,7 +41,7 @@ public override async Task HydrateAsync(DbDataReader rs, string[] names, EmbeddedComponentType ownerIdType = session.GetEntityPersister(null, owner).IdentifierType as EmbeddedComponentType; if (ownerIdType != null) { - object[] values = await (ownerIdType.GetPropertyValuesAsync(identifier, session, cancellationToken)).ConfigureAwait(false); + object[] values = ownerIdType.GetPropertyValues(identifier, session); object id = await (componentType.ResolveIdentifierAsync(values, session, null, cancellationToken)).ConfigureAwait(false); IEntityPersister persister = session.Factory.GetEntityPersister(type.ReturnedClass.FullName); var key = session.GenerateEntityKey(id, persister); diff --git a/src/NHibernate/Async/Type/TicksType.cs b/src/NHibernate/Async/Type/TicksType.cs deleted file mode 100644 index 0ffb06b37f6..00000000000 --- a/src/NHibernate/Async/Type/TicksType.cs +++ /dev/null @@ -1,44 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Data; -using System.Data.Common; -using NHibernate.Engine; -using NHibernate.SqlTypes; - -namespace NHibernate.Type -{ - using System.Threading.Tasks; - using System.Threading; - public partial class TicksType : AbstractDateTimeType - { - - #region IVersionType Members - - public override Task SeedAsync(ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Seed(session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - #endregion - } -} diff --git a/src/NHibernate/Async/Type/TimeAsTimeSpanType.cs b/src/NHibernate/Async/Type/TimeAsTimeSpanType.cs deleted file mode 100644 index 185baa88eba..00000000000 --- a/src/NHibernate/Async/Type/TimeAsTimeSpanType.cs +++ /dev/null @@ -1,55 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Collections; -using System.Data.Common; -using NHibernate.Engine; -using NHibernate.SqlTypes; -using System.Collections.Generic; -using System.Data; - -namespace NHibernate.Type -{ - using System.Threading.Tasks; - using System.Threading; - public partial class TimeAsTimeSpanType : PrimitiveType, IVersionType - { - - #region IVersionType Members - - public Task NextAsync(object current, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - return SeedAsync(session, cancellationToken); - } - - public virtual Task SeedAsync(ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Seed(session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - #endregion - } -} diff --git a/src/NHibernate/Async/Type/TimeSpanType.cs b/src/NHibernate/Async/Type/TimeSpanType.cs deleted file mode 100644 index 0917413671c..00000000000 --- a/src/NHibernate/Async/Type/TimeSpanType.cs +++ /dev/null @@ -1,56 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Collections; -using System.Data.Common; -using NHibernate.Engine; -using NHibernate.SqlTypes; -using System.Collections.Generic; -using System.Data; - -namespace NHibernate.Type -{ - using System.Threading.Tasks; - using System.Threading; - public partial class TimeSpanType : PrimitiveType, IVersionType, ILiteralType - { - - #region IVersionType Members - - public Task NextAsync(object current, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - return SeedAsync(session, cancellationToken); - } - - /// - public virtual Task SeedAsync(ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Seed(session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - #endregion - } -} diff --git a/src/NHibernate/Async/Type/TypeHelper.cs b/src/NHibernate/Async/Type/TypeHelper.cs index 3446d115249..27776656f93 100644 --- a/src/NHibernate/Async/Type/TypeHelper.cs +++ b/src/NHibernate/Async/Type/TypeHelper.cs @@ -299,8 +299,8 @@ public static async Task ReplaceAssociationsAsync(object[] original, o // need to extract the component values and check for subtype replacements... IAbstractComponentType componentType = (IAbstractComponentType)types[i]; IType[] subtypes = componentType.Subtypes; - object[] origComponentValues = original[i] == null ? new object[subtypes.Length] : await (componentType.GetPropertyValuesAsync(original[i], session, cancellationToken)).ConfigureAwait(false); - object[] targetComponentValues = target[i] == null ? new object[subtypes.Length] : await (componentType.GetPropertyValuesAsync(target[i], session, cancellationToken)).ConfigureAwait(false); + object[] origComponentValues = original[i] == null ? new object[subtypes.Length] : componentType.GetPropertyValues(original[i], session); + object[] targetComponentValues = target[i] == null ? new object[subtypes.Length] : componentType.GetPropertyValues(target[i], session); object[] componentCopy = await (ReplaceAssociationsAsync(origComponentValues, targetComponentValues, subtypes, session, null, copyCache, foreignKeyDirection, cancellationToken)).ConfigureAwait(false); @@ -320,172 +320,5 @@ public static async Task ReplaceAssociationsAsync(object[] original, o } return copied; } - - /// - /// Determine if any of the given field values are dirty, returning an array containing - /// indices of the dirty fields. - /// If it is determined that no fields are dirty, null is returned. - /// - /// The property definitions - /// The current state of the entity - /// The baseline state of the entity - /// Columns to be included in the dirty checking, per property - /// Does the entity currently hold any uninitialized property values? - /// The session from which the dirty check request originated. - /// A cancellation token that can be used to cancel the work - /// Array containing indices of the dirty properties, or null if no properties considered dirty. - // Since 5.3 - [Obsolete("Use overload without anyUninitializedProperties parameter instead")] - public static Task FindDirtyAsync(StandardProperty[] properties, - object[] currentState, - object[] previousState, - bool[][] includeColumns, - bool anyUninitializedProperties, - ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - return FindDirtyAsync(properties, currentState, previousState, includeColumns, session, cancellationToken); - } - - /// - /// Determine if any of the given field values are dirty, returning an array containing - /// indices of the dirty fields. - /// If it is determined that no fields are dirty, null is returned. - /// - /// The property definitions - /// The current state of the entity - /// The baseline state of the entity - /// Columns to be included in the dirty checking, per property - /// The session from which the dirty check request originated. - /// A cancellation token that can be used to cancel the work - /// Array containing indices of the dirty properties, or null if no properties considered dirty. - public static async Task FindDirtyAsync(StandardProperty[] properties, - object[] currentState, - object[] previousState, - bool[][] includeColumns, - ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - int[] results = null; - int count = 0; - int span = properties.Length; - - for (int i = 0; i < span; i++) - { - var dirty = await (DirtyAsync(properties, currentState, previousState, includeColumns, session, i, cancellationToken)).ConfigureAwait(false); - if (dirty) - { - if (results == null) - { - results = new int[span]; - } - results[count++] = i; - } - } - if (count == 0) - { - return null; - } - else - { - int[] trimmed = new int[count]; - Array.Copy(results, 0, trimmed, 0, count); - return trimmed; - } - } - - private static async Task DirtyAsync(StandardProperty[] properties, object[] currentState, object[] previousState, bool[][] includeColumns, ISessionImplementor session, int i, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - if (Equals(LazyPropertyInitializer.UnfetchedProperty, currentState[i])) - return false; - if (Equals(LazyPropertyInitializer.UnfetchedProperty, previousState[i])) - return true; - return properties[i].IsDirtyCheckable() && - await (properties[i].Type.IsDirtyAsync(previousState[i], currentState[i], includeColumns[i], session, cancellationToken)).ConfigureAwait(false); - } - - /// - /// Determine if any of the given field values are modified, returning an array containing - /// indices of the modified fields. - /// If it is determined that no fields are dirty, null is returned. - /// - /// The property definitions - /// The current state of the entity - /// The baseline state of the entity - /// Columns to be included in the mod checking, per property - /// Does the entity currently hold any uninitialized property values? - /// The session from which the dirty check request originated. - /// A cancellation token that can be used to cancel the work - /// Array containing indices of the modified properties, or null if no properties considered modified. - // Since 5.3 - [Obsolete("Use the overload without anyUninitializedProperties parameter.")] - public static Task FindModifiedAsync(StandardProperty[] properties, - object[] currentState, - object[] previousState, - bool[][] includeColumns, - bool anyUninitializedProperties, - ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - return FindModifiedAsync(properties, currentState, previousState, includeColumns, session, cancellationToken); - } - - /// - /// Determine if any of the given field values are modified, returning an array containing - /// indices of the modified fields. - /// If it is determined that no fields are dirty, null is returned. - /// - /// The property definitions - /// The current state of the entity - /// The baseline state of the entity - /// Columns to be included in the mod checking, per property - /// The session from which the dirty check request originated. - /// A cancellation token that can be used to cancel the work - /// Array containing indices of the modified properties, or null if no properties considered modified. - public static async Task FindModifiedAsync(StandardProperty[] properties, - object[] currentState, - object[] previousState, - bool[][] includeColumns, - ISessionImplementor session, CancellationToken cancellationToken) - { - cancellationToken.ThrowIfCancellationRequested(); - int[] results = null; - int count = 0; - int span = properties.Length; - - for (int i = 0; i < span; i++) - { - bool dirty = - !Equals(LazyPropertyInitializer.UnfetchedProperty, currentState[i]) && - properties[i].IsDirtyCheckable() - && await (properties[i].Type.IsModifiedAsync(previousState[i], currentState[i], includeColumns[i], session, cancellationToken)).ConfigureAwait(false); - - if (dirty) - { - if (results == null) - { - results = new int[span]; - } - results[count++] = i; - } - } - if (count == 0) - { - return null; - } - else - { - int[] trimmed = new int[count]; - Array.Copy(results, 0, trimmed, 0, count); - return trimmed; - } - } } } diff --git a/src/NHibernate/Async/Type/UInt16Type.cs b/src/NHibernate/Async/Type/UInt16Type.cs deleted file mode 100644 index b30c8ee87a4..00000000000 --- a/src/NHibernate/Async/Type/UInt16Type.cs +++ /dev/null @@ -1,62 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Data; -using System.Data.Common; -using NHibernate.Engine; -using NHibernate.SqlTypes; - -namespace NHibernate.Type -{ - using System.Threading.Tasks; - using System.Threading; - public partial class UInt16Type : PrimitiveType, IDiscriminatorType, IVersionType - { - - #region IVersionType Members - - public virtual Task NextAsync(object current, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Next(current, session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public virtual Task SeedAsync(ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Seed(session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - #endregion - } -} diff --git a/src/NHibernate/Async/Type/UInt32Type.cs b/src/NHibernate/Async/Type/UInt32Type.cs deleted file mode 100644 index b5aa62179c0..00000000000 --- a/src/NHibernate/Async/Type/UInt32Type.cs +++ /dev/null @@ -1,62 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Data; -using System.Data.Common; -using NHibernate.Engine; -using NHibernate.SqlTypes; - -namespace NHibernate.Type -{ - using System.Threading.Tasks; - using System.Threading; - public partial class UInt32Type : PrimitiveType, IDiscriminatorType, IVersionType - { - - #region IVersionType Members - - public virtual Task NextAsync(object current, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Next(current, session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public virtual Task SeedAsync(ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Seed(session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - #endregion - } -} diff --git a/src/NHibernate/Async/Type/UInt64Type.cs b/src/NHibernate/Async/Type/UInt64Type.cs deleted file mode 100644 index 08e7c68a1e6..00000000000 --- a/src/NHibernate/Async/Type/UInt64Type.cs +++ /dev/null @@ -1,62 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by AsyncGenerator. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Data; -using System.Data.Common; -using NHibernate.Engine; -using NHibernate.SqlTypes; - -namespace NHibernate.Type -{ - using System.Threading.Tasks; - using System.Threading; - public partial class UInt64Type : PrimitiveType, IDiscriminatorType, IVersionType - { - - #region IVersionType Members - - public virtual Task NextAsync(object current, ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Next(current, session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - public virtual Task SeedAsync(ISessionImplementor session, CancellationToken cancellationToken) - { - if (cancellationToken.IsCancellationRequested) - { - return Task.FromCanceled(cancellationToken); - } - try - { - return Task.FromResult(Seed(session)); - } - catch (Exception ex) - { - return Task.FromException(ex); - } - } - - #endregion - } -} diff --git a/src/NHibernate/Engine/ForeignKeys.cs b/src/NHibernate/Engine/ForeignKeys.cs index fe8dbb9cdea..3df1e806aff 100644 --- a/src/NHibernate/Engine/ForeignKeys.cs +++ b/src/NHibernate/Engine/ForeignKeys.cs @@ -184,17 +184,21 @@ public static bool IsNotTransientSlow(string entityName, object entity, ISession return interceptorResult; // let the persister inspect the instance to decide - if (proxy != null) - { - // The persister only deals with unproxied entities. - entity = proxy.HibernateLazyInitializer.GetImplementation(); - } - + // The persister only deals with unproxied entities. + entity = UnproxyForInitialized(proxy) ?? entity; return session .GetEntityPersister( entityName, entity) - .IsTransient(entity, session); + .IsTransient(entity); + } + + private static object UnproxyForInitialized(INHibernateProxy proxy) + { + return + proxy?.HibernateLazyInitializer.IsUninitialized == false + ? proxy.HibernateLazyInitializer.GetImplementation() + : null; } /// @@ -205,25 +209,37 @@ public static bool IsNotTransientSlow(string entityName, object entity, ISession /// public static bool IsTransientSlow(string entityName, object entity, ISessionImplementor session) { - return IsTransientFast(entityName, entity, session) ?? - HasDbSnapshot(entityName, entity, session); + bool? isTransient = IsTransientFast(entityName, entity, session); + if (isTransient.HasValue) + return isTransient.Value; + + var persister = session.GetEntityPersister(entityName, entity); + var id = persister.GetIdentifier(entity); + + // check to see if it is in the second-level cache + if (persister.HasCache && session.CacheMode.HasFlag(CacheMode.Get)) + { + var ck = session.GenerateCacheKey(id, persister.IdentifierType, persister.RootEntityName); + if (persister.Cache.Get(ck, session.Timestamp) != null) + return false; + } + + return HasDbSnapshot(persister, id, session); } - static bool HasDbSnapshot(string entityName, object entity, ISessionImplementor session) + static bool HasDbSnapshot(IEntityPersister persister, object identifier, ISessionImplementor session) { - IEntityPersister persister = session.GetEntityPersister(entityName, entity); if (persister.IdentifierGenerator is Assigned) { // When using assigned identifiers we cannot tell if an entity // is transient or detached without querying the database. // This could potentially cause Select N+1 in cascaded saves, so warn the user. log.Warn("Unable to determine if {0} with assigned identifier {1} is transient or detached; querying the database. Use explicit Save() or Update() in session to prevent this.", - entity, persister.GetIdentifier(entity)); + persister.EntityName, identifier); } // hit the database, after checking the session cache for a snapshot - System.Object[] snapshot = - session.PersistenceContext.GetDatabaseSnapshot(persister.GetIdentifier(entity), persister); + System.Object[] snapshot = session.PersistenceContext.GetDatabaseSnapshot(identifier, persister); return snapshot == null; } diff --git a/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs b/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs index 924da726cc1..ac4a8d937f8 100644 --- a/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs +++ b/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs @@ -4201,7 +4201,7 @@ public virtual void AfterReassociate(object entity, ISessionImplementor session) } } - public virtual bool? IsTransient(object entity, ISessionImplementor session) + public virtual bool? IsTransient(object entity) { object id; if (CanExtractIdOutOfEntity) @@ -4238,14 +4238,7 @@ public virtual void AfterReassociate(object entity, ISessionImplementor session) } } - // check to see if it is in the second-level cache - if (HasCache && session.CacheMode.HasFlag(CacheMode.Get)) - { - CacheKey ck = session.GenerateCacheKey(id, IdentifierType, RootEntityName); - if (Cache.Get(ck, session.Timestamp) != null) - return false; - } - + //Note: second level cache check is moved to ForeignKeys.IsTransientSlow as a potentially slow operation return null; } diff --git a/src/NHibernate/Persister/Entity/IEntityPersister.cs b/src/NHibernate/Persister/Entity/IEntityPersister.cs index 495e6147ddd..8c89336a2dc 100644 --- a/src/NHibernate/Persister/Entity/IEntityPersister.cs +++ b/src/NHibernate/Persister/Entity/IEntityPersister.cs @@ -458,7 +458,7 @@ void Update( object CreateProxy(object id, ISessionImplementor session); /// Is this a new transient instance? - bool? IsTransient(object obj, ISessionImplementor session); + bool? IsTransient(object obj); /// Return the values of the insertable properties of the object (including backrefs) object[] GetPropertyValuesToInsert(object obj, IDictionary mergeMap, ISessionImplementor session);