You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ibatis.apache.org by gb...@apache.org on 2008/06/19 20:38:39 UTC
svn commit: r669636 [1/2] - in /ibatis/trunk/cs/V3/src:
Apache.Ibatis.Common/Configuration/
Apache.Ibatis.Common/Utilities/TypesResolver/
Apache.Ibatis.DataMapper.SqlClient.Test.2005/
Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/ Apache.Ibatis...
Author: gbayon
Date: Thu Jun 19 11:38:37 2008
New Revision: 669636
URL: http://svn.apache.org/viewvc?rev=669636&view=rev
Log:
IBATISNET-273, cache support refactoring
Added:
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/BaseCacheTest.cs (with props)
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/CacheKeyTest.cs (with props)
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/CacheModelTest.cs
- copied, changed from r666256, ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/CacheController/CacheModelTest.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/FifoCacheTest.cs (with props)
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/LruCacheTest.cs (with props)
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/PerpetualCacheTest.cs (with props)
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/ScheduledCacheTest.cs (with props)
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/WeakCacheTest.cs (with props)
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/BaseCache.cs (with props)
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/Decorators/
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/Decorators/LoggingCache.cs (with props)
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/Decorators/NullValueDecorator.cs (with props)
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/Decorators/ScheduledCache.cs (with props)
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/Decorators/SharedCache.cs (with props)
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/Decorators/SynchronizedCache.cs (with props)
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/ICache.cs
- copied, changed from r666256, ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/ICacheController.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/Implementation/
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/Implementation/FifoCache.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/Implementation/LruCache.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/Implementation/PerpetualCache.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/Implementation/WeakCache.cs (with props)
Removed:
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/CacheController/
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/CacheKeyTest.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/Fifo/
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/FlushInterval.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/ICacheController.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/Lru/
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/Memory/
Modified:
ibatis/trunk/cs/V3/src/Apache.Ibatis.Common/Configuration/ConfigurationUtils.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.Common/Utilities/TypesResolver/TypeRegistry.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Apache.Ibatis.DataMapper.SqlClient.Test.2005.csproj
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/ConfigureTest.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/CacheTest.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/StatementTest.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Account.xml
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Mapping1.xml
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Apache.Ibatis.DataMapper.20005.csproj
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/DefaultModelBuilder.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/Interpreters/Config/ConfigConstants.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/Interpreters/Config/Xml/Processor/Handlers/ProcessCacheModelElement.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/ModelBuilder/BuildCacheModel.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/Serializers/CacheModelDeSerializer.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/MappedStatements/CachingStatement.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/CacheKey.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/CacheModel.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/DefaultModelStore.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/IModelStore.cs
ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/SqlMap.xsd
Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.Common/Configuration/ConfigurationUtils.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.Common/Configuration/ConfigurationUtils.cs?rev=669636&r1=669635&r2=669636&view=diff
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.Common/Configuration/ConfigurationUtils.cs (original)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.Common/Configuration/ConfigurationUtils.cs Thu Jun 19 11:38:37 2008
@@ -140,6 +140,27 @@
}
/// <summary>
+ /// Gets the long value of the attribute with the specified name.
+ /// </summary>
+ /// <param name="attributes">The attributes.</param>
+ /// <param name="name">The name.</param>
+ /// <param name="def">The default value to be returned if the attribute is not found.</param>
+ /// <returns>If the attribute exists its value otherwise the default value</returns>
+ public static long GetLongAttribute(IDictionary<string, string> attributes, string name, long def)
+ {
+ string value = null;
+ attributes.TryGetValue(name, out value);
+ if (value == null)
+ {
+ return def;
+ }
+ else
+ {
+ return XmlConvert.ToInt64(value);
+ }
+ }
+
+ /// <summary>
/// Gets the bool value of the attribute with the specified name.
/// </summary>
/// <param name="attributes">The list of attributes</param>
Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.Common/Utilities/TypesResolver/TypeRegistry.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.Common/Utilities/TypesResolver/TypeRegistry.cs?rev=669636&r1=669635&r2=669636&view=diff
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.Common/Utilities/TypesResolver/TypeRegistry.cs (original)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.Common/Utilities/TypesResolver/TypeRegistry.cs Thu Jun 19 11:38:37 2008
@@ -28,7 +28,6 @@
using System;
using System.Collections;
-using System.Collections.Specialized;
using System.Collections.Generic;
using System.Data;
Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Apache.Ibatis.DataMapper.SqlClient.Test.2005.csproj
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Apache.Ibatis.DataMapper.SqlClient.Test.2005.csproj?rev=669636&r1=669635&r2=669636&view=diff
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Apache.Ibatis.DataMapper.SqlClient.Test.2005.csproj (original)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Apache.Ibatis.DataMapper.SqlClient.Test.2005.csproj Thu Jun 19 11:38:37 2008
@@ -49,6 +49,13 @@
<Compile Include="Domain\SimpleSqlSource.cs" />
<Compile Include="Domain\SqlSourceWithInlineParameter.cs" />
<Compile Include="Domain\SqlSourceWithParameter.cs" />
+ <Compile Include="Fixtures\Mapping\Cache\BaseCacheTest.cs" />
+ <Compile Include="Fixtures\Mapping\Cache\CacheKeyTest.cs" />
+ <Compile Include="Fixtures\Mapping\Cache\FifoCacheTest.cs" />
+ <Compile Include="Fixtures\Mapping\Cache\LruCacheTest.cs" />
+ <Compile Include="Fixtures\Mapping\Cache\PerpetualCacheTest.cs" />
+ <Compile Include="Fixtures\Mapping\Cache\ScheduledCacheTest.cs" />
+ <Compile Include="Fixtures\Mapping\Cache\WeakCacheTest.cs" />
<Compile Include="Fixtures\Mapping\CircularReferenceTest.cs" />
<Compile Include="Fixtures\Mapping\EventTest.cs" />
<Compile Include="Fixtures\Mapping\VelocityTest.cs" />
@@ -106,11 +113,7 @@
<Compile Include="Fixtures\ConfigureTest.cs" />
<Compile Include="Fixtures\DefaultConfigurationEngineTest.cs" />
<Compile Include="Fixtures\DefaultModelBuilderTest.cs" />
- <Compile Include="Fixtures\Mapping\CacheController\CacheModelTest.cs" />
- <Compile Include="Fixtures\Mapping\CacheController\FifoCacheControllerTest.cs" />
- <Compile Include="Fixtures\Mapping\CacheController\LruCacheControllerTest.cs" />
- <Compile Include="Fixtures\Mapping\CacheController\MemoryCacheControllerTest.cs" />
- <Compile Include="Fixtures\Mapping\CacheKeyTest.cs" />
+ <Compile Include="Fixtures\Mapping\Cache\CacheModelTest.cs" />
<Compile Include="Fixtures\Mapping\CacheTest.cs" />
<Compile Include="Fixtures\Mapping\ComplexTypeTest.cs" />
<Compile Include="Fixtures\Mapping\ConstructorTest.cs" />
Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/ConfigureTest.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/ConfigureTest.cs?rev=669636&r1=669635&r2=669636&view=diff
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/ConfigureTest.cs (original)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/ConfigureTest.cs Thu Jun 19 11:38:37 2008
@@ -205,7 +205,7 @@
// Cache model
Assert.That(store.CacheModels.Length, Is.EqualTo(2));
IConfiguration cacheModel = store.CacheModels[0];
- Assert.That(cacheModel.Children.Count, Is.EqualTo(4));
+ Assert.That(cacheModel.Children.Count, Is.EqualTo(2));
Assert.That(cacheModel.Attributes.ContainsKey(ConfigConstants.ATTRIBUTE_NAMESPACE), Is.True);
// Result map
Added: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/BaseCacheTest.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/BaseCacheTest.cs?rev=669636&view=auto
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/BaseCacheTest.cs (added)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/BaseCacheTest.cs Thu Jun 19 11:38:37 2008
@@ -0,0 +1,25 @@
+
+using Apache.Ibatis.DataMapper.Model.Cache.Decorators;
+using Apache.Ibatis.DataMapper.Model.Cache.Implementation;
+using NUnit.Framework;
+using NUnit.Framework.SyntaxHelpers;
+
+namespace Apache.Ibatis.DataMapper.SqlClient.Test.Fixtures.Mapping.Cache
+{
+ [TestFixture]
+ public class BaseCacheTest
+ {
+ [Test]
+ public void Equals_and_hashCode_on_decorated_cache_should_be_equal()
+ {
+ PerpetualCache cache = new PerpetualCache();
+ cache.Id = "test_cache";
+
+ Assert.That(cache, Is.EqualTo(cache));
+ Assert.That(cache.Equals( new SynchronizedCache(cache) ), Is.True );
+ Assert.That(cache.Equals( new SharedCache(cache) ), Is.True );
+ Assert.That(cache.Equals( new LoggingCache(cache) ), Is.True );
+ Assert.That(cache.Equals( new ScheduledCache(cache, long.MinValue) ), Is.True );
+ }
+ }
+}
Propchange: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/BaseCacheTest.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/BaseCacheTest.cs
------------------------------------------------------------------------------
svn:keywords = Id LastChangedDate LastChangedBy
Added: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/CacheKeyTest.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/CacheKeyTest.cs?rev=669636&view=auto
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/CacheKeyTest.cs (added)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/CacheKeyTest.cs Thu Jun 19 11:38:37 2008
@@ -0,0 +1,135 @@
+
+using System;
+using System.Collections.Generic;
+using Apache.Ibatis.DataMapper.Model.Cache;
+using Apache.Ibatis.DataMapper.Model.Cache.Implementation;
+using NUnit.Framework;
+using NUnit.Framework.SyntaxHelpers;
+
+namespace Apache.Ibatis.DataMapper.SqlClient.Test.Fixtures.Mapping.Cache
+{
+ [TestFixture]
+ public class CacheKeyTest
+ {
+ [Test]
+ public void CacheKeys_should_be_equal()
+ {
+ DateTime date = DateTime.Now;
+ CacheKey key1 = new CacheKey(new Object[] { 1, "hello", null, new DateTime(date.Ticks) });
+ CacheKey key2 = new CacheKey(new Object[] { 1, "hello", null, new DateTime(date.Ticks) });
+
+ Assert.That(key1, Is.EqualTo(key2));
+ Assert.That(key2, Is.EqualTo(key1));
+ Assert.That(key2.GetHashCode(), Is.EqualTo(key1.GetHashCode()));
+ Assert.That(key1.GetHashCode(), Is.EqualTo(key2.GetHashCode()));
+ Assert.That(key1.ToString(), Is.EqualTo(key2.ToString()));
+ }
+
+ [Test]
+ public void CacheKeys_should_not_be_equal()
+ {
+ DateTime date = DateTime.Now;
+ CacheKey key1 = new CacheKey(new Object[] { 1, "hello", null, new DateTime(date.Ticks) });
+ CacheKey key2 = new CacheKey(new Object[] { 1, "hello", null, new DateTime(date.Ticks+5) });
+
+ Assert.That(key1, Is.Not.EqualTo(key2));
+ Assert.That(key2, Is.Not.EqualTo(key1));
+ Assert.That(key1.GetHashCode(), Is.Not.EqualTo(key2.GetHashCode()));
+ Assert.That(key1.ToString(), Is.Not.EqualTo(key2.ToString()));
+ }
+
+ [Test]
+ public void CacheKeys_should_not_be_equal_due_to_order()
+ {
+ CacheKey key1 = new CacheKey(new Object[] { 1, "hello", null });
+ CacheKey key2 = new CacheKey(new Object[] { 1, null, "hello" });
+
+ Assert.That(key1, Is.Not.EqualTo(key2));
+ Assert.That(key2, Is.Not.EqualTo(key1));
+ Assert.That(key1.GetHashCode(), Is.Not.EqualTo(key2.GetHashCode()));
+ Assert.That(key1.ToString(), Is.Not.EqualTo(key2.ToString()));
+ }
+
+ [Test]
+ public void CacheKeys_empty_and_null_should_be_equal()
+ {
+ CacheKey key1 = new CacheKey();
+ CacheKey key2 = new CacheKey();
+
+ Assert.That(key1, Is.EqualTo(key2));
+ Assert.That(key2, Is.EqualTo(key1));
+
+ key1.Update(null);
+ key2.Update(null);
+
+ Assert.That(key1, Is.EqualTo(key2));
+ Assert.That(key2, Is.EqualTo(key1));
+
+ key1.Update(null);
+ key2.Update(null);
+
+ Assert.That(key1, Is.EqualTo(key2));
+ Assert.That(key2, Is.EqualTo(key1));
+ }
+
+ [Test]
+ public void ShouldNotConsider1LAndNegative9223372034707292159LToBeEqual()
+ {
+ // old version of ObjectProbe gave TestClass based on these longs the same HashCode
+ DoTestClassEquals(1L, -9223372034707292159L);
+ }
+
+ [Test]
+ public void Should_not_consider_1L_and_negative_9223372036524971138L_to_be_equal()
+ {
+ // current version of ObjectProbe gives TestClass based on these longs the same HashCode
+ DoTestClassEquals(1L, -9223372036524971138L);
+ }
+
+ private static void DoTestClassEquals(long firstLong, long secondLong)
+ {
+ // Two cache keys are equal except for the parameter.
+ CacheKey key = new CacheKey();
+
+ key.Update(firstLong);
+
+ CacheKey aDifferentKey = new CacheKey();
+
+ key.Update(secondLong);
+
+ Assert.IsFalse(aDifferentKey.Equals(key)); // should not be equal.
+ }
+
+ [Test]
+ public void CacheKey_with_same_hashcode_shoul_be_equal()
+ {
+ CacheKey key1 = new CacheKey();
+ CacheKey key2 = new CacheKey();
+
+ key1.Update("HS1CS001");
+ key2.Update("HS1D4001");
+ /*
+ The string hash algorithm is not an industry standard and is not guaranteed to produce the same behaviour between versions.
+ And in fact it does not. The .NET 2.0 CLR uses a different algorithm for string hashing than the .NET 1.1 CLR.
+ */
+
+ Assert.Ignore("The .NET 2.0 CLR uses a different algorithm for string hashing than the .NET 1.1 CLR.");
+
+ }
+
+ [Test]
+ public void CacheKey_with_2_params_having_same_hashcode_shoul_not_be_equal()
+ {
+ CacheKey key1 = new CacheKey();
+ CacheKey key2 = new CacheKey();
+
+ key1.Update("HS1CS001");
+ key1.Update("HS1D4001");
+
+ key2.Update("HS1D4001");
+ key2.Update("HS1CS001");
+
+ Assert.Ignore("The .NET 2.0 CLR uses a different algorithm for string hashing than the .NET 1.1 CLR.");
+ }
+ }
+}
Propchange: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/CacheKeyTest.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/CacheKeyTest.cs
------------------------------------------------------------------------------
svn:keywords = Id LastChangedDate LastChangedBy
Copied: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/CacheModelTest.cs (from r666256, ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/CacheController/CacheModelTest.cs)
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/CacheModelTest.cs?p2=ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/CacheModelTest.cs&p1=ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/CacheController/CacheModelTest.cs&r1=666256&r2=669636&rev=669636&view=diff
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/CacheController/CacheModelTest.cs (original)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/CacheModelTest.cs Thu Jun 19 11:38:37 2008
@@ -1,15 +1,11 @@
using System;
-using System.Collections;
-using System.Collections.Specialized;
using Apache.Ibatis.Common.Utilities;
-
-using NUnit.Framework;
-
-using Apache.Ibatis.DataMapper.SqlClient.Test.Domain;
using Apache.Ibatis.DataMapper.Model.Cache;
-using Apache.Ibatis.DataMapper.Model.Cache.Lru;
+using Apache.Ibatis.DataMapper.Model.Cache.Implementation;
+using Apache.Ibatis.DataMapper.SqlClient.Test.Domain;
+using NUnit.Framework;
-namespace Apache.Ibatis.DataMapper.SqlClient.Test.Fixtures.Mapping.CacheController
+namespace Apache.Ibatis.DataMapper.SqlClient.Test.Fixtures.Mapping.Cache
{
/// <summary>
/// Summary description for CacheKeyTest.
@@ -23,15 +19,9 @@
/// </summary>
public void TestReturnInstanceOfCachedOject()
{
- IDictionary props = new HybridDictionary();
- props.Add("CacheSize", "1");
- //cacheController.Configure(props);
-
- FlushInterval interval = new FlushInterval(1,0,0,0);
-
- CacheModel cacheModel = new CacheModel("test", typeof(LruCacheController).FullName, props);
+ CacheModel cacheModel = new CacheModel("test", typeof(LruCache).FullName, 60, 1, false);
- cacheModel.FlushInterval = interval;
+ //cacheModel.FlushInterval = interval;
//cacheModel.IsReadOnly = true;
//cacheModel.IsSerializable = false;
@@ -63,17 +53,7 @@
/// </summary>
public void TestReturnCopyOfCachedOject()
{
- //ICacheController cacheController = new LruCacheController();
- IDictionary props = new HybridDictionary();
- props.Add("CacheSize", "1");
-
- FlushInterval interval = new FlushInterval(1,0,0,0);
-
- CacheModel cacheModel = new CacheModel("test", typeof(LruCacheController).FullName, props, false, true);
- cacheModel.FlushInterval = interval;
- //cacheModel.CacheController = cacheController;
- //cacheModel.IsReadOnly = false;
- //cacheModel.IsSerializable = true;
+ CacheModel cacheModel = new CacheModel("test", typeof(LruCache).FullName, 60, 1, true);
Order order = new Order();
order.CardNumber = "CardNumber";
Added: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/FifoCacheTest.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/FifoCacheTest.cs?rev=669636&view=auto
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/FifoCacheTest.cs (added)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/FifoCacheTest.cs Thu Jun 19 11:38:37 2008
@@ -0,0 +1,60 @@
+
+using Apache.Ibatis.DataMapper.Model.Cache;
+using Apache.Ibatis.DataMapper.Model.Cache.Implementation;
+using NUnit.Framework;
+using NUnit.Framework.SyntaxHelpers;
+
+namespace Apache.Ibatis.DataMapper.SqlClient.Test.Fixtures.Mapping.Cache
+{
+ [TestFixture]
+ public class FifoCacheTest
+ {
+ [Test]
+ public void First_item_should_be_removed()
+ {
+ FifoCache cache = new FifoCache();
+ cache.Size = 5;
+
+ for (int i = 0; i < 5; i++)
+ {
+ cache[i]= i;
+ }
+
+ Assert.That(cache[0], Is.EqualTo(0));
+ cache[5] = 5;
+ Assert.That(cache[0], Is.Null);
+ Assert.That(cache.Size, Is.EqualTo(5));
+ }
+
+ [Test]
+ public void Item_should_be_removed_on_demand()
+ {
+ ICache cache = new FifoCache();
+
+ cache[0] = 0;
+ Assert.That(cache[0], Is.Not.Null);
+
+ cache.Remove(0);
+ Assert.That(cache[0], Is.Null);
+ }
+
+ [Test]
+ public void Cache_should_be_clear_on_demand()
+ {
+ ICache cache = new FifoCache();
+
+ for (int i = 0; i < 5; i++)
+ {
+ cache[i] = i;
+ }
+
+ Assert.That(cache[0], Is.Not.Null);
+ Assert.That(cache[4], Is.Not.Null);
+ cache.Clear();
+ Assert.That(cache[0], Is.Null);
+ Assert.That(cache[4], Is.Null);
+ }
+
+
+ }
+}
Propchange: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/FifoCacheTest.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/FifoCacheTest.cs
------------------------------------------------------------------------------
svn:keywords = Id LastChangedDate LastChangedBy
Added: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/LruCacheTest.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/LruCacheTest.cs?rev=669636&view=auto
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/LruCacheTest.cs (added)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/LruCacheTest.cs Thu Jun 19 11:38:37 2008
@@ -0,0 +1,130 @@
+
+using Apache.Ibatis.DataMapper.Model.Cache;
+using Apache.Ibatis.DataMapper.Model.Cache.Implementation;
+using NUnit.Framework;
+using NUnit.Framework.SyntaxHelpers;
+
+namespace Apache.Ibatis.DataMapper.SqlClient.Test.Fixtures.Mapping.Cache
+{
+ [TestFixture]
+ public class LruCacheTest
+ {
+ [Test]
+ public void Least_recently_used_item_should_be_removed()
+ {
+ LruCache cache = new LruCache();
+ cache.Size = 5;
+
+ for (int i = 0; i < 5; i++)
+ {
+ cache[i] = i;
+ }
+
+ Assert.That(cache[0], Is.EqualTo(0));
+ cache[5] = 5;
+ Assert.That(cache[1], Is.Null);
+ Assert.That(cache.Size, Is.EqualTo(5));
+ }
+
+ [Test]
+ public void Item_should_be_removed_on_demand()
+ {
+ ICache cache = new LruCache();
+
+ cache[0] = 0;
+ Assert.That(cache[0], Is.Not.Null);
+
+ cache.Remove(0);
+ Assert.That(cache[0], Is.Null);
+ }
+
+ [Test]
+ public void Cache_should_be_clear_on_demand()
+ {
+ ICache cache = new LruCache();
+
+ for (int i = 0; i < 5; i++)
+ {
+ cache[i] = i;
+ }
+
+ Assert.That(cache[0], Is.Not.Null);
+ Assert.That(cache[4], Is.Not.Null);
+ cache.Clear();
+ Assert.That(cache[0], Is.Null);
+ Assert.That(cache[4], Is.Null);
+ }
+
+ protected virtual ICache GetCache()
+ {
+ return new LruCache();
+ }
+
+ [Test]
+ public void Cache_with_size_one_should_be_clear()
+ {
+ ICache cache = GetCache();
+ cache.Size = 1;
+
+ string testKey = "testKey";
+ string testVal = "testVal";
+ cache[testKey] = testVal;
+ Assert.AreEqual(testVal, cache[testKey]);
+
+ string testKey2 = "testKey2";
+ string testVal2 = "testVal2";
+ cache[testKey2] = testVal2;
+ Assert.AreEqual(testVal2, cache[testKey2]);
+
+ Assert.IsNull(cache[testKey]);
+ }
+
+ [Test]
+ public void Get_and_put_object_should_work()
+ {
+ ICache cache = GetCache();
+ string testKey = "testKey";
+ string testVal = "testVal";
+
+ Assert.AreEqual(cache[testKey], null);
+
+ cache[testKey] = testVal;
+ Assert.AreEqual(cache[testKey], testVal);
+
+ cache[testKey] = null;
+ Assert.AreEqual(cache[testKey], null);
+ }
+
+ [Test]
+ public void Remove_from_cache_object_should_work()
+ {
+ ICache cache = GetCache();
+ string testKey = "testKey";
+ string testVal = "testVal";
+
+ Assert.AreEqual(cache[testKey], null);
+
+ cache[testKey] = testVal;
+ Assert.AreEqual(cache[testKey], testVal);
+
+ cache.Remove(testKey);
+ Assert.AreEqual(cache[testKey], null);
+ }
+
+ [Test]
+ public void Clear_cache_should_work()
+ {
+ ICache cache = GetCache();
+ string testKey = "testKey";
+ string testVal = "testVal";
+
+ Assert.AreEqual(cache[testKey], null);
+
+ cache[testKey] = testVal;
+ Assert.AreEqual(cache[testKey], testVal);
+
+ cache.Clear();
+ Assert.AreEqual(cache[testKey], null);
+ }
+ }
+}
Propchange: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/LruCacheTest.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/LruCacheTest.cs
------------------------------------------------------------------------------
svn:keywords = Id LastChangedDate LastChangedBy
Added: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/PerpetualCacheTest.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/PerpetualCacheTest.cs?rev=669636&view=auto
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/PerpetualCacheTest.cs (added)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/PerpetualCacheTest.cs Thu Jun 19 11:38:37 2008
@@ -0,0 +1,73 @@
+using Apache.Ibatis.DataMapper.Model.Cache;
+using Apache.Ibatis.DataMapper.Model.Cache.Decorators;
+using Apache.Ibatis.DataMapper.Model.Cache.Implementation;
+using NUnit.Framework;
+using NUnit.Framework.SyntaxHelpers;
+
+namespace Apache.Ibatis.DataMapper.SqlClient.Test.Fixtures.Mapping.Cache
+{
+ [TestFixture]
+ public class PerpetualCacheTest
+ {
+ [Test]
+ [Category("Perpetual cache")]
+ public void Demonstrate_how_all_objects_are_kept()
+ {
+ ICache cache = new PerpetualCache();
+ cache = new SynchronizedCache(cache);
+
+ for (int i = 0; i < 100000; i++)
+ {
+ cache[i] = i;
+ Assert.That(cache[i], Is.EqualTo(i));
+ }
+
+ Assert.That(cache.Size, Is.EqualTo(100000));
+ }
+
+ [Test]
+ [Category("Perpetual cache")]
+ public void Demonstrate_that_copies_are_equals()
+ {
+ ICache cache = new PerpetualCache();
+ cache = new SharedCache(cache);
+
+ for (int i = 0; i < 100000; i++)
+ {
+ cache[i] = i;
+ Assert.That(cache[i], Is.EqualTo(i));
+ }
+ }
+
+ [Test]
+ public void Item_should_be_removed_on_demand()
+ {
+ ICache cache = new PerpetualCache();
+ cache = new SynchronizedCache(cache);
+
+ cache[0] = 0;
+ Assert.That(cache[0], Is.Not.Null);
+
+ cache.Remove(0);
+ Assert.That(cache[0], Is.Null);
+ }
+
+ [Test]
+ public void Cache_should_be_clear_on_demand()
+ {
+ ICache cache = new PerpetualCache();
+ cache = new SynchronizedCache(cache);
+
+ for (int i = 0; i < 5; i++)
+ {
+ cache[i] = i;
+ }
+
+ Assert.That(cache[0], Is.Not.Null);
+ Assert.That(cache[4], Is.Not.Null);
+ cache.Clear();
+ Assert.That(cache[0], Is.Null);
+ Assert.That(cache[4], Is.Null);
+ }
+ }
+}
Propchange: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/PerpetualCacheTest.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/PerpetualCacheTest.cs
------------------------------------------------------------------------------
svn:keywords = Id LastChangedDate LastChangedBy
Added: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/ScheduledCacheTest.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/ScheduledCacheTest.cs?rev=669636&view=auto
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/ScheduledCacheTest.cs (added)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/ScheduledCacheTest.cs Thu Jun 19 11:38:37 2008
@@ -0,0 +1,63 @@
+using System;
+using System.Threading;
+using Apache.Ibatis.DataMapper.Model.Cache;
+using Apache.Ibatis.DataMapper.Model.Cache.Decorators;
+using Apache.Ibatis.DataMapper.Model.Cache.Implementation;
+using NUnit.Framework;
+using NUnit.Framework.SyntaxHelpers;
+
+namespace Apache.Ibatis.DataMapper.SqlClient.Test.Fixtures.Mapping.Cache
+{
+ [TestFixture]
+ public class ScheduledCacheTest
+ {
+ [Test]
+ [Category("Scheduled cache")]
+ public void All_objects_should_be_flush_after_a_certain_time()
+ {
+ ICache cache = new PerpetualCache();
+ cache = new ScheduledCache(cache, 1);
+ cache = new LoggingCache(cache);
+ for (int i = 0; i < 100; i++)
+ {
+ cache[i] = i;
+ Assert.That(cache[i], Is.EqualTo(i));
+ }
+ Thread.Sleep(new TimeSpan(0,0,1,5));
+ Assert.That(cache.Size, Is.EqualTo(0));
+ }
+
+ [Test]
+ public void Item_should_be_removed_on_demand()
+ {
+ ICache cache = new PerpetualCache();
+ cache = new ScheduledCache(cache, 60000);
+ cache = new LoggingCache(cache);
+
+ cache[0] = 0;
+ Assert.That(cache[0], Is.Not.Null);
+
+ cache.Remove(0);
+ Assert.That(cache[0], Is.Null);
+ }
+
+ [Test]
+ public void Cache_should_be_clear_on_demand()
+ {
+ ICache cache = new PerpetualCache();
+ cache = new ScheduledCache(cache, 60000);
+ cache = new LoggingCache(cache);
+
+ for (int i = 0; i < 5; i++)
+ {
+ cache[i] = i;
+ }
+
+ Assert.That(cache[0], Is.Not.Null);
+ Assert.That(cache[4], Is.Not.Null);
+ cache.Clear();
+ Assert.That(cache[0], Is.Null);
+ Assert.That(cache[4], Is.Null);
+ }
+ }
+}
Propchange: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/ScheduledCacheTest.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/ScheduledCacheTest.cs
------------------------------------------------------------------------------
svn:keywords = Id LastChangedDate LastChangedBy
Added: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/WeakCacheTest.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/WeakCacheTest.cs?rev=669636&view=auto
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/WeakCacheTest.cs (added)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/WeakCacheTest.cs Thu Jun 19 11:38:37 2008
@@ -0,0 +1,72 @@
+using System;
+using System.Collections.Generic;
+using Apache.Ibatis.DataMapper.Model.Cache;
+using Apache.Ibatis.DataMapper.Model.Cache.Decorators;
+using Apache.Ibatis.DataMapper.Model.Cache.Implementation;
+using NUnit.Framework;
+using NUnit.Framework.SyntaxHelpers;
+
+namespace Apache.Ibatis.DataMapper.SqlClient.Test.Fixtures.Mapping.Cache
+{
+ [TestFixture]
+ public class WeakCacheTest
+ {
+
+ [Test]
+ public void Least_recently_used_item_should_be_removed()
+ {
+ WeakCache cache = new WeakCache();
+ for (int i = 0; i < 1000000; i++)
+ {
+ cache[i] = i;
+ }
+ GC.Collect();
+ object o = cache[0];
+
+ Assert.That(cache.Size, Is.EqualTo(999999));
+ }
+
+ [Test]
+ public void Demonstrate_that_copies_are_equals()
+ {
+ ICache cache = new WeakCache();
+ cache = new SharedCache(cache);
+
+ for (int i = 0; i < 100000; i++)
+ {
+ cache[i] = i;
+ object value = cache[i];
+ Assert.That(value, Is.Null | Is.EqualTo(i));
+ }
+ }
+
+ [Test]
+ public void Item_should_be_removed_on_demand()
+ {
+ ICache cache = new WeakCache();
+
+ cache[0] = 0;
+ Assert.That(cache[0], Is.Not.Null);
+
+ cache.Remove(0);
+ Assert.That(cache[0], Is.Null);
+ }
+
+ [Test]
+ public void Cache_should_be_clear_on_demand()
+ {
+ ICache cache = new WeakCache();
+
+ for (int i = 0; i < 5; i++)
+ {
+ cache[i] = i;
+ }
+
+ Assert.That(cache[0], Is.Not.Null);
+ Assert.That(cache[4], Is.Not.Null);
+ cache.Clear();
+ Assert.That(cache[0], Is.Null);
+ Assert.That(cache[4], Is.Null);
+ }
+ }
+}
Propchange: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/WeakCacheTest.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/Cache/WeakCacheTest.cs
------------------------------------------------------------------------------
svn:keywords = Id LastChangedDate LastChangedBy
Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/CacheTest.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/CacheTest.cs?rev=669636&r1=669635&r2=669636&view=diff
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/CacheTest.cs (original)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/CacheTest.cs Thu Jun 19 11:38:37 2008
@@ -5,11 +5,12 @@
using Apache.Ibatis.Common.Utilities;
using Apache.Ibatis.DataMapper.MappedStatements;
+using Apache.Ibatis.DataMapper.Model.Cache.Decorators;
+using Apache.Ibatis.DataMapper.Model.Cache.Implementation;
using Apache.Ibatis.DataMapper.SqlClient.Test.Domain;
using Apache.Ibatis.DataMapper.SqlClient.Test.Fixtures;
using NUnit.Framework;
using Apache.Ibatis.DataMapper.Model.Cache;
-using Apache.Ibatis.DataMapper.Model.Cache.Lru;
using Apache.Ibatis.DataMapper.Session;
namespace Apache.Ibatis.DataMapper.SqlClient.Test.Fixtures.Mapping
@@ -288,7 +289,6 @@
object returnedObject = cache[key];
Assert.AreEqual(CacheModel.NULL_OBJECT, returnedObject);
Assert.AreEqual(HashCodeProvider.GetIdentityHashCode(CacheModel.NULL_OBJECT), HashCodeProvider.GetIdentityHashCode(returnedObject));
- Assert.AreEqual(1, cache.HitRatio);
}
@@ -299,6 +299,7 @@
public void TestCacheHit()
{
CacheModel cache = GetCacheModel();
+
CacheKey key = new CacheKey();
key.Update("testKey");
@@ -308,7 +309,6 @@
object returnedObject = cache[key];
Assert.AreEqual(value, returnedObject);
Assert.AreEqual(HashCodeProvider.GetIdentityHashCode(value), HashCodeProvider.GetIdentityHashCode(returnedObject));
- Assert.AreEqual(1, cache.HitRatio);
}
/// <summary>
@@ -318,6 +318,7 @@
public void TestCacheMiss()
{
CacheModel cache = GetCacheModel();
+
CacheKey key = new CacheKey();
key.Update("testKey");
@@ -330,7 +331,7 @@
object returnedObject = cache[wrongKey];
Assert.IsTrue(!value.Equals(returnedObject));
Assert.IsNull(returnedObject) ;
- Assert.AreEqual(0, cache.HitRatio);
+ //Assert.AreEqual(0, cache.HitRatio);
}
/// <summary>
@@ -340,6 +341,7 @@
public void TestCacheHitMiss()
{
CacheModel cache = GetCacheModel();
+
CacheKey key = new CacheKey();
key.Update("testKey");
@@ -356,7 +358,7 @@
returnedObject = cache[wrongKey];
Assert.IsTrue(!value.Equals(returnedObject));
Assert.IsNull(returnedObject) ;
- Assert.AreEqual(0.5, cache.HitRatio);
+ //Assert.AreEqual(0.5, cache.HitRatio);
}
@@ -368,6 +370,7 @@
public void TestDuplicateAddCache()
{
CacheModel cache = GetCacheModel();
+
CacheKey key = new CacheKey();
key.Update("testKey");
string value = "testValue";
@@ -388,8 +391,8 @@
private CacheModel GetCacheModel()
{
- CacheModel cache = new CacheModel("test", typeof(LruCacheController).FullName, new Hashtable());
- cache.FlushInterval = new FlushInterval(0, 5, 0, 0);
+ CacheModel cache = new CacheModel("test", typeof(PerpetualCache).FullName, long.MinValue, 0, false);
+ //cache.FlushInterval = new FlushInterval(0, 5, 0, 0);
return cache;
}
Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/StatementTest.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/StatementTest.cs?rev=669636&r1=669635&r2=669636&view=diff
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/StatementTest.cs (original)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Fixtures/Mapping/StatementTest.cs Thu Jun 19 11:38:37 2008
@@ -1252,6 +1252,7 @@
[Test]
[Category("JIRA")]
[Description("JIRA113")]
+ [Ignore]
public void Cache_stats_should_only_be_calculated_on_CachingStatments()
{
IModelStore modelStore = ((IModelStoreAccessor)dataMapper).ModelStore;
@@ -1267,9 +1268,9 @@
Assert.AreEqual(firstId, secondId);
- string cacheStats = modelStore.GetDataCacheStats();
+ //string cacheStats = modelStore.GetDataCacheStats();
- Assert.IsNotNull(cacheStats);
+ //Assert.IsNotNull(cacheStats);
}
#endregion
Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Account.xml
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Account.xml?rev=669636&r1=669635&r2=669636&view=diff
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Account.xml (original)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Account.xml Thu Jun 19 11:38:37 2008
@@ -10,23 +10,16 @@
</alias>
<cacheModels>
- <cacheModel id="account-cache" implementation="MEMORY" >
- <flushInterval hours="24"/>
- <flushOnExecute statement="UpdateAccountViaInlineParameters"/>
- <flushOnExecute statement="UpdateAccountViaParameterMap"/>
- <property name="Type" value="Weak"/>
- </cacheModel>
-
- <cacheModel id="rw-account-cache" implementation="FIFO" serialize="true" readOnly="false">
- <flushInterval hours="24"/>
- <flushOnExecute statement="UpdateAccountViaInlineParameters"/>
- </cacheModel>
-
- <cacheModel id="lru-account-cache" implementation="LRU" >
- <flushInterval minutes="5"/>
- <property name="CacheSize" value="2"/>
- </cacheModel>
-
+ <cacheModel id="account-cache" type="Perpetual" flushInterval="30" >
+ <flushOnExecute statement="UpdateAccountViaInlineParameters"/>
+ <flushOnExecute statement="UpdateAccountViaParameterMap"/>
+ </cacheModel>
+
+ <cacheModel id="rw-account-cache" type="Fifo" flushInterval="600" share="true">
+ <flushOnExecute statement="UpdateAccountViaInlineParameters"/>
+ </cacheModel>
+
+ <cacheModel id="lru-account-cache" type="Lru" flushInterval="5" size="2" />
</cacheModels>
<resultMaps>
Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Mapping1.xml
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Mapping1.xml?rev=669636&r1=669635&r2=669636&view=diff
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Mapping1.xml (original)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper.SqlClient.Test.2005/Maps/Mapping1.xml Thu Jun 19 11:38:37 2008
@@ -9,15 +9,12 @@
</alias>
<cacheModels>
- <cacheModel id="account-cache" implementation="MEMORY" >
- <flushInterval hours="24"/>
+ <cacheModel id="account-cache" type="Perpetual" flushInterval="30" >
<flushOnExecute statement="UpdateAccountViaInlineParameters"/>
<flushOnExecute statement="UpdateAccountViaParameterMap"/>
- <property name="Type" value="Weak"/>
</cacheModel>
- <cacheModel id="rw-account-cache" implementation="FIFO" serialize="true" readOnly="false">
- <flushInterval hours="24"/>
+ <cacheModel id="rw-account-cache" type="Fifo" flushInterval="600" share="true">
<flushOnExecute statement="UpdateAccountViaInlineParameters"/>
</cacheModel>
Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Apache.Ibatis.DataMapper.20005.csproj
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Apache.Ibatis.DataMapper.20005.csproj?rev=669636&r1=669635&r2=669636&view=diff
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Apache.Ibatis.DataMapper.20005.csproj (original)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Apache.Ibatis.DataMapper.20005.csproj Thu Jun 19 11:38:37 2008
@@ -121,6 +121,13 @@
<Compile Include="Configuration\Module\TypeAliasModuleBuilder.cs" />
<Compile Include="Configuration\Module\TypeHandlerModuleBuilder.cs" />
<Compile Include="MappedStatements\ResultStrategy\DataRowStrategy.cs" />
+ <Compile Include="Model\Cache\BaseCache.cs" />
+ <Compile Include="Model\Cache\Decorators\LoggingCache.cs" />
+ <Compile Include="Model\Cache\Decorators\NullValueDecorator.cs" />
+ <Compile Include="Model\Cache\Decorators\ScheduledCache.cs" />
+ <Compile Include="Model\Cache\Decorators\SharedCache.cs" />
+ <Compile Include="Model\Cache\Decorators\SynchronizedCache.cs" />
+ <Compile Include="Model\Cache\Implementation\WeakCache.cs" />
<Compile Include="Session\DataMapperLocalSessionScope.cs" />
<Compile Include="IMapperFactory.cs" />
<Compile Include="Configuration\Interpreters\Config\AbstractInterpreter.cs" />
@@ -411,12 +418,10 @@
<Compile Include="Model\Alias\TypeHandler.cs" />
<Compile Include="Model\Cache\CacheKey.cs" />
<Compile Include="Model\Cache\CacheModel.cs" />
- <Compile Include="Model\Cache\Fifo\FifoCacheController.cs" />
- <Compile Include="Model\Cache\FlushInterval.cs" />
- <Compile Include="Model\Cache\ICacheController.cs" />
- <Compile Include="Model\Cache\Lru\LruCacheController.cs" />
- <Compile Include="Model\Cache\Memory\MemoryCacheControler.cs" />
- <Compile Include="Model\Cache\Memory\MemoryCacheLevel.cs" />
+ <Compile Include="Model\Cache\Implementation\FifoCache.cs" />
+ <Compile Include="Model\Cache\ICache.cs" />
+ <Compile Include="Model\Cache\Implementation\LruCache.cs" />
+ <Compile Include="Model\Cache\Implementation\PerpetualCache.cs" />
<Compile Include="Model\DefaultModelStore.cs" />
<Compile Include="Model\IModelBuilder.cs" />
<Compile Include="Model\IModelStore.cs" />
Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/DefaultModelBuilder.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/DefaultModelBuilder.cs?rev=669636&r1=669635&r2=669636&view=diff
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/DefaultModelBuilder.cs (original)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/DefaultModelBuilder.cs Thu Jun 19 11:38:37 2008
@@ -31,11 +31,9 @@
using Apache.Ibatis.Common.Utilities.Objects;
using Apache.Ibatis.Common.Utilities.Objects.Members;
using Apache.Ibatis.DataMapper.Model.Alias;
-using Apache.Ibatis.DataMapper.Model.Cache.Fifo;
-using Apache.Ibatis.DataMapper.Model.Cache.Lru;
-using Apache.Ibatis.DataMapper.Model.Cache.Memory;
using Apache.Ibatis.DataMapper.DataExchange;
using Apache.Ibatis.DataMapper.Model;
+using Apache.Ibatis.DataMapper.Model.Cache.Implementation;
using Apache.Ibatis.DataMapper.Session.Transaction;
using Apache.Ibatis.DataMapper.TypeHandlers;
using Apache.Ibatis.DataMapper.Configuration.Interpreters.Config;
@@ -143,13 +141,24 @@
AccessorFactory accessorFactory = new AccessorFactory(setAccessorFactory, getAccessorFactory);
TypeHandlerFactory typeHandlerFactory = new TypeHandlerFactory();
- TypeAlias alias = new TypeAlias("MEMORY", typeof(MemoryCacheControler));
+ TypeAlias alias = new TypeAlias("MEMORY", typeof(PerpetualCache));
+ typeHandlerFactory.AddTypeAlias(alias.Id, alias);
+ alias = new TypeAlias("Perpetual", typeof(PerpetualCache));
+ typeHandlerFactory.AddTypeAlias(alias.Id, alias);
+
+ alias = new TypeAlias("LRU", typeof(LruCache));
+ typeHandlerFactory.AddTypeAlias(alias.Id, alias);
+ alias = new TypeAlias("Lru", typeof(LruCache));
typeHandlerFactory.AddTypeAlias(alias.Id, alias);
- alias = new TypeAlias("LRU", typeof(LruCacheController));
+ alias = new TypeAlias("FIFO", typeof(FifoCache));
+ typeHandlerFactory.AddTypeAlias(alias.Id, alias);
+ alias = new TypeAlias("Fifo", typeof(FifoCache));
typeHandlerFactory.AddTypeAlias(alias.Id, alias);
- alias = new TypeAlias("FIFO", typeof(FifoCacheController));
+ alias = new TypeAlias("Weak", typeof(WeakCache));
+ typeHandlerFactory.AddTypeAlias(alias.Id, alias);
+ alias = new TypeAlias("WEAK", typeof(WeakCache));
typeHandlerFactory.AddTypeAlias(alias.Id, alias);
alias = new TypeAlias("AnsiStringTypeHandler", typeof(AnsiStringTypeHandler));
Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/Interpreters/Config/ConfigConstants.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/Interpreters/Config/ConfigConstants.cs?rev=669636&r1=669635&r2=669636&view=diff
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/Interpreters/Config/ConfigConstants.cs (original)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/Interpreters/Config/ConfigConstants.cs Thu Jun 19 11:38:37 2008
@@ -255,7 +255,14 @@
/// Token for attribute validateSqlMap.
/// </summary>
public const string ATTRIBUTE_VALIDATE_SQLMAP = "validateSqlMap";
-
+ /// <summary>
+ /// Token for attribute flushInterval.
+ /// </summary>
+ public const string ATTRIBUTE_FLUSHINTERVAL = "flushInterval";
+ /// <summary>
+ /// Token for attribute share.
+ /// </summary>
+ public const string ATTRIBUTE_SHARE = "share";
#endregion
#region Token element
Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/Interpreters/Config/Xml/Processor/Handlers/ProcessCacheModelElement.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/Interpreters/Config/Xml/Processor/Handlers/ProcessCacheModelElement.cs?rev=669636&r1=669635&r2=669636&view=diff
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/Interpreters/Config/Xml/Processor/Handlers/ProcessCacheModelElement.cs (original)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/Interpreters/Config/Xml/Processor/Handlers/ProcessCacheModelElement.cs Thu Jun 19 11:38:37 2008
@@ -39,7 +39,7 @@
MutableConfiguration config = new MutableConfiguration(
element.Name,
ApplyNamespace(element.Attributes[ConfigConstants.ATTRIBUTE_ID]),
- element.Attributes[ConfigConstants.ATTRIBUTE_IMPLEMENTATION]);
+ element.Attributes[ConfigConstants.ATTRIBUTE_TYPE]);
config.CreateAttributes(element.Attributes);
config.CreateAttribute(ConfigConstants.ATTRIBUTE_NAMESPACE, nameSpace);
Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/ModelBuilder/BuildCacheModel.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/ModelBuilder/BuildCacheModel.cs?rev=669636&r1=669635&r2=669636&view=diff
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/ModelBuilder/BuildCacheModel.cs (original)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/ModelBuilder/BuildCacheModel.cs Thu Jun 19 11:38:37 2008
@@ -23,17 +23,11 @@
********************************************************************************/
#endregion
-using System;
+using System.Collections.Generic;
using Apache.Ibatis.Common.Configuration;
-using Apache.Ibatis.Common.Data;
-
+using Apache.Ibatis.DataMapper.Configuration.Interpreters.Config;
using Apache.Ibatis.DataMapper.Configuration.Serializers;
-using Apache.Ibatis.DataMapper.Configuration.Interpreters.Config.Xml;
using Apache.Ibatis.DataMapper.Model.Cache;
-using Apache.Ibatis.DataMapper.Configuration.Interpreters.Config;
-using Apache.Ibatis.Common.Exceptions;
-using System.Collections;
-using System.Collections.Specialized;
namespace Apache.Ibatis.DataMapper.Configuration
{
@@ -48,9 +42,7 @@
{
foreach (IConfiguration cacheModelConfig in store.CacheModels)
{
- IDictionary properties = GetProperties(cacheModelConfig);
-
- CacheModel cacheModel = CacheModelDeSerializer.Deserialize(cacheModelConfig, properties, modelStore.DataExchangeFactory.TypeHandlerFactory);
+ CacheModel cacheModel = CacheModelDeSerializer.Deserialize(cacheModelConfig, modelStore.DataExchangeFactory);
string nameSpace = ConfigurationUtils.GetMandatoryStringAttribute(cacheModelConfig, ConfigConstants.ATTRIBUTE_NAMESPACE);
@@ -67,8 +59,6 @@
cacheModel.StatementFlushNames.Add(statementId);
}
- cacheModel.FlushInterval = BuildFlushInterval(cacheModelConfig);
-
modelStore.AddCacheModel(cacheModel);
}
}
@@ -78,9 +68,9 @@
/// </summary>
/// <param name="cacheModelConfiguration">The cache model configuration.</param>
/// <returns></returns>
- private IDictionary GetProperties(IConfiguration cacheModelConfiguration)
+ private IDictionary<string, string> GetProperties(IConfiguration cacheModelConfiguration)
{
- IDictionary properties = new HybridDictionary();
+ IDictionary<string, string> properties = new Dictionary<string, string>();
// Get Properties
ConfigurationCollection propertiesConfigs = cacheModelConfiguration.Children.Find(ConfigConstants.ELEMENT_PROPERTY);
@@ -95,26 +85,5 @@
return properties;
}
- /// <summary>
- /// Builds the flush interval.
- /// </summary>
- /// <param name="cacheModelConfiguration">The cache model configuration.</param>
- private FlushInterval BuildFlushInterval(IConfiguration cacheModelConfiguration)
- {
- FlushInterval flushInterval = null;
- ConfigurationCollection flushIntervalConfigs = cacheModelConfiguration.Children.Find(ConfigConstants.ELEMENT_FLUSHINTERVAL);
-
- if (flushIntervalConfigs.Count > 0)
- {
- int hours = ConfigurationUtils.GetIntAttribute(flushIntervalConfigs[0].Attributes, "hours", 0);
- int minutes = ConfigurationUtils.GetIntAttribute(flushIntervalConfigs[0].Attributes, "minutes", 0);
- int seconds = ConfigurationUtils.GetIntAttribute(flushIntervalConfigs[0].Attributes, "seconds", 0);
- int milliseconds = ConfigurationUtils.GetIntAttribute(flushIntervalConfigs[0].Attributes, "milliseconds", 0);
-
- flushInterval = new FlushInterval(hours, minutes, seconds, milliseconds);
- }
-
- return flushInterval;
- }
}
}
Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/Serializers/CacheModelDeSerializer.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/Serializers/CacheModelDeSerializer.cs?rev=669636&r1=669635&r2=669636&view=diff
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/Serializers/CacheModelDeSerializer.cs (original)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Configuration/Serializers/CacheModelDeSerializer.cs Thu Jun 19 11:38:37 2008
@@ -25,15 +25,11 @@
#region Using
-using System.Collections.Specialized;
-using System.Xml;
-using Apache.Ibatis.Common.Xml;
-using Apache.Ibatis.DataMapper.Model.Cache;
-using Apache.Ibatis.DataMapper.Scope;
using Apache.Ibatis.Common.Configuration;
-using Apache.Ibatis.DataMapper.TypeHandlers;
-using System.Collections;
using Apache.Ibatis.DataMapper.Configuration.Interpreters.Config;
+using Apache.Ibatis.DataMapper.DataExchange;
+using Apache.Ibatis.DataMapper.Model.Cache;
+
#endregion
@@ -49,18 +45,18 @@
/// Deserializes the specified config in a CacheModel object.
/// </summary>
/// <param name="config">The config.</param>
- /// <param name="properties">The cacheModel properties.</param>
- /// <param name="typeHandlerFactory">The type handler factory.</param>
+ /// <param name="dataExchangeFactory">The data exchange factory.</param>
/// <returns>A CacheModel object</returns>
- public static CacheModel Deserialize(IConfiguration config, IDictionary properties, TypeHandlerFactory typeHandlerFactory)
+ public static CacheModel Deserialize(IConfiguration config, DataExchangeFactory dataExchangeFactory)
{
string id = config.Id;
- string implementation = ConfigurationUtils.GetMandatoryStringAttribute(config, ConfigConstants.ATTRIBUTE_IMPLEMENTATION);
- implementation = typeHandlerFactory.GetTypeAlias(implementation).Type.AssemblyQualifiedName;
- bool isReadOnly = ConfigurationUtils.GetBooleanAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_READONLY, true);
- bool isSerializable = ConfigurationUtils.GetBooleanAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_SERIALIZE, false);
+ string type = ConfigurationUtils.GetMandatoryStringAttribute(config, ConfigConstants.ATTRIBUTE_TYPE);
+ type = dataExchangeFactory.TypeHandlerFactory.GetTypeAlias(type).Type.AssemblyQualifiedName;
+ long flushInterval = ConfigurationUtils.GetLongAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_FLUSHINTERVAL, int.MinValue);
+ bool isShare = ConfigurationUtils.GetBooleanAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_SHARE, false);
+ int size = ConfigurationUtils.GetIntAttribute(config.Attributes, ConfigConstants.ATTRIBUTE_SIZE, int.MinValue);
- return new CacheModel(id, implementation, properties, isReadOnly, isSerializable);
+ return new CacheModel(id, type, flushInterval, size, isShare);
}
}
}
Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/MappedStatements/CachingStatement.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/MappedStatements/CachingStatement.cs?rev=669636&r1=669635&r2=669636&view=diff
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/MappedStatements/CachingStatement.cs (original)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/MappedStatements/CachingStatement.cs Thu Jun 19 11:38:37 2008
@@ -32,6 +32,7 @@
using Apache.Ibatis.DataMapper.Data;
using Apache.Ibatis.DataMapper.Model;
using Apache.Ibatis.DataMapper.Model.Cache;
+using Apache.Ibatis.DataMapper.Model.Cache.Decorators;
using Apache.Ibatis.DataMapper.Model.Events;
using Apache.Ibatis.DataMapper.Model.Statements;
using Apache.Ibatis.DataMapper.Scope;
@@ -144,7 +145,7 @@
if (map == null)
{
map = mappedStatement.RunQueryForMap( request, session, parameterObject, keyProperty, valueProperty, null );
- Statement.CacheModel[cacheKey] = map;
+ Statement.CacheModel[cacheKey] = map;
}
return map;
@@ -340,9 +341,9 @@
CacheKey cacheKey = GetCacheKey(request);
cacheKey.Update("ExecuteQueryForObject");
- obj = Statement.CacheModel[cacheKey];
+ obj = Statement.CacheModel[cacheKey];
// check if this query has alreay been run
- if (obj == CacheModel.NULL_OBJECT)
+ if (obj == CacheModel.NULL_OBJECT)
{
// convert the marker object back into a null value
obj = null;
@@ -350,7 +351,7 @@
else if (obj ==null)
{
obj = mappedStatement.RunQueryForObject(request, session, param, resultObject);
- Statement.CacheModel[cacheKey] = obj;
+ Statement.CacheModel[cacheKey] = obj;
}
return RaisePostEvent<object, PostSelectEventArgs>(PostSelectEvent, param, obj);
@@ -445,22 +446,6 @@
#endregion
- /// <summary>
- /// Gets a percentage of successful cache hits achieved
- /// </summary>
- /// <returns>The percentage of hits (0-1), or -1 if cache is disabled.</returns>
- public double GetDataCacheHitRatio()
- {
- if (mappedStatement.Statement.CacheModel != null)
- {
- return mappedStatement.Statement.CacheModel.HitRatio;
- }
- else
- {
- return -1;
- }
- }
-
/// <summary>
/// Gets the cache key.
/// </summary>
@@ -483,11 +468,12 @@
cacheKey.Update(mappedStatement.ModelStore.SessionFactory.DataSource.ConnectionString);
cacheKey.Update(request.IDbCommand.CommandText);
- CacheModel cacheModel = mappedStatement.Statement.CacheModel;
- if (!cacheModel.IsReadOnly && !cacheModel.IsSerializable)
- {
- cacheKey.Update(request);
- }
+ //todo a supprimer
+ //CacheModel cacheModel = mappedStatement.Statement.CacheModel;
+ //if (!cacheModel.IsReadOnly && !cacheModel.IsSerializable)
+ //{
+ // cacheKey.Update(request);
+ //}
return cacheKey;
}
}
Added: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/BaseCache.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/BaseCache.cs?rev=669636&view=auto
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/BaseCache.cs (added)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/BaseCache.cs Thu Jun 19 11:38:37 2008
@@ -0,0 +1,143 @@
+
+#region Apache Notice
+/*****************************************************************************
+ * $Header: $
+ * $Revision: 383115 $
+ * $Date$
+ *
+ * iBATIS.NET Data Mapper
+ * Copyright (C) 2004 - Gilles Bayon
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ********************************************************************************/
+#endregion
+
+using Apache.Ibatis.DataMapper.Exceptions;
+
+namespace Apache.Ibatis.DataMapper.Model.Cache
+{
+ /// <summary>
+ /// Base Cache class implements a template method pattern for subclasses.
+ /// </summary>
+ public abstract class BaseCache : ICache
+ {
+ protected string id = string.Empty;
+ protected int size = 0;
+
+ #region ICache Members
+
+ /// <summary>
+ /// Gets the id.
+ /// </summary>
+ /// <value>The id.</value>
+ public virtual string Id
+ {
+ get { return id; }
+ set { id = value;}
+ }
+
+ /// <summary>
+ /// Gets the size.
+ /// </summary>
+ /// <value>The size.</value>
+ public virtual int Size
+ {
+ get { return size; }
+ set { size = value; }
+ }
+
+ /// <summary>
+ /// Adds an item with the specified key and value into cached data.
+ /// Gets a cached object with the specified key.
+ /// </summary>
+ /// <value>The cached object or <c>null</c></value>
+ public abstract object this[object key] { get;set;}
+
+
+ /// <summary>
+ /// Remove an object from a cache model
+ /// </summary>
+ /// <param name="key">the key to the object</param>
+ /// <returns>the removed object(?)</returns>
+ public abstract object Remove(object key);
+
+
+ /// <summary>
+ /// Clears all elements from the cache.
+ /// </summary>
+ public abstract void Clear();
+
+ /// <summary>
+ /// Determines whether the cache contains the key.
+ /// </summary>
+ /// <param name="key">The key.</param>
+ /// <returns>
+ /// <c>true</c> if the specified key contains key; otherwise, <c>false</c>.
+ /// </returns>
+ public abstract bool ContainsKey(object key);
+
+
+ #endregion
+
+
+ /// <summary>
+ /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
+ /// </summary>
+ /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>.</param>
+ /// <returns>
+ /// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
+ /// </returns>
+ /// <exception cref="T:System.NullReferenceException">The <paramref name="obj"/> parameter is null.</exception>
+ public override bool Equals(object obj)
+ {
+ if (string.IsNullOrEmpty(Id))
+ {
+ throw new DataMapperException("Cache instances require an ID.");
+ }
+ if (this == obj)
+ {
+ return true;
+ }
+ if (!(obj is BaseCache))
+ {
+ return false;
+ }
+
+ BaseCache baseCache = (BaseCache)obj;
+
+ if ( !Id.Equals(baseCache.Id) )
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ /// <summary>
+ /// Get the HashCode for this CacheKey
+ /// </summary>
+ /// <returns>
+ /// A hash code for the current <see cref="T:System.Object"/>.
+ /// </returns>
+ public override int GetHashCode()
+ {
+ if (string.IsNullOrEmpty(Id))
+ {
+ throw new DataMapperException("Cache instances require an ID.");
+ }
+ return Id.GetHashCode();
+ }
+ }
+}
Propchange: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/BaseCache.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/BaseCache.cs
------------------------------------------------------------------------------
svn:keywords = Id LastChangedDate LastChangedBy
Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/CacheKey.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/CacheKey.cs?rev=669636&r1=669635&r2=669636&view=diff
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/CacheKey.cs (original)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/CacheKey.cs Thu Jun 19 11:38:37 2008
@@ -24,7 +24,7 @@
********************************************************************************/
#endregion
-using System.Collections;
+using System.Collections.Generic;
using System.Text;
using Apache.Ibatis.Common.Utilities;
@@ -43,7 +43,7 @@
private int hashCode = DEFAULT_HASHCODE;
private long checksum = long.MinValue;
private int count = 0;
- private readonly IList paramList = new ArrayList();
+ private readonly IList<object> paramList = new List<object>();
/// <summary>
/// Default constructor
@@ -55,28 +55,14 @@
count = 0;
}
- /// <summary>
- /// Constructor that supplies an initial hashcode
- /// </summary>
- /// <param name="initialNonZeroOddNumber">the hashcode to use</param>
- public CacheKey(int initialNonZeroOddNumber)
- {
- hashCode = initialNonZeroOddNumber;
- multiplier = DEFAULT_MULTIPLYER;
- count = 0;
- }
-
- /// <summary>
- /// Constructor that supplies an initial hashcode and multiplier
- /// </summary>
- /// <param name="initialNonZeroOddNumber">the hashcode to use</param>
- /// <param name="multiplierNonZeroOddNumber">the multiplier to use</param>
- public CacheKey(int initialNonZeroOddNumber, int multiplierNonZeroOddNumber)
- {
- hashCode = initialNonZeroOddNumber;
- multiplier = multiplierNonZeroOddNumber;
- count = 0;
- }
+ /// <summary>
+ /// Initializes a new instance of the <see cref="CacheKey"/> class.
+ /// </summary>
+ /// <param name="objects">The objects.</param>
+ public CacheKey(object[] objects):this()
+ {
+ UpdateAll(objects);
+ }
/// <summary>
/// Updates this object with new information based on an object
@@ -85,7 +71,7 @@
/// <returns>the cachekey</returns>
public CacheKey Update(object obj)
{
- int baseHashCode = HashCodeProvider.GetIdentityHashCode(obj);
+ int baseHashCode = (obj == null)? 1 :HashCodeProvider.GetIdentityHashCode(obj);
count++;
checksum += baseHashCode;
@@ -98,6 +84,18 @@
return this;
}
+ /// <summary>
+ /// Updates all.
+ /// </summary>
+ /// <param name="objects">The objects.</param>
+ public void UpdateAll(object[] objects)
+ {
+ foreach(object o in objects)
+ {
+ Update(o);
+ }
+ }
+
/// <summary>
///
/// </summary>
Modified: ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/CacheModel.cs
URL: http://svn.apache.org/viewvc/ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/CacheModel.cs?rev=669636&r1=669635&r2=669636&view=diff
==============================================================================
--- ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/CacheModel.cs (original)
+++ ibatis/trunk/cs/V3/src/Apache.Ibatis.DataMapper/Model/Cache/CacheModel.cs Thu Jun 19 11:38:37 2008
@@ -27,19 +27,13 @@
#region Using
using System;
-using System.Collections;
using System.Collections.Generic;
-using System.Collections.Specialized;
using System.Diagnostics;
-using System.IO;
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.Serialization.Formatters.Binary;
using Apache.Ibatis.Common.Contracts;
using Apache.Ibatis.Common.Exceptions;
-using Apache.Ibatis.Common.Logging;
using Apache.Ibatis.Common.Utilities;
using Apache.Ibatis.DataMapper.MappedStatements;
+using Apache.Ibatis.DataMapper.Model.Cache.Decorators;
#endregion
@@ -50,46 +44,25 @@
/// Summary description for CacheModel.
/// </summary>
[Serializable]
- [DebuggerDisplay("CacheModel: {Id}-{Implementation}")]
+ [DebuggerDisplay("CacheModel: {Id}-{Cache}")]
public class CacheModel
{
- #region Fields
-
- private readonly static IDictionary lockMap = new HybridDictionary();
-
- private static readonly ILog logger = LogManager.GetLogger( MethodBase.GetCurrentMethod().DeclaringType );
- /// <summary>
- /// This is used to represent null objects that are returned from the cache so
- /// that they can be cached, too.
- /// </summary>
- public readonly static object NULL_OBJECT = new Object();
+ /// <summary>
+ /// This is used to represent null objects that are returned from the cache so
+ /// that they can be cached, too.
+ /// </summary>
+ public readonly static object NULL_OBJECT = new Object();
- /// <summary>
- /// Constant to turn off periodic cache flushes
- /// </summary>
- public const long NO_FLUSH_INTERVAL = -99999;
+ private ICache cache = null;
- private readonly object syncLock = new Object();
- private int requests = 0;
- private int hits = 0;
- private readonly string id = string.Empty;
- private ICacheController controller = null;
- private FlushInterval flushInterval = null;
- private long lastFlush = 0;
- private readonly string implementation = string.Empty;
- private readonly bool isReadOnly = true;
- private readonly bool isSerializable = false;
private readonly IList<string> statementFlushNames = new List<string>();
- #endregion
-
- #region Properties
/// <summary>
/// Identifier used to identify the CacheModel amongst the others.
/// </summary>
public string Id
{
- get { return id; }
+ get { return cache.Id; }
}
@@ -103,120 +76,70 @@
}
/// <summary>
- /// Cache controller implementation name.
- /// </summary>
- public string Implementation
- {
- get { return implementation; }
- }
-
- /// <summary>
- /// Set the cache controller
- /// </summary>
- public ICacheController CacheController
- {
- set{ controller =value; }
- }
-
- /// <summary>
- /// Set or get the flushInterval (in Ticks)
- /// </summary>
- public FlushInterval FlushInterval
- {
- get { return flushInterval; }
- set { flushInterval = value; }
- }
-
- /// <summary>
- /// Specifie how the cache content should be returned.
- /// If true a deep copy is returned.
+ /// Set the cache implementation
/// </summary>
- /// <remarks>
- /// Combinaison
- /// IsReadOnly=true/IsSerializable=false : Returned instance of cached object
- /// IsReadOnly=false/IsSerializable=true : Returned coopy of cached object
- /// </remarks>
- public bool IsSerializable
+ public ICache Cache
{
- get { return isSerializable; }
+ get { return cache; }
+ set { cache = value; }
}
- /// <summary>
- /// Determines if the cache will be used as a read-only cache.
- /// Tells the cache model that is allowed to pass back a reference to the object
- /// existing in the cache.
- /// </summary>
- /// <remarks>
- /// The IsReadOnly properties works in conjonction with the IsSerializable propertie.
- /// </remarks>
- public bool IsReadOnly
- {
- get { return isReadOnly; }
- }
- #endregion
-
- #region Constructor (s) / Destructor
-
/// <summary>
- /// Initializes a new instance of the <see cref="CacheModel"/> class.
- /// </summary>
- /// <param name="name">The name.</param>
- /// <param name="controllerImplementation">The controller implementation.</param>
- /// <param name="properties">The properties.</param>
- public CacheModel(
- string name,
- string controllerImplementation,
- IDictionary properties)
- : this(name, controllerImplementation, properties, true, false)
- {}
+ /// Adds an item with the specified key and value into cached data.
+ /// Gets a cached object with the specified key.
+ /// </summary>
+ /// <value>The cached object or <c>null</c></value>
+ public object this[CacheKey key]
+ {
+ get { return cache[key]; }
+ set { cache[key] = value;}
+ }
/// <summary>
/// Initializes a new instance of the <see cref="CacheModel"/> class.
/// </summary>
/// <param name="id">The id.</param>
- /// <param name="implementation">The controller implementation.</param>
- /// <param name="properties">The properties.</param>
- /// <param name="isReadOnly">if set to <c>true</c> [is read only].</param>
- /// <param name="isSerializable">if set to <c>true</c> [is serializable].</param>
+ /// <param name="implementation">The cache implementation.</param>
+ /// <param name="flushInterval">The flush interval.</param>
+ /// <param name="size">The size.</param>
+ /// <param name="isShare">if set to <c>true</c> [is share].</param>
public CacheModel(
string id,
- string implementation,
- IDictionary properties,
- bool isReadOnly,
- bool isSerializable)
+ string implementation,
+ long flushInterval,
+ int size,
+ bool isShare)
{
Contract.Require.That(id, Is.Not.Null & Is.Not.Empty).When("retrieving argument id in CacheModel constructor");
Contract.Require.That(implementation, Is.Not.Null & Is.Not.Empty).When("retrieving argument implementation in CacheModel constructor");
- Contract.Require.That(properties, Is.Not.Null).When("retrieving argument properties in CacheModel constructor");
-
- this.id = id;
- this.implementation = implementation;
- this.isReadOnly = isReadOnly;
- this.isSerializable = isSerializable;
-
- lastFlush = DateTime.Now.Ticks;
try
{
- // Build the CacheController
+ // Build the Cache
Type type = TypeUtils.ResolveType(implementation);
- object[] arguments = new object[0];
+ object[] arguments = new object[0];
- controller = (ICacheController)Activator.CreateInstance(type, arguments);
- }
- catch (Exception e)
- {
- throw new ConfigurationException("Error instantiating cache controller for cache named '"+id+". Cause: " + e.Message, e);
- }
+ cache = (ICache)Activator.CreateInstance(type, arguments);
+ cache.Id = id;
+ cache = new NullValueDecorator(cache);
- //------------ configure Controller---------------------
- try
- {
- controller.Configure(properties);
+ if (size != int.MinValue)
+ {
+ cache.Size = size;
+ }
+ if (flushInterval != long.MinValue)
+ {
+ cache = cache = new ScheduledCache(cache, flushInterval);
+ }
+ if (isShare)
+ {
+ cache = cache = new SharedCache(cache);
+ }
+ cache = new SynchronizedCache(cache);
}
catch (Exception e)
{
- throw new ConfigurationException ("Error configuring controller named '"+id+"'. Cause: " + e.Message, e);
+ throw new ConfigurationException("Error instantiating cache implementation for cache '"+id+". Cause: " + e.Message, e);
}
}
@@ -238,155 +161,7 @@
/// <param name="e"></param>
private void FlushHandler(object sender, ExecuteEventArgs e)
{
- if (logger.IsDebugEnabled)
- {
- logger.Debug("Flush cacheModel named "+id+" for statement '"+e.StatementName+"'");
- }
-
- Flush();
- }
-
-
- /// <summary>
- /// Clears all elements from the cache.
- /// </summary>
- public void Flush()
- {
- lastFlush = DateTime.Now.Ticks;
- controller.Flush();
- }
-
-
- /// <summary>
- /// Adds an item with the specified key and value into cached data.
- /// Gets a cached object with the specified key.
- /// </summary>
- /// <value>The cached object or <c>null</c></value>
- /// <remarks>
- /// A side effect of this method is that is may clear the cache
- /// if it has not been cleared in the flushInterval.
- /// </remarks>
- public object this [CacheKey key]
- {
- get
- {
- lock(this)
- {
- if (lastFlush != NO_FLUSH_INTERVAL
- && (DateTime.Now.Ticks - lastFlush > flushInterval.Interval))
- {
- Flush();
- }
- }
-
- object value = null;
- lock (GetLock(key))
- {
- value = controller[key];
- }
-
- if(isSerializable && !isReadOnly &&
- (value != NULL_OBJECT && value != null))
- {
- try
- {
- MemoryStream stream = new MemoryStream((byte[]) value);
- stream.Position = 0;
- BinaryFormatter formatter = new BinaryFormatter();
- value = formatter.Deserialize( stream );
- }
- catch(Exception ex)
- {
- throw new IbatisException("Error caching serializable object. Be sure you're not attempting to use " +
- "a serialized cache for an object that may be taking advantage of lazy loading. Cause: "+ex.Message, ex);
- }
- }
-
- lock(syncLock)
- {
- requests++;
- if (value != null)
- {
- hits++;
- }
- }
-
- if (logger.IsDebugEnabled)
- {
- if (value != null)
- {
- logger.Debug(String.Format("Retrieved cached object '{0}' using key '{1}' ", value, key));
- }
- else
- {
- logger.Debug(String.Format("Cache miss using key '{0}' ", key));
- }
- }
- return value;
- }
- set
- {
- if (null == value) {value = NULL_OBJECT;}
- if(isSerializable && !isReadOnly && value != NULL_OBJECT)
- {
- try
- {
- MemoryStream stream = new MemoryStream();
- BinaryFormatter formatter = new BinaryFormatter();
- formatter.Serialize(stream, value);
- value = stream.ToArray();
- }
- catch(Exception ex)
- {
- throw new IbatisException("Error caching serializable object. Cause: "+ex.Message, ex);
- }
- }
- controller[key] = value;
- if (logger.IsDebugEnabled)
- {
- logger.Debug(String.Format("Cache object '{0}' using key '{1}' ", value, key));
- }
- }
- }
-
- /// <summary>
- ///
- /// </summary>
- public double HitRatio
- {
- get
- {
- if (requests!=0)
- {
- return (double)hits/(double)requests;
- }
- else
- {
- return 0;
- }
- }
- }
-
- #endregion
-
- /// <summary>
- ///
- /// </summary>
- /// <param name="key"></param>
- /// <returns></returns>
- [MethodImpl(MethodImplOptions.Synchronized)]
- public object GetLock(CacheKey key)
- {
- int controllerId = HashCodeProvider.GetIdentityHashCode(controller);
- int keyHash = key.GetHashCode();
- int lockKey = 29 * controllerId + keyHash;
- object lok =lockMap[lockKey];
- if (lok == null)
- {
- lok = lockKey; //might as well use the same object
- lockMap[lockKey] = lok;
- }
- return lok;
+ cache.Clear();
}
}
}