|
From: <fab...@us...> - 2011-04-07 23:21:28
|
Revision: 5634
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=5634&view=rev
Author: fabiomaulo
Date: 2011-04-07 23:21:21 +0000 (Thu, 07 Apr 2011)
Log Message:
-----------
Fix NH-2632 + minor refactoring
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs
trunk/nhibernate/src/NHibernate/Tuple/Entity/EntityMetamodel.cs
trunk/nhibernate/src/NHibernate.Test/GhostProperty/GhostPropertyFixture.cs
trunk/nhibernate/src/NHibernate.Test/LazyProperty/LazyPropertyFixture.cs
trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2632/Fixture.cs
Modified: trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2011-04-07 20:44:05 UTC (rev 5633)
+++ trunk/nhibernate/src/NHibernate/Persister/Entity/AbstractEntityPersister.cs 2011-04-07 23:21:21 UTC (rev 5634)
@@ -332,7 +332,8 @@
#region PROPERTIES
- bool lazyAvailable = IsInstrumented(EntityMode.Poco);
+ // NH: see consistence with the implementation on EntityMetamodel where we are disabling lazy-properties for no lazy entities
+ bool lazyAvailable = IsInstrumented(EntityMode.Poco) && entityMetamodel.IsLazy;
int hydrateSpan = entityMetamodel.PropertySpan;
propertyColumnSpans = new int[hydrateSpan];
Modified: trunk/nhibernate/src/NHibernate/Tuple/Entity/EntityMetamodel.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Tuple/Entity/EntityMetamodel.cs 2011-04-07 20:44:05 UTC (rev 5633)
+++ trunk/nhibernate/src/NHibernate/Tuple/Entity/EntityMetamodel.cs 2011-04-07 23:21:21 UTC (rev 5634)
@@ -8,6 +8,7 @@
using NHibernate.Mapping;
using NHibernate.Type;
using NHibernate.Util;
+using Array = NHibernate.Mapping.Array;
namespace NHibernate.Tuple.Entity
{
@@ -126,19 +127,47 @@
bool foundUpdateGeneratedValue = false;
bool foundNonIdentifierPropertyNamedId = false;
HasPocoRepresentation = persistentClass.HasPocoRepresentation;
+
+ // NH: WARNING if we have to disable lazy/unproxy properties we have to do it in the whole process.
+ lazy = persistentClass.IsLazy && (!persistentClass.HasPocoRepresentation || !ReflectHelper.IsFinalClass(persistentClass.ProxyInterface));
+ lazyAvailable &= lazy; // <== Disable lazy properties if the class is marked with lazy=false
+
+ bool hadLazyProperties = false;
+ bool hadNoProxyRelations = false;
foreach (Mapping.Property prop in persistentClass.PropertyClosureIterator)
{
- // NH: A lazy property is a simple property marked with lazy=true or a relation (in this case many-to-one or one-to-one marked as "no-proxy")
- bool lazyProperty = prop.IsLazy && lazyAvailable && (!prop.IsEntityRelation || prop.UnwrapProxy);
+ if (prop.IsLazy)
+ {
+ hadLazyProperties = true;
+ }
+ if(prop.UnwrapProxy)
+ {
+ hadNoProxyRelations = true;
+ }
+ // NH: A lazy property is a simple property marked with lazy=true
+ bool islazyProperty = prop.IsLazy && lazyAvailable && (!prop.IsEntityRelation || prop.UnwrapProxy);
+ // NH: A Relation (in this case many-to-one or one-to-one) marked as "no-proxy"
+ var isUnwrapProxy = prop.UnwrapProxy && lazyAvailable;
+
+ if (islazyProperty || isUnwrapProxy)
+ {
+ // NH: verify property proxiability
+ var getter = prop.GetGetter(persistentClass.MappedClass);
+ if (getter.Method == null || getter.Method.IsDefined(typeof(CompilerGeneratedAttribute), false) == false)
+ {
+ log.ErrorFormat("Lazy or no-proxy property {0}.{1} is not an auto property, which may result in uninitialized property access", persistentClass.EntityName, prop.Name);
+ }
+ }
+
if (prop == persistentClass.Version)
{
tempVersionProperty = i;
- properties[i] = PropertyFactory.BuildVersionProperty(prop, lazyProperty);
+ properties[i] = PropertyFactory.BuildVersionProperty(prop, islazyProperty);
}
else
{
- properties[i] = PropertyFactory.BuildStandardProperty(prop, lazyProperty);
+ properties[i] = PropertyFactory.BuildStandardProperty(prop, islazyProperty);
}
if (prop.IsNaturalIdentifier)
@@ -151,16 +180,16 @@
foundNonIdentifierPropertyNamedId = true;
}
- if (lazyProperty)
+ if (islazyProperty)
{
hasLazy = true;
}
- if (prop.UnwrapProxy)
+ if (isUnwrapProxy)
{
hasUnwrapProxyForProperties = true;
}
- propertyLaziness[i] = lazyProperty;
+ propertyLaziness[i] = islazyProperty;
propertyNames[i] = properties[i].Name;
propertyTypes[i] = properties[i].Type;
@@ -170,7 +199,7 @@
insertInclusions[i] = DetermineInsertValueGenerationType(prop, properties[i]);
updateInclusions[i] = DetermineUpdateValueGenerationType(prop, properties[i]);
propertyVersionability[i] = properties[i].IsVersionable;
- nonlazyPropertyUpdateability[i] = properties[i].IsUpdateable && !lazyProperty;
+ nonlazyPropertyUpdateability[i] = properties[i].IsUpdateable && !islazyProperty;
propertyCheckability[i] = propertyUpdateability[i]
||
(propertyTypes[i].IsAssociationType
@@ -224,36 +253,24 @@
versionPropertyIndex = tempVersionProperty;
hasLazyProperties = hasLazy;
- lazy = persistentClass.IsLazy
- && (!persistentClass.HasPocoRepresentation || !ReflectHelper.IsFinalClass(persistentClass.ProxyInterface));
+ if(hadLazyProperties && !hasLazy)
+ {
+ log.WarnFormat("Disabled lazy properies fetching for {0} beacuse it does not support lazy at the entity level", name);
+ }
if (hasLazy)
{
- if (lazy == false)
- {
- log.WarnFormat("Disabled lazy properies fetching for {0} beacuse it does not support lazy at the entity level", name);
- hasLazyProperties = false;
- }
- else
- {
- log.Info("lazy property fetching available for: " + name);
- VerifyCanInterceptPropertiesForLazyOrGhostProperties(persistentClass);
- }
+ log.Info("lazy property fetching available for: " + name);
}
- if(hasUnwrapProxyForProperties)
+
+ if(hadNoProxyRelations && !hasUnwrapProxyForProperties)
{
- if (lazy == false)
- {
- log.WarnFormat("Disabled ghost properies fetching for {0} beacuse it does not support lazy at the entity level", name);
- hasUnwrapProxyForProperties = false;
- }
- else
- {
- log.Info("Ghost property fetching available for: " + name);
- if (hasLazy == false) // avoid double checking
- VerifyCanInterceptPropertiesForLazyOrGhostProperties(persistentClass);
- }
+ log.WarnFormat("Disabled ghost properies fetching for {0} beacuse it does not support lazy at the entity level", name);
}
+ if (hasUnwrapProxyForProperties)
+ {
+ log.Info("no-proxy property fetching available for: " + name);
+ }
mutable = persistentClass.IsMutable;
@@ -303,23 +320,6 @@
public bool HasPocoRepresentation { get; private set; }
- private static void VerifyCanInterceptPropertiesForLazyOrGhostProperties(PersistentClass persistentClass)
- {
- foreach (var prop in persistentClass.PropertyClosureIterator)
- {
- if (prop.IsLazy == false &&
- prop.UnwrapProxy == false)
- continue;
-
- var getter = prop.GetGetter(persistentClass.MappedClass);
- if(getter.Method == null ||
- getter.Method.IsDefined(typeof(CompilerGeneratedAttribute), false) == false)
- {
- log.ErrorFormat("Lazy or ghost property {0}.{1} is not an auto property, which may result in uninitialized property access", persistentClass.EntityName, prop.Name);
- }
- }
- }
-
private ValueInclusion DetermineInsertValueGenerationType(Mapping.Property mappingProperty, StandardProperty runtimeProperty)
{
if (runtimeProperty.IsInsertGenerated)
Modified: trunk/nhibernate/src/NHibernate.Test/GhostProperty/GhostPropertyFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/GhostProperty/GhostPropertyFixture.cs 2011-04-07 20:44:05 UTC (rev 5633)
+++ trunk/nhibernate/src/NHibernate.Test/GhostProperty/GhostPropertyFixture.cs 2011-04-07 23:21:21 UTC (rev 5634)
@@ -69,7 +69,7 @@
[Test]
public void ShouldGenerateErrorForNonAutoPropGhostProp()
{
- Assert.IsTrue(log.Contains("Lazy or ghost property NHibernate.Test.GhostProperty.Order.Payment is not an auto property, which may result in uninitialized property access"));
+ Assert.IsTrue(log.Contains("NHibernate.Test.GhostProperty.Order.Payment is not an auto property, which may result in uninitialized property access"));
}
[Test]
Modified: trunk/nhibernate/src/NHibernate.Test/LazyProperty/LazyPropertyFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/LazyProperty/LazyPropertyFixture.cs 2011-04-07 20:44:05 UTC (rev 5633)
+++ trunk/nhibernate/src/NHibernate.Test/LazyProperty/LazyPropertyFixture.cs 2011-04-07 23:21:21 UTC (rev 5634)
@@ -76,7 +76,7 @@
[Test]
public void ShouldGenerateErrorForNonAutoPropLazyProp()
{
- Assert.IsTrue(log.Contains("Lazy or ghost property NHibernate.Test.LazyProperty.Book.ALotOfText is not an auto property, which may result in uninitialized property access"));
+ Assert.IsTrue(log.Contains("NHibernate.Test.LazyProperty.Book.ALotOfText is not an auto property, which may result in uninitialized property access"));
}
[Test]
Modified: trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2632/Fixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2632/Fixture.cs 2011-04-07 20:44:05 UTC (rev 5633)
+++ trunk/nhibernate/src/NHibernate.Test/NHSpecificTest/NH2632/Fixture.cs 2011-04-07 23:21:21 UTC (rev 5634)
@@ -86,7 +86,7 @@
}
}
- [Test, Ignore("Not fixed yet")]
+ [Test]
public void GettingCustomerDoesNotThrow()
{
using (var scenario = new Scenario(Sfi))
@@ -95,7 +95,9 @@
{
Customer customer = null;
Executing.This(()=> customer = session.Get<Customer>(scenario.CustomerId)).Should().NotThrow();
- NHibernateUtil.IsInitialized(customer.Address).Should().Be.False();
+ // An entity defined with lazy=false can't have lazy properties (as reported by the WARNING; see EntityMetamodel class)
+ NHibernateUtil.IsInitialized(customer.Address).Should().Be.True();
+ customer.Address.Should().Be("Bah?!??");
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|