Skip to content

Commit

Permalink
- Added conventional override of default-lazy=false
Browse files Browse the repository at this point in the history
- Removed some derelict files that were in SVN, but not actually included in the CSPROJ files (AutoMapXmlCreationTester.cs and MappingTests.cs)

git-svn-id: https://fluent-nhibernate.googlecode.com/svn/trunk@139 48f0ce17-cc52-0410-af8c-857c09b6549b
  • Loading branch information
chadmyers committed Dec 6, 2008
1 parent 4eb6026 commit 032349c
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 129 deletions.

This file was deleted.

Expand Up @@ -512,6 +512,38 @@ public void ShouldAddRenameAttributeWhenDifferentNameSpecified()
.ForMapping(x => x.ImportType<SecondMappedObject>().As("MappedObject"))
.Element("import").HasAttribute("rename", "MappedObject");
}

[Test]
public void DefaultLazyLoad_should_be_false_by_default_for_compatibility()
{
new MappingTester<MappedObject>()
.ForMapping(c => { })
.HasAttribute("default-lazy", "false");
}

[Test]
public void DefaultLazyLoad_should_be_true_if_set_by_convention()
{
var visitor = new MappingVisitor();
visitor.Conventions.DefaultLazyLoad = true;

new MappingTester<MappedObject>()
.UsingVisitor(visitor)
.ForMapping(c => { })
.HasAttribute("default-lazy", "true");
}

[Test]
public void DefaultLazyLoad_convention_should_not_override_direct_setting_on_classmap()
{
var visitor = new MappingVisitor();
visitor.Conventions.DefaultLazyLoad = false;

new MappingTester<MappedObject>()
.UsingVisitor(visitor)
.ForMapping(c =>c.SetHibernateMappingAttribute(ClassMap<MappedObject>.DefaultLazyAttributeKey, "false"))
.HasAttribute("default-lazy", "false");
}
}

public class SecondMappedObject
Expand Down
Expand Up @@ -45,6 +45,12 @@ public void add_property_convention_for_type_of_attribute()
conventions.AlterMap(property);
}
}

[Test]
public void DefaultLazyLoad_should_be_false_by_default_for_compatibility()
{
new Conventions().DefaultLazyLoad.ShouldBeFalse();
}
}

public class Invoice{}
Expand Down
18 changes: 0 additions & 18 deletions src/FluentNHibernate.Testing/Mapping/MappingTests.cs

This file was deleted.

3 changes: 3 additions & 0 deletions src/FluentNHibernate/Conventions.cs
Expand Up @@ -102,6 +102,7 @@ public void AlterJoin(IMappingPart part)
_propertyConventions.Add(convention);
}


public Func<PropertyInfo,bool> FindIdentity = p => p.Name == "Id";

public Action<IOneToManyPart> OneToManyConvention = m => {};
Expand All @@ -110,5 +111,7 @@ public void AlterJoin(IMappingPart part)
public Action<IMappingPart> OneToOneConvention = m => { };

public Func<PropertyInfo, string> GetVersionColumnName;

public bool DefaultLazyLoad;
}
}
23 changes: 18 additions & 5 deletions src/FluentNHibernate/Mapping/ClassMap.cs
Expand Up @@ -10,6 +10,7 @@ namespace FluentNHibernate.Mapping
{
public class ClassMap<T> : ClassMapBase<T>, IMapping, IHasAttributes
{
public const string DefaultLazyAttributeKey = "default-lazy";
private readonly Cache<string, string> attributes = new Cache<string, string>();
private readonly Cache<string, string> hibernateMappingAttributes = new Cache<string, string>();
private readonly AccessStrategyBuilder<ClassMap<T>> defaultAccess;
Expand All @@ -27,7 +28,7 @@ public XmlDocument CreateMapping(IMappingVisitor visitor)
{
visitor.CurrentType = typeof(T);
XmlDocument document = getBaseDocument();
setHeaderValues(document);
setHeaderValues(visitor, document);

foreach (var import in imports)
{
Expand All @@ -36,6 +37,7 @@ public XmlDocument CreateMapping(IMappingVisitor visitor)

XmlElement classElement = createClassValues(document, document.DocumentElement);


writeTheParts(classElement, visitor);

return document;
Expand Down Expand Up @@ -67,12 +69,23 @@ protected virtual XmlElement createClassValues(XmlDocument document, XmlNode par
.WithProperties(attributes);
}

private void setHeaderValues(XmlDocument document)
private void setHeaderValues(IMappingVisitor visitor, XmlDocument document)
{
document.DocumentElement.SetAttribute("assembly", typeof (T).Assembly.GetName().Name);
document.DocumentElement.SetAttribute("namespace", typeof (T).Namespace);
var documentElement = document.DocumentElement;

//TODO: Law of Demeter violation here. The convention stuff smells, perhaps some double-dispatch is in order?
var defaultLazyValue = visitor.Conventions.DefaultLazyLoad.ToString().ToLowerInvariant();

if (!hibernateMappingAttributes.Has(DefaultLazyAttributeKey))
{
documentElement.SetAttribute(DefaultLazyAttributeKey, defaultLazyValue);
}

documentElement.SetAttribute("assembly", typeof(T).Assembly.GetName().Name);
documentElement.SetAttribute("assembly", typeof (T).Assembly.GetName().Name);
documentElement.SetAttribute("namespace", typeof (T).Namespace);

hibernateMappingAttributes.ForEachPair((name,value) => document.DocumentElement.SetAttribute(name, value));
hibernateMappingAttributes.ForEachPair(documentElement.SetAttribute);
}

private static XmlDocument getBaseDocument()
Expand Down
2 changes: 1 addition & 1 deletion src/FluentNHibernate/Mapping/Template.xml
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false">
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">

</hibernate-mapping>

0 comments on commit 032349c

Please sign in to comment.