private void Parse(XPathNavigator collectionCacheElement) { if (collectionCacheElement.MoveToFirstAttribute()) { do { switch (collectionCacheElement.Name) { case "collection": if (string.IsNullOrWhiteSpace(collectionCacheElement.Value)) { throw new HibernateConfigException("Invalid collection-cache element; the attribute <collection> must be assigned with no empty value"); } collection = collectionCacheElement.Value; break; case "usage": usage = EntityCacheUsageParser.Parse(collectionCacheElement.Value); break; case "region": region = collectionCacheElement.Value; break; } }while (collectionCacheElement.MoveToNextAttribute()); } }
public void CovertToString() { Assert.That(EntityCacheUsageParser.ToString(EntityCacheUsage.Readonly), Is.EqualTo("read-only")); Assert.That(EntityCacheUsageParser.ToString(EntityCacheUsage.ReadWrite), Is.EqualTo("read-write")); Assert.That(EntityCacheUsageParser.ToString(EntityCacheUsage.NonStrictReadWrite), Is.EqualTo("nonstrict-read-write")); Assert.That(EntityCacheUsageParser.ToString(EntityCacheUsage.Transactional), Is.EqualTo("transactional")); }
public void Parse() { Assert.That(EntityCacheUsageParser.Parse("read-only"), Is.EqualTo(EntityCacheUsage.Readonly)); Assert.That(EntityCacheUsageParser.Parse("read-write"), Is.EqualTo(EntityCacheUsage.ReadWrite)); Assert.That(EntityCacheUsageParser.Parse("nonstrict-read-write"), Is.EqualTo(EntityCacheUsage.NonStrictReadWrite)); Assert.That(EntityCacheUsageParser.Parse("transactional"), Is.EqualTo(EntityCacheUsage.Transactional)); }
private void Parse(XPathNavigator classCacheElement) { if (classCacheElement.MoveToFirstAttribute()) { do { switch (classCacheElement.Name) { case "class": if (string.IsNullOrWhiteSpace(classCacheElement.Value)) { throw new HibernateConfigException("Invalid class-cache element; the attribute <class> must be assigned with no empty value"); } clazz = classCacheElement.Value; break; case "usage": usage = EntityCacheUsageParser.Parse(classCacheElement.Value); break; case "region": region = classCacheElement.Value; break; case "include": include = CfgXmlHelper.ClassCacheIncludeConvertFrom(classCacheElement.Value); break; } }while (classCacheElement.MoveToNextAttribute()); } }
public static Configuration CacheEntity(this Configuration cfg, Type type) { cfg.SetCacheConcurrencyStrategy(type.FullName, EntityCacheUsageParser.ToString(EntityCacheUsage.NonStrictReadWrite), "My.DomainModel"); //foreach (var collection in ecc.Collections) //{ // configuration.SetCollectionCacheConcurrencyStrategy(collection.Key, // EntityCacheUsageParser.ToString(collection.Value.Strategy), collection.Value.RegionName); //} return(cfg); }
public void ConfigureCacheOfClass() { Configuration configure = new Configuration().Configure(); configure.AddResource("NHibernate.Test.CfgTest.Loquacious.EntityToCache.hbm.xml", GetType().Assembly); configure.EntityCache <EntityToCache>(ce => { ce.Strategy = EntityCacheUsage.NonStrictReadWrite; ce.RegionName = "MyRegion"; }); var pc = (RootClass)configure.GetClassMapping(typeof(EntityToCache)); Assert.That(pc.CacheConcurrencyStrategy, Is.EqualTo(EntityCacheUsageParser.ToString(EntityCacheUsage.NonStrictReadWrite))); Assert.That(pc.CacheRegionName, Is.EqualTo("MyRegion")); }
public static Configuration EntityCache <TEntity>(this Configuration configuration, Action <IEntityCacheConfigurationProperties <TEntity> > entityCacheConfiguration) where TEntity : class { var ecc = new EntityCacheConfigurationProperties <TEntity>(); entityCacheConfiguration(ecc); if (ecc.Strategy.HasValue) { configuration.SetCacheConcurrencyStrategy(typeof(TEntity).FullName, EntityCacheUsageParser.ToString(ecc.Strategy.Value), ecc.RegionName); } foreach (var collection in ecc.Collections) { configuration.SetCollectionCacheConcurrencyStrategy(collection.Key, EntityCacheUsageParser.ToString(collection.Value.Strategy), collection.Value.RegionName); } return(configuration); }
public void ConfigureCacheOfCollection() { Configuration configure = new Configuration().Configure(); configure.AddResource("NHibernate.Test.CfgTest.Loquacious.EntityToCache.hbm.xml", GetType().Assembly); configure.EntityCache <EntityToCache>(ce => { ce.Strategy = EntityCacheUsage.NonStrictReadWrite; ce.RegionName = "MyRegion"; ce.Collection(e => e.Elements, cc => { cc.RegionName = "MyCollectionRegion"; cc.Strategy = EntityCacheUsage.NonStrictReadWrite; }); }); Mapping.Collection pc = configure.GetCollectionMapping("NHibernate.Test.CfgTest.Loquacious.EntityToCache.Elements"); Assert.That(pc.CacheConcurrencyStrategy, Is.EqualTo(EntityCacheUsageParser.ToString(EntityCacheUsage.NonStrictReadWrite))); Assert.That(pc.CacheRegionName, Is.EqualTo("MyCollectionRegion")); }