|
From: <fab...@us...> - 2009-05-17 16:36:02
|
Revision: 4333
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4333&view=rev
Author: fabiomaulo
Date: 2009-05-17 16:35:57 +0000 (Sun, 17 May 2009)
Log Message:
-----------
Fix NH-1093
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Cache/NoCacheProvider.cs
trunk/nhibernate/src/NHibernate/NHibernate.csproj
trunk/nhibernate/src/NHibernate/Util/PropertiesHelper.cs
trunk/nhibernate/src/NHibernate.Test/LogSpy.cs
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Cache/FakeCache.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1093/
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1093/Fixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1093/Mappings.hbm.xml
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1093/SimpleCached.cs
Removed Paths:
-------------
trunk/nhibernate/src/NHibernate/Cache/NoCachingEnabledException.cs
Added: trunk/nhibernate/src/NHibernate/Cache/FakeCache.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cache/FakeCache.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Cache/FakeCache.cs 2009-05-17 16:35:57 UTC (rev 4333)
@@ -0,0 +1,50 @@
+namespace NHibernate.Cache
+{
+ /// <summary>
+ /// Used by <see cref="NoCacheProvider"/>
+ /// </summary>
+ public class FakeCache : ICache
+ {
+ public FakeCache(string regionName)
+ {
+ RegionName = regionName;
+ }
+
+ public object Get(object key)
+ {
+ return null;
+ }
+
+ public void Put(object key, object value)
+ {
+ }
+
+ public void Remove(object key)
+ {
+ }
+
+ public void Clear()
+ {
+ }
+
+ public void Destroy()
+ {
+ }
+
+ public void Lock(object key)
+ {
+ }
+
+ public void Unlock(object key)
+ {
+ }
+
+ public long NextTimestamp()
+ {
+ return Timestamper.Next();
+ }
+
+ public int Timeout { get; private set; }
+ public string RegionName { get; private set; }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/Cache/NoCacheProvider.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cache/NoCacheProvider.cs 2009-05-17 05:37:33 UTC (rev 4332)
+++ trunk/nhibernate/src/NHibernate/Cache/NoCacheProvider.cs 2009-05-17 16:35:57 UTC (rev 4333)
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using log4net;
namespace NHibernate.Cache
{
@@ -8,6 +9,10 @@
/// </summary>
public class NoCacheProvider : ICacheProvider
{
+ private static readonly ILog log = LogManager.GetLogger(typeof(NoCacheProvider));
+
+ public const string WarnMessage = "Second-level cache is enabled in a class, but no cache provider was selected. Fake cache used.";
+
/// <summary>
/// Configure the cache
/// </summary>
@@ -16,7 +21,9 @@
/// <exception cref="CacheException" />
public ICache BuildCache(string regionName, IDictionary<string, string> properties)
{
- throw new NoCachingEnabledException();
+ // NH different behavior because NH-1093
+ log.Warn(WarnMessage);
+ return new FakeCache(regionName);
}
/// <summary>
Deleted: trunk/nhibernate/src/NHibernate/Cache/NoCachingEnabledException.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Cache/NoCachingEnabledException.cs 2009-05-17 05:37:33 UTC (rev 4332)
+++ trunk/nhibernate/src/NHibernate/Cache/NoCachingEnabledException.cs 2009-05-17 16:35:57 UTC (rev 4333)
@@ -1,17 +0,0 @@
-using System;
-using Environment = NHibernate.Cfg.Environment;
-
-namespace NHibernate.Cache
-{
- [Serializable]
- public class NoCachingEnabledException : CacheException
- {
- private const string ExceptionMessage = "Second-level cache is enabled, but no cache provider was selected. " +
- "Please use " + Environment.CacheProvider + " to specify a cache provider such as SysCacheProvider";
-
- public NoCachingEnabledException()
- : base(ExceptionMessage)
- {
- }
- }
-}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-05-17 05:37:33 UTC (rev 4332)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-05-17 16:35:57 UTC (rev 4333)
@@ -454,6 +454,7 @@
<Compile Include="Bytecode\HibernateByteCodeException.cs" />
<Compile Include="Bytecode\ProxyFactoryFactoryNotConfiguredException.cs" />
<Compile Include="Bytecode\UnableToLoadProxyFactoryFactoryException.cs" />
+ <Compile Include="Cache\FakeCache.cs" />
<Compile Include="Cfg\MappingSchema\AbstractDecoratable.cs" />
<Compile Include="Cfg\MappingSchema\HbmTimestamp.cs" />
<Compile Include="Cfg\MappingSchema\HbmVersion.cs" />
@@ -641,7 +642,6 @@
<Compile Include="Cache\FilterKey.cs" />
<Compile Include="Cache\IOptimisticCacheSource.cs" />
<Compile Include="Cache\NoCacheProvider.cs" />
- <Compile Include="Cache\NoCachingEnabledException.cs" />
<Compile Include="Cfg\ClassExtractor.cs" />
<Compile Include="Cfg\ConfigurationSchema\CfgXmlHelper.cs" />
<Compile Include="Cfg\ConfigurationSchema\ClassCacheConfiguration.cs" />
Modified: trunk/nhibernate/src/NHibernate/Util/PropertiesHelper.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Util/PropertiesHelper.cs 2009-05-17 05:37:33 UTC (rev 4332)
+++ trunk/nhibernate/src/NHibernate/Util/PropertiesHelper.cs 2009-05-17 16:35:57 UTC (rev 4333)
@@ -41,6 +41,10 @@
{
string value;
properties.TryGetValue(property, out value);
+ if(value == string.Empty)
+ {
+ value = null;
+ }
return value ?? defaultValue;
}
Modified: trunk/nhibernate/src/NHibernate.Test/LogSpy.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/LogSpy.cs 2009-05-17 05:37:33 UTC (rev 4332)
+++ trunk/nhibernate/src/NHibernate.Test/LogSpy.cs 2009-05-17 16:35:57 UTC (rev 4333)
@@ -14,7 +14,7 @@
private readonly Logger logger;
private readonly Level prevLogLevel;
- public LogSpy(ILog log, bool disable)
+ public LogSpy(ILog log, Level level)
{
logger = log.Logger as Logger;
if (logger == null)
@@ -24,13 +24,18 @@
// Change the log level to DEBUG and temporarily save the previous log level
prevLogLevel = logger.Level;
- logger.Level = disable ? Level.Off : Level.Debug;
+ logger.Level = level;
// Add a new MemoryAppender to the logger.
appender = new MemoryAppender();
logger.AddAppender(appender);
}
+ public LogSpy(ILog log, bool disable)
+ : this(log, disable ? Level.Off : Level.Debug)
+ {
+ }
+
public LogSpy(ILog log) : this(log, false) { }
public LogSpy(System.Type loggerType) : this(LogManager.GetLogger(loggerType), false) { }
public LogSpy(System.Type loggerType, bool disable) : this(LogManager.GetLogger(loggerType), disable) { }
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1093/Fixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1093/Fixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1093/Fixture.cs 2009-05-17 16:35:57 UTC (rev 4333)
@@ -0,0 +1,93 @@
+using log4net;
+using NHibernate.Cfg;
+using NUnit.Framework;
+using log4net.Core;
+
+namespace NHibernate.Test.NHSpecificTest.NH1093
+{
+ [TestFixture]
+ public class Fixture : BugTestCase
+ {
+ protected override void Configure(Configuration configuration)
+ {
+ configuration.SetProperty(Environment.CacheProvider, string.Empty);
+ configuration.SetProperty(Environment.UseQueryCache, "true");
+ configuration.SetProperty(Environment.UseSecondLevelCache, "true");
+ }
+
+ protected override string CacheConcurrencyStrategy
+ {
+ get { return null; }
+ }
+
+ private void Cleanup()
+ {
+ using (ISession s = sessions.OpenSession())
+ {
+ using (s.BeginTransaction())
+ {
+ s.CreateQuery("delete from SimpleCached").ExecuteUpdate();
+ s.Transaction.Commit();
+ }
+ }
+ }
+
+ private void FillDb()
+ {
+ using (ISession s = sessions.OpenSession())
+ {
+ using (ITransaction tx = s.BeginTransaction())
+ {
+ s.Save(new SimpleCached {Description = "Simple 1"});
+ s.Save(new SimpleCached {Description = "Simple 2"});
+ tx.Commit();
+ }
+ }
+ }
+
+ [Test]
+ [Description("Without configured cache, shouldn't throw exception")]
+ public void NoException()
+ {
+ FillDb();
+ NormalList();
+ CriteriaQueryCache();
+ HqlQueryCache();
+ Cleanup();
+ }
+
+ private void HqlQueryCache()
+ {
+ using (ISession s = OpenSession())
+ {
+ s.CreateQuery("from SimpleCached").SetCacheable(true).List<SimpleCached>();
+ }
+ }
+
+ private void CriteriaQueryCache()
+ {
+ using (ISession s = OpenSession())
+ {
+ s.CreateCriteria<SimpleCached>().SetCacheable(true).List<SimpleCached>();
+ }
+ }
+
+ private void NormalList()
+ {
+ using (ISession s = OpenSession())
+ {
+ s.CreateCriteria<SimpleCached>().List<SimpleCached>();
+ }
+ }
+
+ protected override void BuildSessionFactory()
+ {
+ // Without configured cache, should log warn.
+ using (var ls = new LogSpy(LogManager.GetLogger("NHibernate"), Level.Warn))
+ {
+ base.BuildSessionFactory();
+ Assert.That(ls.GetWholeLog(), Text.Contains("Fake cache used"));
+ }
+ }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1093/Mappings.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1093/Mappings.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1093/Mappings.hbm.xml 2009-05-17 16:35:57 UTC (rev 4333)
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ assembly="NHibernate.Test"
+ namespace="NHibernate.Test.NHSpecificTest.NH1093">
+
+ <class name="SimpleCached">
+ <cache region="something" usage="nonstrict-read-write"/>
+ <id name="Id">
+ <generator class="native"/>
+ </id>
+ <property name="Description"/>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1093/SimpleCached.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1093/SimpleCached.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH1093/SimpleCached.cs 2009-05-17 16:35:57 UTC (rev 4333)
@@ -0,0 +1,8 @@
+namespace NHibernate.Test.NHSpecificTest.NH1093
+{
+ public class SimpleCached
+ {
+ public virtual int Id { get; set; }
+ public virtual string Description { get; set; }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-05-17 05:37:33 UTC (rev 4332)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-05-17 16:35:57 UTC (rev 4333)
@@ -334,6 +334,8 @@
<Compile Include="NHSpecificTest\ElementsEnums\IntEnumsBagPartialNameFixture.cs" />
<Compile Include="NHSpecificTest\ElementsEnums\IntEnumsBagFixture.cs" />
<Compile Include="NHSpecificTest\ElementsEnums\Something.cs" />
+ <Compile Include="NHSpecificTest\NH1093\Fixture.cs" />
+ <Compile Include="NHSpecificTest\NH1093\SimpleCached.cs" />
<Compile Include="NHSpecificTest\NH1264\Fixture.cs" />
<Compile Include="NHSpecificTest\NH1264\Name.cs" />
<Compile Include="NHSpecificTest\NH1264\Passenger.cs" />
@@ -1804,6 +1806,7 @@
<EmbeddedResource Include="BulkManipulation\SimpleClass.hbm.xml" />
<EmbeddedResource Include="Ado\VerySimple.hbm.xml" />
<Content Include="DynamicEntity\package.html" />
+ <EmbeddedResource Include="NHSpecificTest\NH1093\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1714\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1763\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\ElementsEnums\SimpleWithEnumsNoName.hbm.xml" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|