From: <aye...@us...> - 2010-01-26 09:25:33
|
Revision: 4931 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4931&view=rev Author: ayenderahien Date: 2010-01-26 09:25:25 +0000 (Tue, 26 Jan 2010) Log Message: ----------- Simplifying no-proxy implementation, adding comments to point out differences from hibernate Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Intercept/AbstractFieldInterceptor.cs trunk/nhibernate/src/NHibernate/Mapping/Property.cs trunk/nhibernate/src/NHibernate.Test/GhostProperty/GhostPropertyFixture.cs Modified: trunk/nhibernate/src/NHibernate/Intercept/AbstractFieldInterceptor.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Intercept/AbstractFieldInterceptor.cs 2010-01-25 21:57:55 UTC (rev 4930) +++ trunk/nhibernate/src/NHibernate/Intercept/AbstractFieldInterceptor.cs 2010-01-26 09:25:25 UTC (rev 4931) @@ -13,7 +13,8 @@ [NonSerialized] private ISessionImplementor session; private ISet<string> uninitializedFields; - private ISet<string> unwrapProxyFieldNames; + private readonly ISet<string> unwrapProxyFieldNames; + private readonly ISet<string> loadedUnwrapProxyFieldNames = new HashedSet<string>(); private readonly string entityName; [NonSerialized] @@ -47,6 +48,10 @@ public bool IsInitializedField(string field) { + if (unwrapProxyFieldNames != null && unwrapProxyFieldNames.Contains(field)) + { + return loadedUnwrapProxyFieldNames.Contains(field); + } return uninitializedFields == null || !uninitializedFields.Contains(field); } @@ -77,6 +82,8 @@ get { return initializing; } } + // NH Specific: Hibernate only deals with lazy properties here, we deal with + // both lazy properties and with no-proxy. public object Intercept(object target, string fieldName, object value) { if (initializing) @@ -97,25 +104,18 @@ } if (value is INHibernateProxy && unwrapProxyFieldNames != null && unwrapProxyFieldNames.Contains(fieldName)) { - return InitializeOrGetAssociation((INHibernateProxy)value); + return InitializeOrGetAssociation((INHibernateProxy)value, fieldName); } return InvokeImplementation; } - private object InitializeOrGetAssociation(INHibernateProxy value) + private object InitializeOrGetAssociation(INHibernateProxy value, string fieldName) { if(value.HibernateLazyInitializer.IsUninitialized) { value.HibernateLazyInitializer.Initialize(); - var association = value.HibernateLazyInitializer.GetImplementation(session); - //var narrowedProxy = session.PersistenceContext.ProxyFor(association); - // we set the narrowed impl here to be able to get it back in the future - value.HibernateLazyInitializer.SetImplementation(association); - var entityPersister = session.GetEntityPersister(value.HibernateLazyInitializer.EntityName, value); - var key = new EntityKey(value.HibernateLazyInitializer.Identifier, - entityPersister, - session.EntityMode); - session.PersistenceContext.RemoveProxy(key); + value.HibernateLazyInitializer.Unwrap = true; // means that future Load/Get from the session will get the implementation + loadedUnwrapProxyFieldNames.Add(fieldName); } return value.HibernateLazyInitializer.GetImplementation(session); } Modified: trunk/nhibernate/src/NHibernate/Mapping/Property.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Mapping/Property.cs 2010-01-25 21:57:55 UTC (rev 4930) +++ trunk/nhibernate/src/NHibernate/Mapping/Property.cs 2010-01-26 09:25:25 UTC (rev 4931) @@ -261,28 +261,10 @@ { get { - if (propertyValue is ToOne) - { - // both many-to-one and one-to-one are represented as a - // Property. EntityPersister is relying on this value to - // determine "lazy fetch groups" in terms of field-level - // interception. So we need to make sure that we return - // true here for the case of many-to-one and one-to-one - // with lazy="no-proxy" - // - // * impl note - lazy="no-proxy" currently forces both - // lazy and unwrap to be set to true. The other case we - // are extremely interested in here is that of lazy="proxy" - // where lazy is set to true, but unwrap is set to false. - // thus we use both here under the assumption that this - // return is really only ever used during persister - // construction to determine the lazy property/field fetch - // groupings. If that assertion changes then this check - // needs to change as well. Partially, this is an issue with - // the overloading of the term "lazy" here... - ToOne toOneValue = (ToOne)propertyValue; - return toOneValue.IsLazy && toOneValue.UnwrapProxy; - } + // NH Specific: Hibernate doesn't make a distinction between + // lazy and no-proxy, but NHibernate does. While Hibernate tracks + // just whatever a property is lazy, we need to track lazy/no-proxy seperatedly. + return isLazy; } set { isLazy = value; } @@ -305,6 +287,12 @@ set { nodeName = value; } } + // both many-to-one and one-to-one are represented as a + // Property. EntityPersister is relying on this value to + // determine "lazy fetch groups" in terms of field-level + // interception. So we need to make sure that we return + // true here for the case of many-to-one and one-to-one + // with lazy="no-proxy" public bool UnwrapProxy { get; set; } } } Modified: trunk/nhibernate/src/NHibernate.Test/GhostProperty/GhostPropertyFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/GhostProperty/GhostPropertyFixture.cs 2010-01-25 21:57:55 UTC (rev 4930) +++ trunk/nhibernate/src/NHibernate.Test/GhostProperty/GhostPropertyFixture.cs 2010-01-26 09:25:25 UTC (rev 4931) @@ -67,6 +67,16 @@ } [Test] + public void WillNotLoadGhostPropertyByDefault() + { + using (ISession s = OpenSession()) + { + var order = s.Get<Order>(1); + Assert.IsFalse(NHibernateUtil.IsPropertyInitialized(order, "Payment")); + } + } + + [Test] public void GhostPropertyMaintainIdentityMap() { using (ISession s = OpenSession()) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |