Skip to content

Commit 7f5908b

Browse files
author
Ivar Tiller
committed
IQueryCache constraint should be an IQueryCacheFactory constraint
The configuration setting is used to create an instance of a factory, not of the query cache itself.
1 parent 233c3b4 commit 7f5908b

File tree

8 files changed

+18
-156
lines changed

8 files changed

+18
-156
lines changed

src/NHibernate.Test/CfgTest/Loquacious/ConfigurationFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void CompleteConfiguration()
2929
.Through<HashtableCacheProvider>()
3030
.PrefixingRegionsWith("xyz")
3131
.Queries
32-
.Through<StandardQueryCache>()
32+
.Through<StandardQueryCacheFactory>()
3333
.UsingMinimalPuts()
3434
.WithDefaultExpiration(15)
3535
.GeneratingCollections
@@ -69,7 +69,7 @@ public void CompleteConfiguration()
6969
Assert.That(cfg.Properties[Environment.SessionFactoryName], Is.EqualTo("SomeName"));
7070
Assert.That(cfg.Properties[Environment.CacheProvider], Is.EqualTo(typeof(HashtableCacheProvider).AssemblyQualifiedName));
7171
Assert.That(cfg.Properties[Environment.CacheRegionPrefix], Is.EqualTo("xyz"));
72-
Assert.That(cfg.Properties[Environment.QueryCacheFactory], Is.EqualTo(typeof(StandardQueryCache).AssemblyQualifiedName));
72+
Assert.That(cfg.Properties[Environment.QueryCacheFactory], Is.EqualTo(typeof(StandardQueryCacheFactory).AssemblyQualifiedName));
7373
Assert.That(cfg.Properties[Environment.UseMinimalPuts], Is.EqualTo("true"));
7474
Assert.That(cfg.Properties[Environment.CacheDefaultExpiration], Is.EqualTo("15"));
7575
Assert.That(cfg.Properties[Environment.CollectionTypeFactoryClass], Is.EqualTo(typeof(DefaultCollectionTypeFactory).AssemblyQualifiedName));

src/NHibernate.Test/CfgTest/Loquacious/LambdaConfigurationFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public void FullConfiguration()
2727
c.DefaultExpiration = 15;
2828
c.RegionsPrefix = "xyz";
2929
c.Provider<HashtableCacheProvider>();
30-
c.QueryCache<StandardQueryCache>();
30+
c.QueryCache<StandardQueryCacheFactory>();
3131
});
3232
configure.CollectionTypeFactory<DefaultCollectionTypeFactory>();
3333
configure.HqlQueryTranslator<ASTQueryTranslatorFactory>();
@@ -69,7 +69,7 @@ public void FullConfiguration()
6969
Is.EqualTo(typeof(HashtableCacheProvider).AssemblyQualifiedName));
7070
Assert.That(configure.Properties[Environment.CacheRegionPrefix], Is.EqualTo("xyz"));
7171
Assert.That(configure.Properties[Environment.QueryCacheFactory],
72-
Is.EqualTo(typeof(StandardQueryCache).AssemblyQualifiedName));
72+
Is.EqualTo(typeof(StandardQueryCacheFactory).AssemblyQualifiedName));
7373
Assert.That(configure.Properties[Environment.UseMinimalPuts], Is.EqualTo("true"));
7474
Assert.That(configure.Properties[Environment.CacheDefaultExpiration], Is.EqualTo("15"));
7575
Assert.That(configure.Properties[Environment.CollectionTypeFactoryClass],

src/NHibernate.Test/MappingByCode/MappersTests/IdMapperTest.cs

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
using System;
21
using System.Linq;
32
using System.Reflection;
43
using NHibernate.Mapping.ByCode;
54
using NHibernate.Cfg.MappingSchema;
65
using NHibernate.Mapping.ByCode.Impl;
7-
using NHibernate.Type;
86
using NUnit.Framework;
97

108
namespace NHibernate.Test.MappingByCode.MappersTests
@@ -82,11 +80,6 @@ private class Related
8280
public int Id { get; set; }
8381
}
8482

