|
From: <fab...@us...> - 2009-07-17 17:02:49
|
Revision: 4650
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4650&view=rev
Author: fabiomaulo
Date: 2009-07-17 17:02:38 +0000 (Fri, 17 Jul 2009)
Log Message:
-----------
Refactoring to allow class usage for fluent-conf.
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs
trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/CfgXmlHelper.cs
trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/ClassCacheConfiguration.cs
trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/CollectionCacheConfiguration.cs
trunk/nhibernate/src/NHibernate/NHibernate.csproj
trunk/nhibernate/src/NHibernate.Test/CfgTest/ConfigurationSchemaFixture.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Cfg/EntityCacheUsage.cs
trunk/nhibernate/src/NHibernate.Test/CfgTest/EntityCacheUsageParserFixture.cs
Modified: trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs 2009-07-17 15:02:04 UTC (rev 4649)
+++ trunk/nhibernate/src/NHibernate/Cfg/Configuration.cs 2009-07-17 17:02:38 UTC (rev 4650)
@@ -1434,7 +1434,7 @@
{
string region = string.IsNullOrEmpty(ccc.Region) ? ccc.Class : ccc.Region;
bool includeLazy = (ccc.Include != ClassCacheInclude.NonLazy);
- SetCacheConcurrencyStrategy(ccc.Class, CfgXmlHelper.ClassCacheUsageConvertToString(ccc.Usage), region, includeLazy);
+ SetCacheConcurrencyStrategy(ccc.Class, EntityCacheUsageParser.ToString(ccc.Usage), region, includeLazy);
}
// Load collection-cache
@@ -1449,7 +1449,7 @@
}
string region = string.IsNullOrEmpty(ccc.Region) ? role : ccc.Region;
- SetCollectionCacheConcurrencyStrategy(role, CfgXmlHelper.ClassCacheUsageConvertToString(ccc.Usage), region);
+ SetCollectionCacheConcurrencyStrategy(role, EntityCacheUsageParser.ToString(ccc.Usage), region);
}
// Events
Modified: trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/CfgXmlHelper.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/CfgXmlHelper.cs 2009-07-17 15:02:04 UTC (rev 4649)
+++ trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/CfgXmlHelper.cs 2009-07-17 17:02:38 UTC (rev 4650)
@@ -102,51 +102,6 @@
}
/// <summary>
- /// Convert a string to <see cref="ClassCacheUsage"/>.
- /// </summary>
- /// <param name="usage">The string that represent <see cref="ClassCacheUsage"/>.</param>
- /// <returns>
- /// The <paramref name="usage"/> converted to <see cref="ClassCacheUsage"/>.
- /// </returns>
- /// <exception cref="HibernateConfigException">If the values is invalid.</exception>
- /// <remarks>
- /// See <see cref="ClassCacheUsage"/> for allowed values.
- /// </remarks>
- public static ClassCacheUsage ClassCacheUsageConvertFrom(string usage)
- {
- switch (usage)
- {
- case "read-only":
- return ClassCacheUsage.Readonly;
- case "read-write":
- return ClassCacheUsage.ReadWrite;
- case "nonstrict-read-write":
- return ClassCacheUsage.NonStrictReadWrite;
- case "transactional":
- return ClassCacheUsage.Transactional;
- default:
- throw new HibernateConfigException(string.Format("Invalid ClassCacheUsage value:{0}", usage));
- }
- }
-
- internal static string ClassCacheUsageConvertToString(ClassCacheUsage usage)
- {
- switch (usage)
- {
- case ClassCacheUsage.Readonly:
- return "read-only";
- case ClassCacheUsage.ReadWrite:
- return "read-write";
- case ClassCacheUsage.NonStrictReadWrite:
- return "nonstrict-read-write";
- case ClassCacheUsage.Transactional:
- return "transactional";
- default:
- return string.Empty;
- }
- }
-
- /// <summary>
/// Convert a string to <see cref="ClassCacheInclude"/>.
/// </summary>
/// <param name="include">The string that represent <see cref="ClassCacheInclude"/>.</param>
Modified: trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/ClassCacheConfiguration.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/ClassCacheConfiguration.cs 2009-07-17 15:02:04 UTC (rev 4649)
+++ trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/ClassCacheConfiguration.cs 2009-07-17 17:02:38 UTC (rev 4650)
@@ -4,21 +4,6 @@
namespace NHibernate.Cfg.ConfigurationSchema
{
/// <summary>
- /// Values for class-cache and collection-cache strategy.
- /// </summary>
- public enum ClassCacheUsage
- {
- /// <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>
/// Values for class-cache include.
/// </summary>
/// <remarks>Not implemented in Cache.</remarks>
@@ -47,7 +32,7 @@
/// <param name="clazz">The class full name.</param>
/// <param name="usage">Cache strategy.</param>
/// <exception cref="ArgumentException">When <paramref name="clazz"/> is null or empty.</exception>
- public ClassCacheConfiguration(string clazz, ClassCacheUsage usage)
+ public ClassCacheConfiguration(string clazz, EntityCacheUsage usage)
{
if (string.IsNullOrEmpty(clazz))
throw new ArgumentException("clazz is null or empty.", "clazz");
@@ -62,7 +47,7 @@
/// <param name="usage">Cache strategy.</param>
/// <param name="include">Values for class-cache include.</param>
/// <exception cref="ArgumentException">When <paramref name="clazz"/> is null or empty.</exception>
- public ClassCacheConfiguration(string clazz, ClassCacheUsage usage, ClassCacheInclude include)
+ public ClassCacheConfiguration(string clazz, EntityCacheUsage usage, ClassCacheInclude include)
: this(clazz, usage)
{
this.include = include;
@@ -75,7 +60,7 @@
/// <param name="usage">Cache strategy.</param>
/// <param name="region">The cache region.</param>
/// <exception cref="ArgumentException">When <paramref name="clazz"/> is null or empty.</exception>
- public ClassCacheConfiguration(string clazz, ClassCacheUsage usage, string region)
+ public ClassCacheConfiguration(string clazz, EntityCacheUsage usage, string region)
: this(clazz, usage)
{
this.region = region;
@@ -89,7 +74,7 @@
/// <param name="include">Values for class-cache include.</param>
/// <param name="region">The cache region.</param>
/// <exception cref="ArgumentException">When <paramref name="clazz"/> is null or empty.</exception>
- public ClassCacheConfiguration(string clazz, ClassCacheUsage usage, ClassCacheInclude include, string region)
+ public ClassCacheConfiguration(string clazz, EntityCacheUsage usage, ClassCacheInclude include, string region)
: this(clazz, usage, include)
{
this.region = region;
@@ -109,7 +94,7 @@
clazz = classCacheElement.Value;
break;
case "usage":
- usage = CfgXmlHelper.ClassCacheUsageConvertFrom(classCacheElement.Value);
+ usage = EntityCacheUsageParser.Parse(classCacheElement.Value);
break;
case "region":
region = classCacheElement.Value;
@@ -143,11 +128,11 @@
}
- private ClassCacheUsage usage;
+ private EntityCacheUsage usage;
/// <summary>
/// Cache strategy.
/// </summary>
- public ClassCacheUsage Usage
+ public EntityCacheUsage Usage
{
get { return usage; }
}
Modified: trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/CollectionCacheConfiguration.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/CollectionCacheConfiguration.cs 2009-07-17 15:02:04 UTC (rev 4649)
+++ trunk/nhibernate/src/NHibernate/Cfg/ConfigurationSchema/CollectionCacheConfiguration.cs 2009-07-17 17:02:38 UTC (rev 4650)
@@ -19,7 +19,7 @@
/// <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, ClassCacheUsage usage)
+ public CollectionCacheConfiguration(string collection, EntityCacheUsage usage)
{
if (String.IsNullOrEmpty(collection))
throw new ArgumentException("collection is null or empty.", "collection");
@@ -34,7 +34,7 @@
/// <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, ClassCacheUsage usage, string region)
+ public CollectionCacheConfiguration(string collection, EntityCacheUsage usage, string region)
:this(collection,usage)
{
this.region = region;
@@ -54,7 +54,7 @@
collection = collectionCacheElement.Value;
break;
case "usage":
- usage = CfgXmlHelper.ClassCacheUsageConvertFrom(collectionCacheElement.Value);
+ usage = EntityCacheUsageParser.Parse(collectionCacheElement.Value);
break;
case "region":
region = collectionCacheElement.Value;
@@ -84,11 +84,11 @@
get { return region; }
}
- private ClassCacheUsage usage;
+ private EntityCacheUsage usage;
/// <summary>
/// Cache strategy.
/// </summary>
- public ClassCacheUsage Usage
+ public EntityCacheUsage Usage
{
get { return usage; }
}
Added: trunk/nhibernate/src/NHibernate/Cfg/EntityCacheUsage.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cfg/EntityCacheUsage.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Cfg/EntityCacheUsage.cs 2009-07-17 17:02:38 UTC (rev 4650)
@@ -0,0 +1,78 @@
+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>
+ /// 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";
+
+ /// <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;
+ 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;
+ default:
+ throw new HibernateConfigException(string.Format("Invalid EntityCacheUsage value:{0}", value));
+ }
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-07-17 15:02:04 UTC (rev 4649)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-07-17 17:02:38 UTC (rev 4650)
@@ -459,6 +459,7 @@
<Compile Include="Bytecode\ProxyFactoryFactoryNotConfiguredException.cs" />
<Compile Include="Bytecode\UnableToLoadProxyFactoryFactoryException.cs" />
<Compile Include="Cache\FakeCache.cs" />
+ <Compile Include="Cfg\EntityCacheUsage.cs" />
<Compile Include="Cfg\Hbm2ddlKeyWords.cs" />
<Compile Include="Cfg\Loquacious\CacheConfiguration.cs" />
<Compile Include="Cfg\Loquacious\ConfigurationExtensions.cs" />
Modified: trunk/nhibernate/src/NHibernate.Test/CfgTest/ConfigurationSchemaFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/CfgTest/ConfigurationSchemaFixture.cs 2009-07-17 15:02:04 UTC (rev 4649)
+++ trunk/nhibernate/src/NHibernate.Test/CfgTest/ConfigurationSchemaFixture.cs 2009-07-17 17:02:38 UTC (rev 4650)
@@ -178,7 +178,7 @@
HibernateConfiguration hc = new HibernateConfiguration(xtr);
Assert.AreEqual(1, hc.SessionFactory.ClassesCache.Count);
Assert.AreEqual("Class1", hc.SessionFactory.ClassesCache[0].Class);
- Assert.AreEqual(ClassCacheUsage.Readonly, hc.SessionFactory.ClassesCache[0].Usage);
+ Assert.AreEqual(EntityCacheUsage.Readonly, hc.SessionFactory.ClassesCache[0].Usage);
Assert.AreEqual(ClassCacheInclude.NonLazy, hc.SessionFactory.ClassesCache[0].Include);
Assert.AreEqual("ARegion", hc.SessionFactory.ClassesCache[0].Region);
}
@@ -198,7 +198,7 @@
HibernateConfiguration hc = new HibernateConfiguration(xtr);
Assert.AreEqual(1, hc.SessionFactory.CollectionsCache.Count);
Assert.AreEqual("Collection1", hc.SessionFactory.CollectionsCache[0].Collection);
- Assert.AreEqual(ClassCacheUsage.NonStrictReadWrite, hc.SessionFactory.CollectionsCache[0].Usage);
+ Assert.AreEqual(EntityCacheUsage.NonStrictReadWrite, hc.SessionFactory.CollectionsCache[0].Usage);
Assert.AreEqual("ARegion", hc.SessionFactory.CollectionsCache[0].Region);
}
Added: trunk/nhibernate/src/NHibernate.Test/CfgTest/EntityCacheUsageParserFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/CfgTest/EntityCacheUsageParserFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/CfgTest/EntityCacheUsageParserFixture.cs 2009-07-17 17:02:38 UTC (rev 4650)
@@ -0,0 +1,27 @@
+using NHibernate.Cfg;
+using NUnit.Framework;
+
+namespace NHibernate.Test.CfgTest
+{
+ [TestFixture]
+ public class EntityCacheUsageParserFixture
+ {
+ [Test]
+ public void CovertToString()
+ {
+ Assert.That(EntityCacheUsageParser.ToString(EntityCacheUsage.Readonly), Is.EqualTo("read-only"));
+ Assert.That(EntityCacheUsageParser.ToString(EntityCacheUsage.ReadWrite), Is.EqualTo("read-write"));
+ Assert.That(EntityCacheUsageParser.ToString(EntityCacheUsage.NonStrictReadWrite), Is.EqualTo("nonstrict-read-write"));
+ Assert.That(EntityCacheUsageParser.ToString(EntityCacheUsage.Transactional), Is.EqualTo("transactional"));
+ }
+
+ [Test]
+ public void Parse()
+ {
+ Assert.That(EntityCacheUsageParser.Parse("read-only"), Is.EqualTo(EntityCacheUsage.Readonly));
+ Assert.That(EntityCacheUsageParser.Parse("read-write"), Is.EqualTo(EntityCacheUsage.ReadWrite));
+ Assert.That(EntityCacheUsageParser.Parse("nonstrict-read-write"), Is.EqualTo(EntityCacheUsage.NonStrictReadWrite));
+ Assert.That(EntityCacheUsageParser.Parse("transactional"), Is.EqualTo(EntityCacheUsage.Transactional));
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-07-17 15:02:04 UTC (rev 4649)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-07-17 17:02:38 UTC (rev 4650)
@@ -104,6 +104,7 @@
<Compile Include="CfgTest\ConfigurationSchemaFixture.cs" />
<Compile Include="CfgTest\ConfigurationSerializationTests.cs" />
<Compile Include="CfgTest\DefaultNsAssmFixture.cs" />
+ <Compile Include="CfgTest\EntityCacheUsageParserFixture.cs" />
<Compile Include="CfgTest\HbmBinderFixture.cs" />
<Compile Include="CfgTest\HbmOrderingFixture.cs" />
<Compile Include="CfgTest\LocatedInTestAssembly.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|