-
Notifications
You must be signed in to change notification settings - Fork 934
/
Copy pathCollectionCacheConfiguration.cs
96 lines (89 loc) · 2.76 KB
/
CollectionCacheConfiguration.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
using System.Xml.XPath;
namespace NHibernate.Cfg.ConfigurationSchema
{
/// <summary>
/// Configuration parsed values for a collection-cache XML node.
/// </summary>
public class CollectionCacheConfiguration
{
internal CollectionCacheConfiguration(XPathNavigator collectionCacheElement)
{
Parse(collectionCacheElement);
}
/// <summary>
/// Initializes a new instance of the <see cref="CollectionCacheConfiguration"/> class.
/// </summary>
/// <param name="collection">The cache role.</param>
/// <param name="usage">Cache strategy.</param>
/// <exception cref="ArgumentException">When <paramref name="collection"/> is null or empty.</exception>
public CollectionCacheConfiguration(string collection, EntityCacheUsage usage)
{
if (String.IsNullOrEmpty(collection))
throw new ArgumentException("collection is null or empty.", "collection");
this.collection = collection;
this.usage = usage;
}
/// <summary>
/// Initializes a new instance of the <see cref="CollectionCacheConfiguration"/> class.
/// </summary>
/// <param name="collection">The cache role.</param>
/// <param name="usage">Cache strategy.</param>
/// <param name="region">The cache region.</param>
/// <exception cref="ArgumentException">When <paramref name="collection"/> is null or empty.</exception>
public CollectionCacheConfiguration(string collection, EntityCacheUsage usage, string region)
:this(collection,usage)
{
this.region = region;
}
private void Parse(XPathNavigator collectionCacheElement)
{
if (collectionCacheElement.MoveToFirstAttribute())
{
do
{
switch (collectionCacheElement.Name)
{
case "collection":
if (string.IsNullOrWhiteSpace(collectionCacheElement.Value))
throw new HibernateConfigException("Invalid collection-cache element; the attribute <collection> must be assigned with no empty value");
collection = collectionCacheElement.Value;
break;
case "usage":
usage = EntityCacheUsageParser.Parse(collectionCacheElement.Value);
break;
case "region":
region = collectionCacheElement.Value;
break;
}
}
while (collectionCacheElement.MoveToNextAttribute());
}
}
private string collection;
/// <summary>
/// The role.
/// </summary>
public string Collection
{
get { return collection; }
}
private string region;
/// <summary>
/// The cache region.
/// </summary>
/// <remarks>If null or empty the <see cref="CollectionCacheConfiguration.Collection"/> is used during configuration.</remarks>
public string Region
{
get { return region; }
}
private EntityCacheUsage usage;
/// <summary>
/// Cache strategy.
/// </summary>
public EntityCacheUsage Usage
{
get { return usage; }
}
}
}