85-
private enum MyEnum
86-
{
87-
One
88-
}
89-
9083
[Test]
9184
public void CanSetGeneratorForeign()
9285
{
@@ -217,82 +210,5 @@ public void CanSqlType()
217210
mapper.Column(x => x.SqlType("CHAR(10)"));
218211
Assert.That(hbmId.column[0].sqltype, Is.EqualTo("CHAR(10)"));
219212
}
220-
221-
[Test]
222-
public void WhenSetTypeByITypeThenSetTypeName()
223-
{
224-
var hbmId = new HbmId();
225-
var mapper = new IdMapper(null, hbmId);
226-
mapper.Type(NHibernateUtil.String);
227-
228-
Assert.That(hbmId.Type.name, Is.EqualTo("String"));
229-
}
230-
231-
[Test]
232-
public void WhenSetTypeByIUserTypeThenSetTypeName()
233-
{
234-
var hbmId = new HbmId();
235-
var mapper = new IdMapper(null, hbmId);
236-
mapper.Type<MyType>();
237-
238-
Assert.That(hbmId.Type.name, Does.Contain("MyType"));
239-
Assert.That(hbmId.type, Is.Null);
240-
}
241-
242-
[Test]
243-
public void WhenSetTypeByICompositeUserTypeThenSetTypeName()
244-
{
245-
var hbmId = new HbmId();
246-
var mapper = new IdMapper(null, hbmId);
247-
mapper.Type<MyCompoType>();
248-
249-
Assert.That(hbmId.Type.name, Does.Contain("MyCompoType"));
250-
Assert.That(hbmId.type, Is.Null);
251-
}
252-
253-
[Test]
254-
public void WhenSetTypeByIUserTypeWithParamsThenSetType()
255-
{
256-
var hbmId = new HbmId();
257-
var mapper = new IdMapper(null, hbmId);
258-
mapper.Type<MyType>(new { Param1 = "a", Param2 = 12 });
259-
260-
Assert.That(hbmId.type1, Is.Null);
261-
Assert.That(hbmId.Type.name, Does.Contain("MyType"));
262-
Assert.That(hbmId.Type.param, Has.Length.EqualTo(2));
263-
Assert.That(hbmId.Type.param.Select(p => p.name), Is.EquivalentTo(new [] {"Param1", "Param2"}));
264-
Assert.That(hbmId.Type.param.Select(p => p.GetText()), Is.EquivalentTo(new [] {"a", "12"}));
265-
}
266-
267-
[Test]
268-
public void WhenSetTypeByIUserTypeWithNullParamsThenSetTypeName()
269-
{
270-
var hbmId = new HbmId();
271-
var mapper = new IdMapper(null, hbmId);
272-
mapper.Type<MyType>(null);
273-
274-
Assert.That(hbmId.Type.name, Does.Contain("MyType"));
275-
Assert.That(hbmId.type, Is.Null);
276-
}
277-
278-
[Test]
279-
public void WhenSetTypeByITypeTypeThenSetType()
280-
{
281-
var hbmId = new HbmId();
282-
var mapper = new IdMapper(null, hbmId);
283-
mapper.Type<EnumStringType<MyEnum>>();
284-
285-
Assert.That(hbmId.Type.name, Does.Contain(typeof(EnumStringType<MyEnum>).FullName));
286-
Assert.That(hbmId.type, Is.Null);
287-
}
288-
289-
[Test]
290-
public void WhenSetInvalidTypeThenThrow()
291-
{
292-
var hbmId = new HbmId();
293-
var mapper = new IdMapper(null, hbmId);
294-
Assert.That(() => mapper.Type(typeof(object), null), Throws.TypeOf<ArgumentOutOfRangeException>());
295-
Assert.That(() => mapper.Type(null, null), Throws.TypeOf<ArgumentNullException>());
296-
}
297213
}
298214
}

src/NHibernate/Cfg/Loquacious/CacheConfiguration.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void Provider<TProvider>() where TProvider : ICacheProvider
3939
cfg.SetProperty(Environment.CacheProvider, typeof(TProvider).AssemblyQualifiedName);
4040
}
4141

42-
public void QueryCache<TFactory>() where TFactory : IQueryCache
42+
public void QueryCache<TFactory>() where TFactory : IQueryCacheFactory
4343
{
4444
UseSecondLevelCache = true;
4545
UseQueryCache = true;
@@ -111,7 +111,7 @@ public QueryCacheConfiguration(CacheConfiguration cc)
111111

112112
#region Implementation of IQueryCacheConfiguration
113113

114-
public ICacheConfiguration Through<TFactory>() where TFactory : IQueryCache
114+
public ICacheConfiguration Through<TFactory>() where TFactory : IQueryCacheFactory
115115
{
116116
cc.Configuration.SetProperty(Environment.UseSecondLevelCache, "true");
117117
cc.Configuration.SetProperty(Environment.UseQueryCache, "true");
@@ -121,4 +121,4 @@ public ICacheConfiguration Through<TFactory>() where TFactory : IQueryCache
121121

122122
#endregion
123123
}
124-
}
124+
}

src/NHibernate/Cfg/Loquacious/ICacheConfiguration.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ public interface ICacheConfigurationProperties
1717
string RegionsPrefix { set; }
1818
int DefaultExpiration { set; }
1919
void Provider<TProvider>() where TProvider : ICacheProvider;
20-
void QueryCache<TFactory>() where TFactory : IQueryCache;
20+
void QueryCache<TFactory>() where TFactory : IQueryCacheFactory;
2121
}
22-
}
22+
}

