Skip to content

Commit 92f158d

Browse files
committed
Add SupportsQueryCache extension methods
1 parent 52d88e2 commit 92f158d

File tree

7 files changed

+30
-18
lines changed

7 files changed

+30
-18
lines changed

src/NHibernate/Action/BulkOperationCleanupAction.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ public BulkOperationCleanupAction(ISessionImplementor session, IQueryable[] affe
3939
affectedCollectionRoles.UnionWith(roles);
4040
}
4141

42-
// 6.0 TODO: the cast and comparison to false will no more be needed once IPersister's todo is done.
43-
var supportsQuerySpace = (affectedQueryable as IPersister)?.SupportsQueryCache != false;
42+
// 6.0 TODO: Use IPersister.SupportsQueryCache property once IPersister's todo is done.
43+
var supportsQuerySpace = affectedQueryable.SupportsQueryCache();
4444
foreach (var querySpace in affectedQueryable.QuerySpaces)
4545
{
4646
affectedSpaces.Add(querySpace);
47-
if (supportsQuerySpace )
47+
if (supportsQuerySpace)
4848
{
4949
affectedQueryCacheSpaces.Add(querySpace);
5050
}
@@ -78,8 +78,8 @@ public BulkOperationCleanupAction(ISessionImplementor session, ISet<string> quer
7878
affectedCollectionRoles.UnionWith(roles);
7979
}
8080

81-
// 6.0 TODO: the cast and comparison to false will no more be needed once IPersister's todo is done.
82-
var supportsQuerySpace = (persister as IPersister)?.SupportsQueryCache != false;
81+
// 6.0 TODO: Use IPersister.SupportsQueryCache property once IPersister's todo is done.
82+
var supportsQuerySpace = persister.SupportsQueryCache();
8383
foreach (var querySpace in persister.QuerySpaces)
8484
{
8585
affectedSpaces.Add(querySpace);

src/NHibernate/Action/CollectionAction.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ public string[] QueryCacheSpaces
9090
{
9191
get
9292
{
93-
// 6.0 TODO: the cast and comparison to false will no more be needed once IPersister's todo is done.
94-
return (persister as IPersister)?.SupportsQueryCache == false ? null : persister.CollectionSpaces;
93+
// 6.0 TODO: Use IPersister.SupportsQueryCache property once IPersister's todo is done.
94+
return persister.SupportsQueryCache() ? persister.CollectionSpaces : null;
9595
}
9696
}
9797

src/NHibernate/Action/EntityAction.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ public string[] QueryCacheSpaces
101101
{
102102
get
103103
{
104-
// 6.0 TODO: the cast and comparison to false will no more be needed once IPersister's todo is done.
105-
return (persister as IPersister)?.SupportsQueryCache == false ? null : persister.PropertySpaces;
104+
// 6.0 TODO: Use IPersister.SupportsQueryCache property once IPersister's todo is done.
105+
return persister.SupportsQueryCache() ? persister.PropertySpaces : null;
106106
}
107107
}
108108

src/NHibernate/Loader/Custom/CustomLoader.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ public CustomLoader(ICustomQuery customQuery, ISessionFactoryImplementor factory
103103
specifiedAliases.Add(rootRtn.Alias);
104104
entityaliases.Add(rootRtn.EntityAliases);
105105
querySpaces.UnionWith(persister.QuerySpaces);
106-
// 6.0 TODO: the cast and null coalesce to true will no more be needed once IPersister's todo is done.
107-
supportsQueryCache = supportsQueryCache && ((persister as IPersister)?.SupportsQueryCache ?? true);
106+
// 6.0 TODO: Use IPersister.SupportsQueryCache property once IPersister's todo is done.
107+
supportsQueryCache = supportsQueryCache && persister.SupportsQueryCache();
108108
includeInResultRowList.Add(true);
109109
}
110110
else if (rtn is CollectionReturn)
@@ -129,8 +129,8 @@ public CustomLoader(ICustomQuery customQuery, ISessionFactoryImplementor factory
129129
entityowners.Add(-1);
130130
entityaliases.Add(collRtn.ElementEntityAliases);
131131
querySpaces.UnionWith(elementPersister.QuerySpaces);
132-
// 6.0 TODO: the cast and null coalesce to true will no more be needed once IPersister's todo is done.
133-
supportsQueryCache = supportsQueryCache && ((elementPersister as IPersister)?.SupportsQueryCache ?? true);
132+
// 6.0 TODO: Use IPersister.SupportsQueryCache property once IPersister's todo is done.
133+
supportsQueryCache = supportsQueryCache && elementPersister.SupportsQueryCache();
134134
}
135135
includeInResultRowList.Add(true);
136136
}
@@ -150,8 +150,8 @@ public CustomLoader(ICustomQuery customQuery, ISessionFactoryImplementor factory
150150
specifiedAliases.Add(fetchRtn.Alias);
151151
entityaliases.Add(fetchRtn.EntityAliases);
152152
querySpaces.UnionWith(persister.QuerySpaces);
153-
// 6.0 TODO: the cast and null coalesce to true will no more be needed once IPersister's todo is done.
154-
supportsQueryCache = supportsQueryCache && ((persister as IPersister)?.SupportsQueryCache ?? true);
153+
// 6.0 TODO: Use IPersister.SupportsQueryCache property once IPersister's todo is done.
154+
supportsQueryCache = supportsQueryCache && persister.SupportsQueryCache();
155155
includeInResultRowList.Add(false);
156156
}
157157
else if (rtn is CollectionFetchReturn)
@@ -177,8 +177,8 @@ public CustomLoader(ICustomQuery customQuery, ISessionFactoryImplementor factory
177177
entityowners.Add(ownerIndex);
178178
entityaliases.Add(fetchRtn.ElementEntityAliases);
179179
querySpaces.UnionWith(elementPersister.QuerySpaces);
180-
// 6.0 TODO: the cast and null coalesce to true will no more be needed once IPersister's todo is done.
181-
supportsQueryCache = supportsQueryCache && ((elementPersister as IPersister)?.SupportsQueryCache ?? true);
180+
// 6.0 TODO: Use IPersister.SupportsQueryCache property once IPersister's todo is done.
181+
supportsQueryCache = supportsQueryCache && elementPersister.SupportsQueryCache();
182182
}
183183
includeInResultRowList.Add(false);
184184
}

