Skip to content

WIP Make IEntityPersister.IsTransient not async #2055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/AsyncGenerator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 0 additions & 50 deletions src/NHibernate.DomainModel/Async/CustomPersister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,44 +34,6 @@ public partial class CustomPersister : IEntityPersister

#region IOptimisticCacheSource Members

public Task<int[]> FindDirtyAsync(object[] currentState, object[] previousState, object entity, ISessionImplementor session, CancellationToken cancellationToken)
{
try
{
if (!Equals(currentState[0], previousState[0]))
{
return Task.FromResult<int[]>(new int[] { 0 });
}
else
{
return Task.FromResult<int[]>(null);
}
}
catch (Exception ex)
{
return Task.FromException<int[]>(ex);
}
}

public Task<int[]> FindModifiedAsync(object[] old, object[] current, object entity, ISessionImplementor session, CancellationToken cancellationToken)
{
try
{
if (!Equals(old[0], current[0]))
{
return Task.FromResult<int[]>(new int[] { 0 });
}
else
{
return Task.FromResult<int[]>(null);
}
}
catch (Exception ex)
{
return Task.FromException<int[]>(ex);
}
}

public Task<object[]> GetNaturalIdentifierSnapshotAsync(object id, ISessionImplementor session, CancellationToken cancellationToken)
{
return Task.FromResult<object[]>(null);
Expand Down Expand Up @@ -165,18 +127,6 @@ public Task<object> ForceVersionIncrementAsync(object id, object currentVersion,
return Task.FromResult<object>(null);
}

public Task<bool?> IsTransientAsync(object obj, ISessionImplementor session, CancellationToken cancellationToken)
{
try
{
return Task.FromResult<bool?>(((Custom) obj).Id == null);
}
catch (Exception ex)
{
return Task.FromException<bool?>(ex);
}
}

public Task ProcessInsertGeneratedPropertiesAsync(object id, object entity, object[] state, ISessionImplementor session, CancellationToken cancellationToken)
{
return Task.CompletedTask;
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate.DomainModel/CustomPersister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
namespace NHibernate.Test.NHSpecificTest.Dates
{
using System.Threading.Tasks;
using System.Threading;
[TestFixture]
public class DateTimeOffsetFixtureAsync : FixtureBaseAsync
{
Expand Down Expand Up @@ -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<DateTimeOffset>().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<DateTimeOffset>());
}
}
}
7 changes: 3 additions & 4 deletions src/NHibernate.Test/Async/NHSpecificTest/GH1486/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
namespace NHibernate.Test.NHSpecificTest.GH1486
{
using System.Threading.Tasks;
using System.Threading;
[TestFixture]
public class FixtureAsync : BugTestCase
{
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<object>(ex);
}
}
}
Expand Down
28 changes: 0 additions & 28 deletions src/NHibernate.Test/Async/TypesTest/AbstractDateTimeTypeFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
namespace NHibernate.Test.TypesTest
{
using System.Threading.Tasks;
using System.Threading;
[TestFixture]
public abstract class AbstractDateTimeTypeFixtureAsync : TypeFixtureBase
{
Expand Down Expand Up @@ -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<DateTime>(), "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<DateTime>(), "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)]
Expand Down
17 changes: 0 additions & 17 deletions src/NHibernate.Test/Async/TypesTest/DateTimeOffsetTypeFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
namespace NHibernate.Test.TypesTest
{
using System.Threading.Tasks;
using System.Threading;
[TestFixture]
public class DateTimeOffsetTypeFixtureAsync : TypeFixtureBase
{
Expand Down Expand Up @@ -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<DateTimeOffset>(), "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<DateTimeOffset>(), "seed should be DateTime");
}

[Test]
public async Task ReadWriteAsync()
{
Expand Down
43 changes: 0 additions & 43 deletions src/NHibernate.Test/Async/TypesTest/Int16TypeFixture.cs

This file was deleted.

43 changes: 0 additions & 43 deletions src/NHibernate.Test/Async/TypesTest/Int32TypeFixture.cs

This file was deleted.

Loading