src/NHibernate/Cfg/Loquacious/IQueryCacheConfiguration.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ namespace NHibernate.Cfg.Loquacious
44
{
55
public interface IQueryCacheConfiguration
66
{
7-
ICacheConfiguration Through<TFactory>() where TFactory : IQueryCache;
7+
ICacheConfiguration Through<TFactory>() where TFactory : IQueryCacheFactory;
88
}
9-
}
9+
}
Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System;
2-
using NHibernate.Mapping.ByCode.Impl;
32
using NHibernate.Type;
4-
using NHibernate.Util;
53

64
namespace NHibernate.Mapping.ByCode
75
{
@@ -11,31 +9,12 @@ public interface IIdMapper : IAccessorPropertyMapper, IColumnsMapper
119
void Generator(IGeneratorDef generator, Action<IGeneratorMapper> generatorMapping);
1210

1311
void Type(IIdentifierType persistentType);
12+
//void Type<TPersistentType>() where TPersistentType : IIdentifierType;
13+
//void Type<TPersistentType>(object parameters) where TPersistentType : IIdentifierType;
14+
//void Type(System.System.Type persistentType, object parameters);
15+
//void Column(Action<IColumnMapper> columnMapper);
16+
//void Columns(params Action<IColumnMapper>[] columnMapper);
1417
void UnsavedValue(object value);
1518
void Length(int length);
1619
}
17-
18-
public static class IdMapperExtensions
19-
{
20-
public static void Type<TPersistentType>(this IIdMapper idMapper)
21-
{
22-
Type<TPersistentType>(idMapper, null);
23-
}
24-
25-
public static void Type<TPersistentType>(this IIdMapper idMapper, object parameters)
26-
{
27-
Type(idMapper, typeof (TPersistentType), parameters);
28-
}
29-
30-
// 6.0 TODO: move into IIdMapper,
31-
// and probably add an ITypeMapper for mutualizing it with IElementMapper and IPropertyMapper
32-
// (Note that there is no IKeyPropertyMapper to be concerned with, the KeyPropertyMapper use IPropertyMapper
33-
// directly instead.)
34-
public static void Type(this IIdMapper idMapper, System.Type persistentType, object parameters)
35-
{
36-
ReflectHelper
37-
.CastOrThrow<IdMapper>(idMapper, "Type method with a type argument")
38-
.Type(persistentType, parameters);
39-
}
40-
}
41-
}
20+
}

src/NHibernate/Mapping/ByCode/Impl/IdMapper.cs

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Reflection;
55
using NHibernate.Cfg.MappingSchema;
66
using NHibernate.Type;
7-
using NHibernate.UserTypes;
87

98
namespace NHibernate.Mapping.ByCode.Impl
109
{
@@ -67,38 +66,6 @@ public void Type(IIdentifierType persistentType)
6766
}
6867
}
6968

70-
public void Type(System.Type persistentType, object parameters)
71-
{
72-
if (persistentType == null)
73-
{
74-
throw new ArgumentNullException(nameof(persistentType));
75-
}
76-
if (!typeof (IUserType).IsAssignableFrom(persistentType) && !typeof (IType).IsAssignableFrom(persistentType) && !typeof (ICompositeUserType).IsAssignableFrom(persistentType))
77-
{
78-
throw new ArgumentOutOfRangeException(nameof(persistentType), "Expected type implementing IUserType, ICompositeUserType or IType.");
79-
}
80-
if (parameters != null)
81-
{
82-
hbmId.type1 = null;
83-
var hbmType = new HbmType
84-
{
85-
name = persistentType.AssemblyQualifiedName,
86-
param = (from pi in parameters.GetType().GetProperties()
87-
let pname = pi.Name
88-
let pvalue = pi.GetValue(parameters, null)
89-
select
90-
new HbmParam {name = pname, Text = new[] {ReferenceEquals(pvalue, null) ? "null" : pvalue.ToString()}})
91-
.ToArray()
92-
};
93-
hbmId.type = hbmType;
94-
}
95-
else
96-
{
97-
hbmId.type1 = persistentType.AssemblyQualifiedName;
98-
hbmId.type = null;
99-
}
100-
}
101-
10269
public void UnsavedValue(object value)
10370
{
10471
hbmId.unsavedvalue = value != null ? value.ToString() : "null";
@@ -215,4 +182,4 @@ public void Access(System.Type accessorType) {}
215182

216183
#endregion
217184
}
218-
}
185+
}

0 commit comments

Comments
 (0)