-
Notifications
You must be signed in to change notification settings - Fork 933
Fix ExtractInterceptor for subclasses #2509
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
src/NHibernate.Test/Async/NHSpecificTest/GH2508/AuditEventListener.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by AsyncGenerator. | ||
// | ||
// Changes to this file may cause incorrect behavior and will be lost if | ||
// the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
|
||
using System; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using NHibernate.Cfg; | ||
using NHibernate.Event; | ||
using NHibernate.Persister.Entity; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH2508 | ||
{ | ||
public partial class AuditEventListener : IPreCollectionUpdateEventListener | ||
{ | ||
public Task OnPreUpdateCollectionAsync(PreCollectionUpdateEvent @event, CancellationToken cancellationToken) | ||
{ | ||
try | ||
{ | ||
var ownerEntity = @event.AffectedOwnerOrNull; | ||
var collectionEntry = @event.Session.PersistenceContext.GetCollectionEntry(@event.Collection); | ||
if (!collectionEntry.LoadedPersister.IsInverse) | ||
return Task.CompletedTask; | ||
|
||
var abstractCollectionPersister = collectionEntry.LoadedPersister as Persister.Collection.AbstractCollectionPersister; | ||
if (abstractCollectionPersister == null) | ||
return Task.CompletedTask; | ||
|
||
var ownerEntityPersister = abstractCollectionPersister.OwnerEntityPersister; | ||
ownerEntityPersister.GetPropertyValues(ownerEntity); | ||
return Task.CompletedTask; | ||
} | ||
catch (Exception ex) | ||
{ | ||
return Task.FromException<object>(ex); | ||
} | ||
} | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
src/NHibernate.Test/Async/NHSpecificTest/GH2508/Fixture.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by AsyncGenerator. | ||
// | ||
// Changes to this file may cause incorrect behavior and will be lost if | ||
// the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
|
||
using System.Linq; | ||
using NHibernate.Cfg; | ||
using NUnit.Framework; | ||
using NHibernate.Linq; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH2508 | ||
{ | ||
using System.Threading.Tasks; | ||
[TestFixture] | ||
public class FixtureAsync : BugTestCase | ||
{ | ||
protected override void Configure(Configuration configuration) | ||
{ | ||
var listeners = configuration.EventListeners; | ||
listeners.PreCollectionUpdateEventListeners = | ||
new[] {new AuditEventListener()} | ||
.Concat(listeners.PreCollectionUpdateEventListeners) | ||
.ToArray(); | ||
} | ||
|
||
protected override void OnSetUp() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
var e1 = new LoggerCase {Name = "Bob"}; | ||
session.Save(e1); | ||
|
||
var e2 = new LoggerCase {Name = "Sally"}; | ||
session.Save(e2); | ||
|
||
transaction.Commit(); | ||
} | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
session.Delete("from System.Object"); | ||
transaction.Commit(); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task TestPreCollectionUpdateEventAsync() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
var result = await ((from e in session.Query<LoggerCase>() | ||
where e.Name == "Bob" | ||
select e).FirstAsync()); | ||
|
||
result.Children.Add(new Child { Logger = result, Name = "child" }); | ||
await (session.SaveOrUpdateAsync(result)); | ||
await (transaction.CommitAsync()); | ||
} | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/NHibernate.Test/NHSpecificTest/GH2508/AuditEventListener.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using NHibernate.Cfg; | ||
using NHibernate.Event; | ||
using NHibernate.Persister.Entity; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH2508 | ||
{ | ||
public partial class AuditEventListener : IPreCollectionUpdateEventListener | ||
{ | ||
public void OnPreUpdateCollection(PreCollectionUpdateEvent @event) | ||
{ | ||
var ownerEntity = @event.AffectedOwnerOrNull; | ||
var collectionEntry = @event.Session.PersistenceContext.GetCollectionEntry(@event.Collection); | ||
if (!collectionEntry.LoadedPersister.IsInverse) | ||
return; | ||
|
||
var abstractCollectionPersister = collectionEntry.LoadedPersister as Persister.Collection.AbstractCollectionPersister; | ||
if (abstractCollectionPersister == null) | ||
return; | ||
|
||
var ownerEntityPersister = abstractCollectionPersister.OwnerEntityPersister; | ||
ownerEntityPersister.GetPropertyValues(ownerEntity); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH2508 | ||
{ | ||
public class Child | ||
{ | ||
public virtual Guid Id { get; set; } | ||
public virtual string Name { get; set; } | ||
public virtual LoggerBase Logger { get; set; } | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System.Linq; | ||
using NHibernate.Cfg; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH2508 | ||
{ | ||
[TestFixture] | ||
public class Fixture : BugTestCase | ||
{ | ||
protected override void Configure(Configuration configuration) | ||
{ | ||
var listeners = configuration.EventListeners; | ||
listeners.PreCollectionUpdateEventListeners = | ||
new[] {new AuditEventListener()} | ||
.Concat(listeners.PreCollectionUpdateEventListeners) | ||
.ToArray(); | ||
} | ||
|
||
protected override void OnSetUp() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
var e1 = new LoggerCase {Name = "Bob"}; | ||
session.Save(e1); | ||
|
||
var e2 = new LoggerCase {Name = "Sally"}; | ||
session.Save(e2); | ||
|
||
transaction.Commit(); | ||
} | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
session.Delete("from System.Object"); | ||
transaction.Commit(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void TestPreCollectionUpdateEvent() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
var result = (from e in session.Query<LoggerCase>() | ||
where e.Name == "Bob" | ||
select e).First(); | ||
|
||
result.Children.Add(new Child { Logger = result, Name = "child" }); | ||
session.SaveOrUpdate(result); | ||
transaction.Commit(); | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH2508 | ||
{ | ||
public abstract class LoggerBase | ||
{ | ||
public LoggerBase() | ||
{ | ||
Children = new List<Child>(); | ||
} | ||
|
||
public virtual string Solution { get; set; } | ||
|
||
public virtual Guid Id { get; set; } | ||
|
||
public virtual string Name { get; set; } | ||
|
||
public virtual IList<Child> Children { get; set; } | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace NHibernate.Test.NHSpecificTest.GH2508 | ||
{ | ||
public class LoggerCase : LoggerBase | ||
{ | ||
public virtual string Description { get; set; } | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/NHibernate.Test/NHSpecificTest/GH2508/Mappings.hbm.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" | ||
namespace="NHibernate.Test.NHSpecificTest.GH2508"> | ||
|
||
<class name="LoggerBase" abstract="true" polymorphism="implicit"> | ||
<id name="Id" generator="guid.comb"/> | ||
|
||
<property name="Name"/> | ||
<property name="Solution" type="StringClob" lazy="true"/> | ||
|
||
<bag name="Children" cascade="all-delete-orphan" inverse="true"> | ||
<key column="LoggerBaseId"/> | ||
<one-to-many class="Child"/> | ||
</bag> | ||
|
||
<joined-subclass name="LoggerCase"> | ||
<key column="Id" /> | ||
<property name="Description"/> | ||
</joined-subclass> | ||
</class> | ||
|
||
<class name="Child"> | ||
<id name="Id" generator="guid.comb"/> | ||
|
||
<many-to-one name="Logger" class="LoggerBase" column="LoggerBaseId" /> | ||
<property name="Name"/> | ||
</class> | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
</hibernate-mapping> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.