src/NHibernate/Loader/Loader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1842,7 +1842,7 @@ internal bool IsCacheable(QueryParameters queryParameters, bool supportsQueryCac
18421842
{
18431843
throw new QueryException(
18441844
"Never cached entities/collections cannot be used in a cacheable query: " +
1845-
{string.Join(", ", persisters.Where(o => !o.SupportsQueryCache).Select(o => o.Name))});
1845+
string.Join(", ", persisters.Where(o => !o.SupportsQueryCache).Select(o => o.Name)));
18461846
}
18471847
else if (Log.IsWarnEnabled())
18481848
{

src/NHibernate/Persister/Collection/ICollectionPersister.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,5 +305,11 @@ public static int GetBatchSize(this ICollectionPersister persister)
305305

306306
return 1;
307307
}
308+
309+
// 6.0 TODO: Remove once IPersister's todo is done.
310+
internal static bool SupportsQueryCache(this ICollectionPersister persister)
311+
{
312+
return (persister as IPersister)?.SupportsQueryCache ?? true;
313+
}
308314
}
309315
}

src/NHibernate/Persister/Entity/IEntityPersister.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,5 +640,11 @@ public static void AfterInitialize(this IEntityPersister persister, object entit
640640
persister.AfterInitialize(entity, true, session);
641641
#pragma warning restore 618
642642
}
643+
644+
// 6.0 TODO: Remove once IPersister's todo is done.
645+
internal static bool SupportsQueryCache(this IEntityPersister persister)
646+
{
647+
return (persister as IPersister)?.SupportsQueryCache ?? true;
648+
}
643649
}
644650
}

0 commit comments

Comments
 (0)