/// <summary> /// Returns copy of cached object /// </summary> public void TestReturnCopyOfCachedOject() { CacheModel cacheModel = new CacheModel("test", typeof(LruCache).FullName, 60, 1, true); Order order = new Order(); order.CardNumber = "CardNumber"; order.Date = DateTime.Now; order.LineItemsCollection = new LineItemCollection(); LineItem item = new LineItem(); item.Code = "Code1"; order.LineItemsCollection.Add(item); item = new LineItem(); item.Code = "Code2"; order.LineItemsCollection.Add(item); CacheKey key = new CacheKey(); key.Update(order); int firstId = HashCodeProvider.GetIdentityHashCode(order); cacheModel[key] = order; Order order2 = cacheModel[key] as Order; int secondId = HashCodeProvider.GetIdentityHashCode(order2); Assert.AreNotEqual(firstId, secondId, "hasCode equal"); }
public GetAccessorFactory(bool allowCodeGeneration) { if (allowCodeGeneration) { if (Environment.Version.Major >= 2) { this._createPropertyGetAccessor = new CreatePropertyGetAccessor(this.CreateDynamicPropertyGetAccessor); this._createFieldGetAccessor = new CreateFieldGetAccessor(this.CreateDynamicFieldGetAccessor); } else { AssemblyName name = new AssemblyName { Name = "iBATIS.FastGetAccessor" + HashCodeProvider.GetIdentityHashCode(this).ToString() }; this._assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(name, AssemblyBuilderAccess.Run); this._moduleBuilder = this._assemblyBuilder.DefineDynamicModule(name.Name + ".dll"); this._createPropertyGetAccessor = new CreatePropertyGetAccessor(this.CreatePropertyAccessor); this._createFieldGetAccessor = new CreateFieldGetAccessor(this.CreateFieldAccessor); } } else { this._createPropertyGetAccessor = new CreatePropertyGetAccessor(this.CreateReflectionPropertyGetAccessor); this._createFieldGetAccessor = new CreateFieldGetAccessor(this.CreateReflectionFieldGetAccessor); } }
/// <summary> /// Returns reference to same instance of cached object /// </summary> public void TestReturnInstanceOfCachedOject() { CacheModel cacheModel = new CacheModel("test", typeof(LruCache).FullName, 60, 1, false); //cacheModel.FlushInterval = interval; //cacheModel.IsReadOnly = true; //cacheModel.IsSerializable = false; Order order = new Order(); order.CardNumber = "CardNumber"; order.Date = DateTime.Now; order.LineItemsCollection = new LineItemCollection(); LineItem item = new LineItem(); item.Code = "Code1"; order.LineItemsCollection.Add(item); item = new LineItem(); item.Code = "Code2"; order.LineItemsCollection.Add(item); CacheKey key = new CacheKey(); key.Update(order); int firstId = HashCodeProvider.GetIdentityHashCode(order); cacheModel[key] = order; Order order2 = cacheModel[key] as Order; int secondId = HashCodeProvider.GetIdentityHashCode(order2); Assert.AreEqual(firstId, secondId, "hasCode different"); }
public void TestCacheHitMiss() { CacheModel cache = GetCacheModel(); CacheKey key = new CacheKey(); key.Update("testKey"); string value = "testValue"; cache[key] = value; object returnedObject = cache[key]; Assert.AreEqual(value, returnedObject); Assert.AreEqual(HashCodeProvider.GetIdentityHashCode(value), HashCodeProvider.GetIdentityHashCode(returnedObject)); CacheKey wrongKey = new CacheKey(); wrongKey.Update("wrongKey"); returnedObject = cache[wrongKey]; Assert.IsTrue(!value.Equals(returnedObject)); Assert.IsNull(returnedObject); Assert.AreEqual(0.5, cache.HitRatio); }
public void TestMappedStatementQueryWithThreadedReadWriteNonSerializableCache() { Hashtable results = new Hashtable(); // run a SELECT query from two different threads. TestCacheThread.StartThread joins the // new thread to the current, so test execution does not continue until the new thread completes TestCacheThread.StartThread(sqlMap, results, "GetRWNSCachedAccountsViaResultMap"); int firstId = (int)results["id"]; TestCacheThread.StartThread(sqlMap, results, "GetRWNSCachedAccountsViaResultMap"); int secondId = (int)results["id"]; Assert.AreNotEqual(firstId, secondId); IList list = (IList)results["list"]; Account account = (Account)list[1]; account.EmailAddress = "*****@*****.**"; sqlMap.Update("UpdateAccountViaInlineParameters", account); list = sqlMap.QueryForList("GetRWNSCachedAccountsViaResultMap", null); int thirdId = HashCodeProvider.GetIdentityHashCode(list); Assert.AreNotEqual(firstId, thirdId); }
/// <summary> /// Initializes a new instance of the <see cref="SetAccessorFactory"/> class. /// </summary> /// <param name="allowCodeGeneration">if set to <c>true</c> [allow code generation].</param> public SetAccessorFactory(bool allowCodeGeneration) { if (allowCodeGeneration) { // Detect runtime environment and create the appropriate factory if (Environment.Version.Major >= 2) { _createPropertySetAccessor = new CreatePropertySetAccessor(CreateDynamicPropertySetAccessor); _createFieldSetAccessor = new CreateFieldSetAccessor(CreateDynamicFieldSetAccessor); } else { AssemblyName assemblyName = new AssemblyName(); assemblyName.Name = "iBATIS.FastSetAccessor" + HashCodeProvider.GetIdentityHashCode(this).ToString(); // Create a new assembly with one module _assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run); _moduleBuilder = _assemblyBuilder.DefineDynamicModule(assemblyName.Name + ".dll"); _createPropertySetAccessor = new CreatePropertySetAccessor(CreatePropertyAccessor); _createFieldSetAccessor = new CreateFieldSetAccessor(CreateFieldAccessor); } } else { _createPropertySetAccessor = new CreatePropertySetAccessor(CreateReflectionPropertySetAccessor); _createFieldSetAccessor = new CreateFieldSetAccessor(CreateReflectionFieldSetAccessor); } }
public void TestMappedStatementQueryWithReadWriteCacheWithSession() { IMappedStatement statement = sqlMap.GetMappedStatement("GetRWNSCachedAccountsViaResultMap"); ISqlMapSession session = new SqlMapSession(sqlMap); session.OpenConnection(); int firstId = 0; int secondId = 0; try { // execute the statement twice; the second call should result in a cache hit IList list = statement.ExecuteQueryForList(session, null); firstId = HashCodeProvider.GetIdentityHashCode(list); list = statement.ExecuteQueryForList(session, null); secondId = HashCodeProvider.GetIdentityHashCode(list); } finally { session.CloseConnection(); } Assert.AreEqual(firstId, secondId); }
public void TestMappedStatementQueryWithThreadedReadWriteCache() { Hashtable results = new Hashtable(); TestCacheThread.StartThread(sqlMap, results, "GetRWCachedAccountsViaResultMap"); int firstId = (int)results["id"]; TestCacheThread.StartThread(sqlMap, results, "GetRWCachedAccountsViaResultMap"); int secondId = (int)results["id"]; Assert.AreNotEqual(firstId, secondId); IList list = (IList)results["list"]; Account account = (Account)list[1]; account.EmailAddress = "*****@*****.**"; sqlMap.Update("UpdateAccountViaInlineParameters", account); list = sqlMap.QueryForList("GetCachedAccountsViaResultMap", null); int thirdId = HashCodeProvider.GetIdentityHashCode(list); Assert.AreNotEqual(firstId, thirdId); }
public void TestQueryWithCache() { IList list = sqlMap.QueryForList("GetCachedAccountsViaResultMap", null); int firstId = HashCodeProvider.GetIdentityHashCode(list); list = sqlMap.QueryForList("GetCachedAccountsViaResultMap", null); //Console.WriteLine(sqlMap.GetDataCacheStats()); int secondId = HashCodeProvider.GetIdentityHashCode(list); Assert.AreEqual(firstId, secondId); Account account = (Account)list[1]; account.EmailAddress = "*****@*****.**"; sqlMap.Update("UpdateAccountViaInlineParameters", account); list = sqlMap.QueryForList("GetCachedAccountsViaResultMap", null); int thirdId = HashCodeProvider.GetIdentityHashCode(list); Assert.IsTrue(firstId != thirdId); //Console.WriteLine(sqlMap.GetDataCacheStats()); }
public SqlMapper(IObjectFactory objectFactory, IBatisNet.Common.Utilities.Objects.Members.AccessorFactory accessorFactory) { this._objectFactory = objectFactory; this._accessorFactory = accessorFactory; this._dataExchangeFactory = new IBatisNet.DataMapper.DataExchange.DataExchangeFactory(this._typeHandlerFactory, this._objectFactory, accessorFactory); this._id = HashCodeProvider.GetIdentityHashCode(this).ToString(); this._sessionStore = SessionStoreFactory.GetSessionStore(this._id); }
public FactoryBuilder() { AssemblyName name = new AssemblyName { Name = "iBATIS.EmitFactory" + HashCodeProvider.GetIdentityHashCode(this).ToString() }; this._moduleBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(name, AssemblyBuilderAccess.Run).DefineDynamicModule(name.Name + ".dll"); }
/// <summary> /// constructor /// </summary> public FactoryBuilder() { AssemblyName assemblyName = new AssemblyName(); assemblyName.Name = "MyBatis.EmitFactory" + HashCodeProvider.GetIdentityHashCode(this); // Create a new assembly with one module AssemblyBuilder _assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run); _moduleBuilder = _assemblyBuilder.DefineDynamicModule(assemblyName.Name + ".dll"); }
public CacheKey Update(object obj) { int identityHashCode = HashCodeProvider.GetIdentityHashCode(obj); this._count++; this._checksum += identityHashCode; identityHashCode *= this._count; this._hashCode = (this._multiplier * this._hashCode) + identityHashCode; this._paramList.Add(obj); return(this); }
/// <summary> /// constructor /// </summary> public FactoryBuilder() { AssemblyName assemblyName = new AssemblyName(); assemblyName.Name = "iBATIS.EmitFactory" + HashCodeProvider.GetIdentityHashCode(this).ToString(); // Create a new assembly with one module AssemblyBuilder _assemblyBuilder = _assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run); _moduleBuilder = _assemblyBuilder.DefineDynamicModule(assemblyName.Name + ".dll"); }
public void TestMemberAccessorFactory() { IGetAccessor accessor11 = factoryGet.CreateGetAccessor(typeof(Property), "Int"); IGetAccessor accessor12 = factoryGet.CreateGetAccessor(typeof(Property), "Int"); Assert.AreEqual(HashCodeProvider.GetIdentityHashCode(accessor11), HashCodeProvider.GetIdentityHashCode(accessor12)); ISetAccessor accessor21 = factorySet.CreateSetAccessor(typeof(Property), "Int"); ISetAccessor accessor22 = factorySet.CreateSetAccessor(typeof(Property), "Int"); Assert.AreEqual(HashCodeProvider.GetIdentityHashCode(accessor21), HashCodeProvider.GetIdentityHashCode(accessor22)); }
public void TestJIRA104() { IList list = dataMapper.QueryForList("Account.GetCachedAccountsViaResultMap", null); int firstId = HashCodeProvider.GetIdentityHashCode(list); list = dataMapper.QueryForList("Account.GetCachedAccountsViaResultMap", null); int secondId = HashCodeProvider.GetIdentityHashCode(list); Assert.AreEqual(firstId, secondId); }
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); }
public object GetLock(CacheKey key) { int identityHashCode = HashCodeProvider.GetIdentityHashCode(this._controller); int hashCode = key.GetHashCode(); int num3 = (0x1d * identityHashCode) + hashCode; object obj2 = _lockMap[num3]; if (obj2 == null) { obj2 = num3; _lockMap[num3] = obj2; } return(obj2); }
/// <summary> /// Updates this object with new information based on an object /// </summary> /// <param name="obj">the object</param> /// <returns>the cachekey</returns> public CacheKey Update(object obj) { int baseHashCode = (obj == null)? 1 :HashCodeProvider.GetIdentityHashCode(obj); count++; checksum += baseHashCode; baseHashCode *= count; hashCode = multiplier * hashCode + baseHashCode; paramList.Add(obj); return(this); }
public void TestGetAccountField() { Account test = new Account(); test.FirstName = "Gilles"; Property prop = new Property(); prop.publicAccount = test; // Property accessor Assert.AreEqual(HashCodeProvider.GetIdentityHashCode(test), HashCodeProvider.GetIdentityHashCode(prop.publicAccount)); Assert.AreEqual(test.FirstName, ((Account)accountGetAccessor.Get(prop)).FirstName); }
public void TestCacheNullObject() { CacheModel cache = GetCacheModel(); CacheKey key = new CacheKey(); key.Update("testKey"); cache[key] = null; object returnedObject = cache[key]; Assert.AreEqual(CacheModel.NULL_OBJECT, returnedObject); Assert.AreEqual(HashCodeProvider.GetIdentityHashCode(CacheModel.NULL_OBJECT), HashCodeProvider.GetIdentityHashCode(returnedObject)); }
/// <summary> /// Updates this object with new information based on an object /// </summary> /// <param name="obj">the object</param> /// <returns>the cachekey</returns> public CacheKey Update(object obj) { int baseHashCode = HashCodeProvider.GetIdentityHashCode(obj); _count++; _checksum += baseHashCode; baseHashCode *= _count; _hashCode = _multiplier * _hashCode + baseHashCode; _paramList.Add(obj); return(this); }
public IBatisDAL() { if (dataMapper == null) { lock (mylock) { if (dataMapper == null) { InitDataMapper(); } } } this.SessionId = HashCodeProvider.GetIdentityHashCode(this).ToString(); sessionStore = SessionStoreFactory.GetSessionStore(this.SessionId); }
public void TestGetAccountField() { Account test = new Account(); test.FirstName = "Gilles"; Property prop = new Property(); FieldInfo fieldInfo = GetFieldInfo("protectedAccount"); fieldInfo.SetValue(prop, test); // Property accessor Assert.AreEqual(HashCodeProvider.GetIdentityHashCode(test), HashCodeProvider.GetIdentityHashCode(fieldInfo.GetValue(prop))); Assert.AreEqual(test.FirstName, ((Account)accountGetAccessor.Get(prop)).FirstName); }
public void TestJIRA242WithCache() { Account account1 = dataMapper.QueryForObject <Account>("GetNoAccountWithCache", 1); AssertAccount1(account1); int firstId = HashCodeProvider.GetIdentityHashCode(account1); Account account2 = dataMapper.QueryForObject <Account>("GetNoAccountWithCache", 1); AssertAccount1(account2); int secondId = HashCodeProvider.GetIdentityHashCode(account2); Assert.AreEqual(firstId, secondId); }
public void TestJIRA242_WithoutGeneric_WithCache() { Account account1 = sqlMap.QueryForObject("GetNoAccountWithCache", 1) as Account; AssertAccount1(account1); int firstId = HashCodeProvider.GetIdentityHashCode(account1); Account account2 = sqlMap.QueryForObject("GetNoAccountWithCache", 1) as Account; AssertAccount1(account2); int secondId = HashCodeProvider.GetIdentityHashCode(account2); Assert.AreEqual(firstId, secondId); }
public void TestFlushDataCacheOnExecute() { IList list = dataMapper.QueryForList("Account.GetCachedAccountsViaResultMap", null); int firstId = HashCodeProvider.GetIdentityHashCode(list); list = dataMapper.QueryForList("Account.GetCachedAccountsViaResultMap", null); int secondId = HashCodeProvider.GetIdentityHashCode(list); Assert.AreEqual(firstId, secondId); dataMapper.Update("UpdateAccountViaInlineParameters", list[0]); list = dataMapper.QueryForList("Account.GetCachedAccountsViaResultMap", null); int thirdId = HashCodeProvider.GetIdentityHashCode(list); Assert.AreNotEqual(firstId, thirdId); }
public void TestCacheHit() { CacheModel cache = GetCacheModel(); CacheKey key = new CacheKey(); key.Update("testKey"); string value = "testValue"; cache[key] = value; object returnedObject = cache[key]; Assert.AreEqual(value, returnedObject); Assert.AreEqual(HashCodeProvider.GetIdentityHashCode(value), HashCodeProvider.GetIdentityHashCode(returnedObject)); }
/// <summary> /// Returns copy of cached object /// </summary> public void TestReturnCopyOfCachedOject() { ICacheController cacheController = new LruCacheController(); IDictionary props = new HybridDictionary(); props.Add("CacheSize", "1"); cacheController.Configure(props); FlushInterval interval = new FlushInterval(); interval.Hours = 1; interval.Initialize(); CacheModel cacheModel = new CacheModel(); cacheModel.FlushInterval = interval; cacheModel.CacheController = cacheController; cacheModel.IsReadOnly = false; cacheModel.IsSerializable = true; Order order = new Order(); order.CardNumber = "CardNumber"; order.Date = DateTime.Now; order.LineItemsCollection = new LineItemCollection(); LineItem item = new LineItem(); item.Code = "Code1"; order.LineItemsCollection.Add(item); item = new LineItem(); item.Code = "Code2"; order.LineItemsCollection.Add(item); CacheKey key = new CacheKey(); key.Update(order); int firstId = HashCodeProvider.GetIdentityHashCode(order); cacheModel[key] = order; Order order2 = cacheModel[key] as Order; int secondId = HashCodeProvider.GetIdentityHashCode(order2); Assert.AreNotEqual(firstId, secondId, "hasCode equal"); }
public void LRU_cache_should_work() { IList list = dataMapper.QueryForList("GetLruCachedAccountsViaResultMap", null); int firstId = HashCodeProvider.GetIdentityHashCode(list); list = dataMapper.QueryForList("GetLruCachedAccountsViaResultMap", null); int secondId = HashCodeProvider.GetIdentityHashCode(list); Assert.AreEqual(firstId, secondId); list = dataMapper.QueryForList("GetLruCachedAccountsViaResultMap", null); int thirdId = HashCodeProvider.GetIdentityHashCode(list); Assert.AreEqual(firstId, thirdId); }