-
Notifications
You must be signed in to change notification settings - Fork 934
/
Copy pathEntityCacheUsage.cs
85 lines (82 loc) · 2.64 KB
/
EntityCacheUsage.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
namespace NHibernate.Cfg
{
/// <summary>
/// Values for class-cache and collection-cache strategy.
/// </summary>
public enum EntityCacheUsage
{
/// <summary>Xml value: read-only</summary>
Readonly,
/// <summary>Xml value: read-write</summary>
ReadWrite,
/// <summary>Xml value: nonstrict-read-write</summary>
NonStrictReadWrite,
/// <summary>Xml value: transactional</summary>
Transactional,
/// <summary>Xml value: never</summary>
Never
}
/// <summary>
/// Helper to parse <see cref="EntityCacheUsage"/> to and from XML string value.
/// </summary>
public static class EntityCacheUsageParser
{
private const string ReadOnlyXmlValue = "read-only";
private const string ReadWriteXmlValue = "read-write";
private const string NonstrictReadWriteXmlValue = "nonstrict-read-write";
private const string TransactionalXmlValue = "transactional";
private const string NeverXmlValue = "never";
/// <summary>
/// Convert a <see cref="EntityCacheUsage"/> in its xml expected value.
/// </summary>
/// <param name="value">The <see cref="EntityCacheUsage"/> to convert.</param>
/// <returns>The <see cref="EntityCacheUsage"/>.</returns>
public static string ToString(EntityCacheUsage value)
{
switch (value)
{
case EntityCacheUsage.Readonly:
return ReadOnlyXmlValue;
case EntityCacheUsage.ReadWrite:
return ReadWriteXmlValue;
case EntityCacheUsage.NonStrictReadWrite:
return NonstrictReadWriteXmlValue;
case EntityCacheUsage.Transactional:
return TransactionalXmlValue;
case EntityCacheUsage.Never:
return NeverXmlValue;
default:
return string.Empty;
}
}
/// <summary>
/// Convert a string to <see cref="EntityCacheUsage"/>.
/// </summary>
/// <param name="value">The string that represent <see cref="EntityCacheUsage"/>.</param>
/// <returns>
/// The <paramref name="value"/> converted to <see cref="EntityCacheUsage"/>.
/// </returns>
/// <exception cref="HibernateConfigException">If the values is invalid.</exception>
/// <remarks>
/// See <see cref="EntityCacheUsage"/> for allowed values.
/// </remarks>
public static EntityCacheUsage Parse(string value)
{
switch (value)
{
case ReadOnlyXmlValue:
return EntityCacheUsage.Readonly;
case ReadWriteXmlValue:
return EntityCacheUsage.ReadWrite;
case NonstrictReadWriteXmlValue:
return EntityCacheUsage.NonStrictReadWrite;
case TransactionalXmlValue:
return EntityCacheUsage.Transactional;
case NeverXmlValue:
return EntityCacheUsage.Never;
default:
throw new HibernateConfigException(string.Format("Invalid EntityCacheUsage value:{0}", value));
}
}
}
}