-
Notifications
You must be signed in to change notification settings - Fork 931
Refactor Command parts to avoid duplicate characters. Reduces memory footprint #3742
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
tschu-schleupen
wants to merge
5
commits into
nhibernate:master
Choose a base branch
from
schleupen:5.5.x
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+57
−1
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5062dae
Fix collection cache lookup failure with enum keys (backport #3693) (…
mergify[bot] 1c6062f
don't duplicate ",", ", ", "(", ")" in Command parts
tschu-schleupen 6e60a6f
add using
tschu-schleupen 7dcb0e8
Add comment to explain switch logic
tschu-schleupen 8764e4a
Merge branch 'master' into 5.5.x
tschu-schleupen 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
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
124 changes: 124 additions & 0 deletions
124
src/NHibernate.Test/Async/NHSpecificTest/GH3643/FixtureByCode.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,124 @@ | ||
| //------------------------------------------------------------------------------ | ||
| // <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 NHibernate.Cfg.MappingSchema; | ||
| using NHibernate.Linq; | ||
| using NHibernate.Mapping.ByCode; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace NHibernate.Test.NHSpecificTest.GH3643 | ||
| { | ||
| using System.Threading.Tasks; | ||
| using System.Threading; | ||
| [TestFixture] | ||
| public class FixtureByCodeAsync : TestCaseMappingByCode | ||
| { | ||
| protected override void Configure(Configuration configuration) | ||
| { | ||
| configuration.SetProperty(Environment.UseQueryCache, "true"); | ||
| configuration.SetProperty(Environment.GenerateStatistics, "true"); | ||
| } | ||
|
|
||
| protected override HbmMapping GetMappings() | ||
| { | ||
| var mapper = new ModelMapper(); | ||
|
|
||
| mapper.Class<Entity>( | ||
| rc => | ||
| { | ||
| rc.Id(x => x.Id); | ||
| rc.Bag( | ||
| x => x.Children, | ||
| m => | ||
| { | ||
| m.Access(Accessor.Field); | ||
| m.Key(k => k.Column("EntityId")); | ||
| m.Cascade(Mapping.ByCode.Cascade.All); | ||
| }, | ||
| r => r.OneToMany()); | ||
|
|
||
| rc.Cache( | ||
| cm => | ||
| { | ||
| cm.Include(CacheInclude.All); | ||
| cm.Usage(CacheUsage.ReadWrite); | ||
| }); | ||
| }); | ||
|
|
||
| mapper.Class<ChildEntity>( | ||
| rc => | ||
| { | ||
| rc.Id(x => x.Id); | ||
| rc.Cache( | ||
| cm => | ||
| { | ||
| cm.Include(CacheInclude.All); | ||
| cm.Usage(CacheUsage.ReadWrite); | ||
| }); | ||
| }); | ||
|
|
||
| return mapper.CompileMappingForAllExplicitlyAddedEntities(); | ||
| } | ||
|
|
||
| protected override void OnSetUp() | ||
| { | ||
| using var session = OpenSession(); | ||
| using var transaction = session.BeginTransaction(); | ||
|
|
||
| var entity = new Entity { Id = EntityId.Id1 }; | ||
| entity.Children.Add(new ChildEntity { Id = 0 }); | ||
| entity.Children.Add(new ChildEntity { Id = 1 }); | ||
| session.Save(entity); | ||
|
|
||
| transaction.Commit(); | ||
| } | ||
|
|
||
| protected override void OnTearDown() | ||
| { | ||
| using var session = OpenSession(); | ||
| using var transaction = session.BeginTransaction(); | ||
|
|
||
| session.CreateQuery("delete from ChildEntity").ExecuteUpdate(); | ||
| session.CreateQuery("delete from System.Object").ExecuteUpdate(); | ||
|
|
||
| transaction.Commit(); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task LoadsEntityWithEnumIdAndChildrenUsingQueryCacheAsync() | ||
| { | ||
| await (LoadEntityWithQueryCacheAsync()); // warm up cache | ||
|
|
||
| var entity = await (LoadEntityWithQueryCacheAsync()); | ||
|
|
||
| Assert.That(entity.Children.Count(), Is.EqualTo(2)); | ||
|
|
||
| Assert.That(Sfi.Statistics.QueryExecutionCount, Is.EqualTo(1), "Unexpected execution count"); | ||
| Assert.That(Sfi.Statistics.QueryCachePutCount, Is.EqualTo(1), "Unexpected cache put count"); | ||
| Assert.That(Sfi.Statistics.QueryCacheHitCount, Is.EqualTo(1), "Unexpected cache hit count"); | ||
| } | ||
|
|
||
| private async Task<Entity> LoadEntityWithQueryCacheAsync(CancellationToken cancellationToken = default(CancellationToken)) | ||
| { | ||
| using var session = OpenSession(); | ||
| using var transaction = session.BeginTransaction(); | ||
| var entity = (await (session | ||
| .Query<Entity>() | ||
| .FetchMany(x => x.Children) | ||
| .WithOptions(opt => opt.SetCacheable(true)) | ||
| .ToListAsync(cancellationToken)))[0]; | ||
|
|
||
| await (transaction.CommitAsync(cancellationToken)); | ||
| return entity; | ||
| } | ||
| } | ||
| } |
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,25 @@ | ||
| using System.Collections.Generic; | ||
|
|
||
| // ReSharper disable CollectionNeverUpdated.Local | ||
| // ReSharper disable UnassignedGetOnlyAutoProperty | ||
|
|
||
| namespace NHibernate.Test.NHSpecificTest.GH3643 | ||
| { | ||
| class Entity | ||
| { | ||
| private readonly ICollection<ChildEntity> _children = new List<ChildEntity>(); | ||
| public virtual EntityId Id { get; set; } | ||
| public virtual ICollection<ChildEntity> Children => _children; | ||
| } | ||
|
|
||
| class ChildEntity | ||
| { | ||
| public virtual int Id { get; set; } | ||
| } | ||
|
|
||
| enum EntityId | ||
| { | ||
| Id1, | ||
| Id2 | ||
| } | ||
| } |
112 changes: 112 additions & 0 deletions
112
src/NHibernate.Test/NHSpecificTest/GH3643/FixtureByCode.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,112 @@ | ||
| using System.Linq; | ||
| using NHibernate.Cfg; | ||
| using NHibernate.Cfg.MappingSchema; | ||
| using NHibernate.Linq; | ||
| using NHibernate.Mapping.ByCode; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace NHibernate.Test.NHSpecificTest.GH3643 | ||
| { | ||
| [TestFixture] | ||
| public class FixtureByCode : TestCaseMappingByCode | ||
| { | ||
| protected override void Configure(Configuration configuration) | ||
| { | ||
| configuration.SetProperty(Environment.UseQueryCache, "true"); | ||
| configuration.SetProperty(Environment.GenerateStatistics, "true"); | ||
| } | ||
|
|
||
| protected override HbmMapping GetMappings() | ||
| { | ||
| var mapper = new ModelMapper(); | ||
|
|
||
| mapper.Class<Entity>( | ||
| rc => | ||
| { | ||
| rc.Id(x => x.Id); | ||
| rc.Bag( | ||
| x => x.Children, | ||
| m => | ||
| { | ||
| m.Access(Accessor.Field); | ||
| m.Key(k => k.Column("EntityId")); | ||
| m.Cascade(Mapping.ByCode.Cascade.All); | ||
| }, | ||
| r => r.OneToMany()); | ||
|
|
||
| rc.Cache( | ||
| cm => | ||
| { | ||
| cm.Include(CacheInclude.All); | ||
| cm.Usage(CacheUsage.ReadWrite); | ||
| }); | ||
| }); | ||
|
|
||
| mapper.Class<ChildEntity>( | ||
| rc => | ||
| { | ||
| rc.Id(x => x.Id); | ||
| rc.Cache( | ||
| cm => | ||
| { | ||
| cm.Include(CacheInclude.All); | ||
| cm.Usage(CacheUsage.ReadWrite); | ||
| }); | ||
| }); | ||
|
|
||
| return mapper.CompileMappingForAllExplicitlyAddedEntities(); | ||
| } | ||
|
|
||
| protected override void OnSetUp() | ||
| { | ||
| using var session = OpenSession(); | ||
| using var transaction = session.BeginTransaction(); | ||
|
|
||
| var entity = new Entity { Id = EntityId.Id1 }; | ||
| entity.Children.Add(new ChildEntity { Id = 0 }); | ||
| entity.Children.Add(new ChildEntity { Id = 1 }); | ||
| session.Save(entity); | ||
|
|
||
| transaction.Commit(); | ||
| } | ||
|
|
||
| protected override void OnTearDown() | ||
| { | ||
| using var session = OpenSession(); | ||
| using var transaction = session.BeginTransaction(); | ||
|
|
||
| session.CreateQuery("delete from ChildEntity").ExecuteUpdate(); | ||
| session.CreateQuery("delete from System.Object").ExecuteUpdate(); | ||
|
|
||
| transaction.Commit(); | ||
| } | ||
|
|
||
| [Test] | ||
| public void LoadsEntityWithEnumIdAndChildrenUsingQueryCache() | ||
| { | ||
| LoadEntityWithQueryCache(); // warm up cache | ||
|
|
||
| var entity = LoadEntityWithQueryCache(); | ||
|
|
||
| Assert.That(entity.Children.Count(), Is.EqualTo(2)); | ||
|
|
||
| Assert.That(Sfi.Statistics.QueryExecutionCount, Is.EqualTo(1), "Unexpected execution count"); | ||
| Assert.That(Sfi.Statistics.QueryCachePutCount, Is.EqualTo(1), "Unexpected cache put count"); | ||
| Assert.That(Sfi.Statistics.QueryCacheHitCount, Is.EqualTo(1), "Unexpected cache hit count"); | ||
| } | ||
|
|
||
| private Entity LoadEntityWithQueryCache() | ||
| { | ||
| using var session = OpenSession(); | ||
| using var transaction = session.BeginTransaction(); | ||
| var entity = session | ||
| .Query<Entity>() | ||
| .FetchMany(x => x.Children) | ||
| .WithOptions(opt => opt.SetCacheable(true)) | ||
| .ToList()[0]; | ||
|
|
||
| transaction.Commit(); | ||
| return entity; | ||
| } | ||
| } | ||
| } |
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
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
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
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
Oops, something went wrong.
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.