From: <aye...@us...> - 2008-10-10 00:08:16
|
Revision: 3825 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=3825&view=rev Author: ayenderahien Date: 2008-10-10 00:08:11 +0000 (Fri, 10 Oct 2008) Log Message: ----------- Initial implementation of static proxies This is likely breaking NHibernate, and it is not production quality code. You need to have postsharp installed and to modify the post build process in VS to get this to work. Modified Paths: -------------- branches/static-proxies/src/NHibernate/Bytecode/DefaultProxyFactoryFactory.cs branches/static-proxies/src/NHibernate/Bytecode/IProxyFactoryFactory.cs branches/static-proxies/src/NHibernate/Cfg/Configuration.cs branches/static-proxies/src/NHibernate/Engine/StatefulPersistenceContext.cs branches/static-proxies/src/NHibernate/Event/Default/DefaultSaveEventListener.cs branches/static-proxies/src/NHibernate/InvalidProxyTypeException.cs branches/static-proxies/src/NHibernate/NHibernate.csproj branches/static-proxies/src/NHibernate/NHibernateUtil.cs branches/static-proxies/src/NHibernate/Tuple/Entity/PocoEntityTuplizer.cs branches/static-proxies/src/NHibernate/Type/GenericSetType.cs branches/static-proxies/src/NHibernate.Test/NHSpecificTest/NH1464/Fixture.cs branches/static-proxies/src/NHibernate.Test/NHSpecificTest/ProxyValidator/Fixture.cs branches/static-proxies/src/NHibernate.Test/ProxyInterface/CustomProxyFixture.cs branches/static-proxies/src/NHibernate.sln Added Paths: ----------- branches/static-proxies/src/NHibernate/Proxy/DynamicProxyTypeValidator.cs branches/static-proxies/src/NHibernate/Proxy/IProxyTypeValidator.cs branches/static-proxies/src/NHibernate.PostSharp.Proxies/ branches/static-proxies/src/NHibernate.PostSharp.Proxies/AddNHibernateProxyAttribute.cs branches/static-proxies/src/NHibernate.PostSharp.Proxies/IPostSharpNHibernateProxy.cs branches/static-proxies/src/NHibernate.PostSharp.Proxies/NHibernate.PostSharp.Proxies.csproj branches/static-proxies/src/NHibernate.PostSharp.Proxies/NHibernateLazyLoadingSupportAttribute.cs branches/static-proxies/src/NHibernate.PostSharp.Proxies/PostSharpInitializer.cs branches/static-proxies/src/NHibernate.PostSharp.Proxies/PostSharpProxyAdapter.cs branches/static-proxies/src/NHibernate.PostSharp.Proxies/PostSharpProxyFactory.cs branches/static-proxies/src/NHibernate.PostSharp.Proxies/PostSharpProxyFactoryFactory.cs branches/static-proxies/src/NHibernate.PostSharp.Proxies/PostSharpProxyValidator.cs branches/static-proxies/src/NHibernate.PostSharp.Proxies/Properties/ branches/static-proxies/src/NHibernate.PostSharp.Proxies/Properties/AssemblyInfo.cs branches/static-proxies/src/NHibernate.PostSharp.Proxies.Tests/ branches/static-proxies/src/NHibernate.PostSharp.Proxies.Tests/Address.cs branches/static-proxies/src/NHibernate.PostSharp.Proxies.Tests/Address.hbm.xml branches/static-proxies/src/NHibernate.PostSharp.Proxies.Tests/App.config branches/static-proxies/src/NHibernate.PostSharp.Proxies.Tests/CanCreateNHibernateSessionFactoryWithLazyLoadingAndNoVirtuals.cs branches/static-proxies/src/NHibernate.PostSharp.Proxies.Tests/ClassesAreWeavedCorrectly.cs branches/static-proxies/src/NHibernate.PostSharp.Proxies.Tests/Customer.cs branches/static-proxies/src/NHibernate.PostSharp.Proxies.Tests/Customer.hbm.xml branches/static-proxies/src/NHibernate.PostSharp.Proxies.Tests/LoadingInstancesFromTheDatabase.cs branches/static-proxies/src/NHibernate.PostSharp.Proxies.Tests/NHibernate.PostSharp.Proxies.Tests.csproj branches/static-proxies/src/NHibernate.PostSharp.Proxies.Tests/Properties/ branches/static-proxies/src/NHibernate.PostSharp.Proxies.Tests/Properties/AssemblyInfo.cs branches/static-proxies/src/NHibernate.PostSharp.Proxies.Tests/SavingInstanceToDatabase.cs branches/static-proxies/src/NHibernate.PostSharp.Proxies.Tests/TestCase.cs Modified: branches/static-proxies/src/NHibernate/Bytecode/DefaultProxyFactoryFactory.cs =================================================================== --- branches/static-proxies/src/NHibernate/Bytecode/DefaultProxyFactoryFactory.cs 2008-10-09 23:48:30 UTC (rev 3824) +++ branches/static-proxies/src/NHibernate/Bytecode/DefaultProxyFactoryFactory.cs 2008-10-10 00:08:11 UTC (rev 3825) @@ -12,6 +12,11 @@ return new CastleProxyFactory(); } - #endregion + public IProxyTypeValidator Validator + { + get { return new DynamicProxyTypeValidator(); } + } + + #endregion } } Modified: branches/static-proxies/src/NHibernate/Bytecode/IProxyFactoryFactory.cs =================================================================== --- branches/static-proxies/src/NHibernate/Bytecode/IProxyFactoryFactory.cs 2008-10-09 23:48:30 UTC (rev 3824) +++ branches/static-proxies/src/NHibernate/Bytecode/IProxyFactoryFactory.cs 2008-10-10 00:08:11 UTC (rev 3825) @@ -16,6 +16,9 @@ /// </summary> /// <returns> The lazy-load proxy factory. </returns> IProxyFactory BuildProxyFactory(); + + IProxyTypeValidator Validator { get; } + /* /// <summary> Build a proxy factory for basic proxy concerns. The return /// should be capable of properly handling newInstance() calls. Modified: branches/static-proxies/src/NHibernate/Cfg/Configuration.cs =================================================================== --- branches/static-proxies/src/NHibernate/Cfg/Configuration.cs 2008-10-09 23:48:30 UTC (rev 3824) +++ branches/static-proxies/src/NHibernate/Cfg/Configuration.cs 2008-10-10 00:08:11 UTC (rev 3825) @@ -787,19 +787,19 @@ private void Validate() { bool validateProxy = PropertiesHelper.GetBoolean(Environment.UseProxyValidator, properties, true); - HashedSet allProxyErrors = null; + HashedSet<string> allProxyErrors = null; foreach (PersistentClass clazz in classes.Values) { clazz.Validate(mapping); if (validateProxy) { - ICollection errors = ValidateProxyInterface(clazz); + ICollection<string> errors = ValidateProxyInterface(clazz); if (errors != null) { if (allProxyErrors == null) { - allProxyErrors = new HashedSet(errors); + allProxyErrors = new HashedSet<string>(errors); } else { @@ -820,21 +820,9 @@ } } - private static ICollection ValidateProxyInterface(PersistentClass persistentClass) + private static ICollection<string> ValidateProxyInterface(PersistentClass persistentClass) { - if (!persistentClass.IsLazy) - { - // Nothing to validate - return null; - } - - if (persistentClass.ProxyInterface == null) - { - // Nothing to validate - return null; - } - - return ProxyTypeValidator.ValidateType(persistentClass.ProxyInterface); + return Environment.BytecodeProvider.ProxyFactoryFactory.Validator.ValidateType(persistentClass); } /// <summary> Modified: branches/static-proxies/src/NHibernate/Engine/StatefulPersistenceContext.cs =================================================================== --- branches/static-proxies/src/NHibernate/Engine/StatefulPersistenceContext.cs 2008-10-09 23:48:30 UTC (rev 3824) +++ branches/static-proxies/src/NHibernate/Engine/StatefulPersistenceContext.cs 2008-10-10 00:08:11 UTC (rev 3825) @@ -17,1231 +17,1233 @@ namespace NHibernate.Engine { - /// <summary> - /// A <see cref="IPersistenceContext"/> represents the state of persistent "stuff" which - /// NHibernate is tracking. This includes persistent entities, collections, - /// as well as proxies generated. - /// </summary> - /// <remarks> - /// There is meant to be a one-to-one correspondence between a SessionImpl and - /// a PersistentContext. The SessionImpl uses the PersistentContext to track - /// the current state of its context. Event-listeners then use the - /// PersistentContext to drive their processing. - /// </remarks> - [Serializable] - public class StatefulPersistenceContext : IPersistenceContext, ISerializable, IDeserializationCallback - { - private const int InitCollectionSize = 8; - private static readonly ILog log = LogManager.GetLogger(typeof(StatefulPersistenceContext)); - private static readonly ILog ProxyWarnLog = LogManager.GetLogger(typeof(StatefulPersistenceContext).FullName + ".ProxyWarnLog"); + /// <summary> + /// A <see cref="IPersistenceContext"/> represents the state of persistent "stuff" which + /// NHibernate is tracking. This includes persistent entities, collections, + /// as well as proxies generated. + /// </summary> + /// <remarks> + /// There is meant to be a one-to-one correspondence between a SessionImpl and + /// a PersistentContext. The SessionImpl uses the PersistentContext to track + /// the current state of its context. Event-listeners then use the + /// PersistentContext to drive their processing. + /// </remarks> + [Serializable] + public class StatefulPersistenceContext : IPersistenceContext, ISerializable, IDeserializationCallback + { + private const int InitCollectionSize = 8; + private static readonly ILog log = LogManager.GetLogger(typeof(StatefulPersistenceContext)); + private static readonly ILog ProxyWarnLog = LogManager.GetLogger(typeof(StatefulPersistenceContext).FullName + ".ProxyWarnLog"); - public static readonly object NoRow = new object(); + public static readonly object NoRow = new object(); - [NonSerialized] - private ISessionImplementor session; + [NonSerialized] + private ISessionImplementor session; - // Loaded entity instances, by EntityKey - private readonly Dictionary<EntityKey, object> entitiesByKey; + // Loaded entity instances, by EntityKey + private readonly Dictionary<EntityKey, object> entitiesByKey; - // Loaded entity instances, by EntityUniqueKey - private readonly Dictionary<EntityUniqueKey, object> entitiesByUniqueKey; + // Loaded entity instances, by EntityUniqueKey + private readonly Dictionary<EntityUniqueKey, object> entitiesByUniqueKey; - // Identity map of EntityEntry instances, by the entity instance - private readonly IDictionary entityEntries; + // Identity map of EntityEntry instances, by the entity instance + private readonly IDictionary entityEntries; - // Entity proxies, by EntityKey - private readonly Dictionary<EntityKey, INHibernateProxy> proxiesByKey; + // Entity proxies, by EntityKey + private readonly Dictionary<EntityKey, INHibernateProxy> proxiesByKey; - // Snapshots of current database state for entities - // that have *not* been loaded - private readonly Dictionary<EntityKey, object> entitySnapshotsByKey; + // Snapshots of current database state for entities + // that have *not* been loaded + private readonly Dictionary<EntityKey, object> entitySnapshotsByKey; - // Identity map of array holder ArrayHolder instances, by the array instance - private readonly IDictionary arrayHolders; + // Identity map of array holder ArrayHolder instances, by the array instance + private readonly IDictionary arrayHolders; - // Identity map of CollectionEntry instances, by the collection wrapper - private readonly IDictionary collectionEntries; + // Identity map of CollectionEntry instances, by the collection wrapper + private readonly IDictionary collectionEntries; - // Collection wrappers, by the CollectionKey - private readonly Dictionary<CollectionKey, IPersistentCollection> collectionsByKey; + // Collection wrappers, by the CollectionKey + private readonly Dictionary<CollectionKey, IPersistentCollection> collectionsByKey; - // Set of EntityKeys of deleted objects - private readonly HashedSet<EntityKey> nullifiableEntityKeys; + // Set of EntityKeys of deleted objects + private readonly HashedSet<EntityKey> nullifiableEntityKeys; - // properties that we have tried to load, and not found in the database - private ISet<AssociationKey> nullAssociations; + // properties that we have tried to load, and not found in the database + private ISet<AssociationKey> nullAssociations; - // A list of collection wrappers that were instantiating during result set - // processing, that we will need to initialize at the end of the query - [NonSerialized] - private List<IPersistentCollection> nonlazyCollections; + // A list of collection wrappers that were instantiating during result set + // processing, that we will need to initialize at the end of the query + [NonSerialized] + private List<IPersistentCollection> nonlazyCollections; - // A container for collections we load up when the owning entity is not - // yet loaded ... for now, this is purely transient! - private Dictionary<CollectionKey, IPersistentCollection> unownedCollections; + // A container for collections we load up when the owning entity is not + // yet loaded ... for now, this is purely transient! + private Dictionary<CollectionKey, IPersistentCollection> unownedCollections; - private bool hasNonReadOnlyEntities; + private bool hasNonReadOnlyEntities; - [NonSerialized] - private int cascading; + [NonSerialized] + private int cascading; - [NonSerialized] - private bool flushing; + [NonSerialized] + private bool flushing; - [NonSerialized] - private int loadCounter; + [NonSerialized] + private int loadCounter; - [NonSerialized] - private LoadContexts loadContexts; + [NonSerialized] + private LoadContexts loadContexts; - [NonSerialized] - private BatchFetchQueue batchFetchQueue; + [NonSerialized] + private BatchFetchQueue batchFetchQueue; - /// <summary> Constructs a PersistentContext, bound to the given session. </summary> - /// <param name="session">The session "owning" this context. </param> - public StatefulPersistenceContext(ISessionImplementor session) - { - loadCounter = 0; - flushing = false; - cascading = 0; - this.session = session; + /// <summary> Constructs a PersistentContext, bound to the given session. </summary> + /// <param name="session">The session "owning" this context. </param> + public StatefulPersistenceContext(ISessionImplementor session) + { + loadCounter = 0; + flushing = false; + cascading = 0; + this.session = session; - entitiesByKey = new Dictionary<EntityKey, object>(InitCollectionSize); - entitiesByUniqueKey = new Dictionary<EntityUniqueKey, object>(InitCollectionSize); - proxiesByKey = new Dictionary<EntityKey, INHibernateProxy>(InitCollectionSize); - entitySnapshotsByKey = new Dictionary<EntityKey, object>(InitCollectionSize); - entityEntries = IdentityMap.InstantiateSequenced(InitCollectionSize); - collectionEntries = IdentityMap.InstantiateSequenced(InitCollectionSize); - collectionsByKey = new Dictionary<CollectionKey, IPersistentCollection>(InitCollectionSize); - arrayHolders = IdentityMap.Instantiate(InitCollectionSize); - nullifiableEntityKeys = new HashedSet<EntityKey>(); - InitTransientState(); - } + entitiesByKey = new Dictionary<EntityKey, object>(InitCollectionSize); + entitiesByUniqueKey = new Dictionary<EntityUniqueKey, object>(InitCollectionSize); + proxiesByKey = new Dictionary<EntityKey, INHibernateProxy>(InitCollectionSize); + entitySnapshotsByKey = new Dictionary<EntityKey, object>(InitCollectionSize); + entityEntries = IdentityMap.InstantiateSequenced(InitCollectionSize); + collectionEntries = IdentityMap.InstantiateSequenced(InitCollectionSize); + collectionsByKey = new Dictionary<CollectionKey, IPersistentCollection>(InitCollectionSize); + arrayHolders = IdentityMap.Instantiate(InitCollectionSize); + nullifiableEntityKeys = new HashedSet<EntityKey>(); + InitTransientState(); + } - private void InitTransientState() - { - loadContexts = null; - nullAssociations = new HashedSet<AssociationKey>(); - nonlazyCollections = new List<IPersistentCollection>(InitCollectionSize); - } + private void InitTransientState() + { + loadContexts = null; + nullAssociations = new HashedSet<AssociationKey>(); + nonlazyCollections = new List<IPersistentCollection>(InitCollectionSize); + } - #region IPersistenceContext Members + #region IPersistenceContext Members - public bool IsStateless - { - get { return false; } - } + public bool IsStateless + { + get { return false; } + } - /// <summary> - /// Get the session to which this persistence context is bound. - /// </summary> - public ISessionImplementor Session - { - get { return session; } - } + /// <summary> + /// Get the session to which this persistence context is bound. + /// </summary> + public ISessionImplementor Session + { + get { return session; } + } - /// <summary> - /// Retrieve this persistence context's managed load context. - /// </summary> - public LoadContexts LoadContexts - { - get - { - if (loadContexts == null) - loadContexts = new LoadContexts(this); + /// <summary> + /// Retrieve this persistence context's managed load context. + /// </summary> + public LoadContexts LoadContexts + { + get + { + if (loadContexts == null) + loadContexts = new LoadContexts(this); - return loadContexts; - } - } + return loadContexts; + } + } - /// <summary> - /// Get the <tt>BatchFetchQueue</tt>, instantiating one if necessary. - /// </summary> - public BatchFetchQueue BatchFetchQueue - { - get - { - if (batchFetchQueue == null) - batchFetchQueue = new BatchFetchQueue(this); + /// <summary> + /// Get the <tt>BatchFetchQueue</tt>, instantiating one if necessary. + /// </summary> + public BatchFetchQueue BatchFetchQueue + { + get + { + if (batchFetchQueue == null) + batchFetchQueue = new BatchFetchQueue(this); - return batchFetchQueue; - } - } + return batchFetchQueue; + } + } - /// <summary> Retrieve the set of EntityKeys representing nullifiable references</summary> - public ISet NullifiableEntityKeys - { - get { return nullifiableEntityKeys; } - } + /// <summary> Retrieve the set of EntityKeys representing nullifiable references</summary> + public ISet NullifiableEntityKeys + { + get { return nullifiableEntityKeys; } + } - /// <summary> Get the mapping from key value to entity instance</summary> - public IDictionary<EntityKey, object> EntitiesByKey - { - get { return entitiesByKey; } - } + /// <summary> Get the mapping from key value to entity instance</summary> + public IDictionary<EntityKey, object> EntitiesByKey + { + get { return entitiesByKey; } + } - /// <summary> Get the mapping from entity instance to entity entry</summary> - public IDictionary EntityEntries - { - get { return entityEntries; } - } + /// <summary> Get the mapping from entity instance to entity entry</summary> + public IDictionary EntityEntries + { + get { return entityEntries; } + } - /// <summary> Get the mapping from collection instance to collection entry</summary> - public IDictionary CollectionEntries - { - get { return collectionEntries; } - } + /// <summary> Get the mapping from collection instance to collection entry</summary> + public IDictionary CollectionEntries + { + get { return collectionEntries; } + } - /// <summary> Get the mapping from collection key to collection instance</summary> - public IDictionary<CollectionKey, IPersistentCollection> CollectionsByKey - { - get { return collectionsByKey; } - } + /// <summary> Get the mapping from collection key to collection instance</summary> + public IDictionary<CollectionKey, IPersistentCollection> CollectionsByKey + { + get { return collectionsByKey; } + } - /// <summary> How deep are we cascaded?</summary> - public int CascadeLevel - { - get { return cascading; } - } + /// <summary> How deep are we cascaded?</summary> + public int CascadeLevel + { + get { return cascading; } + } - /// <summary>Is a flush cycle currently in process?</summary> - /// <remarks>Called before and after the flushcycle</remarks> - public bool Flushing - { - get { return flushing; } - set { flushing = value; } - } + /// <summary>Is a flush cycle currently in process?</summary> + /// <remarks>Called before and after the flushcycle</remarks> + public bool Flushing + { + get { return flushing; } + set { flushing = value; } + } - /// <summary> Add a collection which has no owner loaded</summary> - public void AddUnownedCollection(CollectionKey key, IPersistentCollection collection) - { - if (unownedCollections == null) - unownedCollections = new Dictionary<CollectionKey, IPersistentCollection>(8); + /// <summary> Add a collection which has no owner loaded</summary> + public void AddUnownedCollection(CollectionKey key, IPersistentCollection collection) + { + if (unownedCollections == null) + unownedCollections = new Dictionary<CollectionKey, IPersistentCollection>(8); - unownedCollections[key] = collection; - } + unownedCollections[key] = collection; + } - /// <summary> - /// Get and remove a collection whose owner is not yet loaded, - /// when its owner is being loaded - /// </summary> - public IPersistentCollection UseUnownedCollection(CollectionKey key) - { - if (unownedCollections == null) - { - return null; - } - else - { - IPersistentCollection tempObject; - if (unownedCollections.TryGetValue(key, out tempObject)) - unownedCollections.Remove(key); - return tempObject; - } - } + /// <summary> + /// Get and remove a collection whose owner is not yet loaded, + /// when its owner is being loaded + /// </summary> + public IPersistentCollection UseUnownedCollection(CollectionKey key) + { + if (unownedCollections == null) + { + return null; + } + else + { + IPersistentCollection tempObject; + if (unownedCollections.TryGetValue(key, out tempObject)) + unownedCollections.Remove(key); + return tempObject; + } + } - /// <summary> Clear the state of the persistence context</summary> - public void Clear() - { - foreach (INHibernateProxy proxy in proxiesByKey.Values) - { - proxy.HibernateLazyInitializer.Session = null; - } + /// <summary> Clear the state of the persistence context</summary> + public void Clear() + { + foreach (INHibernateProxy proxy in proxiesByKey.Values) + { + ILazyInitializer initializer = proxy.HibernateLazyInitializer; + if (initializer != null) + initializer.Session = null; + } - ICollection collectionEntryArray = IdentityMap.ConcurrentEntries(collectionEntries); - foreach (DictionaryEntry entry in collectionEntryArray) - { - ((IPersistentCollection)entry.Key).UnsetSession(Session); - } + ICollection collectionEntryArray = IdentityMap.ConcurrentEntries(collectionEntries); + foreach (DictionaryEntry entry in collectionEntryArray) + { + ((IPersistentCollection)entry.Key).UnsetSession(Session); + } - arrayHolders.Clear(); - entitiesByKey.Clear(); - entitiesByUniqueKey.Clear(); - entityEntries.Clear(); - entitySnapshotsByKey.Clear(); - collectionsByKey.Clear(); - collectionEntries.Clear(); - if (unownedCollections != null) - { - unownedCollections.Clear(); - } - proxiesByKey.Clear(); - nullifiableEntityKeys.Clear(); - if (batchFetchQueue != null) - { - batchFetchQueue.Clear(); - } - hasNonReadOnlyEntities = false; - if (loadContexts != null) - { - loadContexts.Cleanup(); - } - } + arrayHolders.Clear(); + entitiesByKey.Clear(); + entitiesByUniqueKey.Clear(); + entityEntries.Clear(); + entitySnapshotsByKey.Clear(); + collectionsByKey.Clear(); + collectionEntries.Clear(); + if (unownedCollections != null) + { + unownedCollections.Clear(); + } + proxiesByKey.Clear(); + nullifiableEntityKeys.Clear(); + if (batchFetchQueue != null) + { + batchFetchQueue.Clear(); + } + hasNonReadOnlyEntities = false; + if (loadContexts != null) + { + loadContexts.Cleanup(); + } + } - /// <summary>False if we know for certain that all the entities are read-only</summary> - public bool HasNonReadOnlyEntities - { - get { return hasNonReadOnlyEntities; } - } + /// <summary>False if we know for certain that all the entities are read-only</summary> + public bool HasNonReadOnlyEntities + { + get { return hasNonReadOnlyEntities; } + } - private void SetHasNonReadOnlyEnties(Status value) - { - if (value == Status.Deleted || value == Status.Loaded || value == Status.Saving) - { - hasNonReadOnlyEntities = true; - } - } + private void SetHasNonReadOnlyEnties(Status value) + { + if (value == Status.Deleted || value == Status.Loaded || value == Status.Saving) + { + hasNonReadOnlyEntities = true; + } + } - /// <summary> Set the status of an entry</summary> - public void SetEntryStatus(EntityEntry entry, Status status) - { - entry.Status = status; - SetHasNonReadOnlyEnties(status); - } + /// <summary> Set the status of an entry</summary> + public void SetEntryStatus(EntityEntry entry, Status status) + { + entry.Status = status; + SetHasNonReadOnlyEnties(status); + } - /// <summary> Called after transactions end</summary> - public void AfterTransactionCompletion() - { - // Downgrade locks - foreach (EntityEntry entityEntry in entityEntries.Values) - entityEntry.LockMode = LockMode.None; - } + /// <summary> Called after transactions end</summary> + public void AfterTransactionCompletion() + { + // Downgrade locks + foreach (EntityEntry entityEntry in entityEntries.Values) + entityEntry.LockMode = LockMode.None; + } - /// <summary> - /// Get the current state of the entity as known to the underlying - /// database, or null if there is no corresponding row - /// </summary> - public object[] GetDatabaseSnapshot(object id, IEntityPersister persister) - { - EntityKey key = new EntityKey(id, persister, session.EntityMode); - object cached; - if (entitySnapshotsByKey.TryGetValue(key, out cached)) - { - return cached == NoRow ? null : (object[])cached; - } - else - { - object[] snapshot = persister.GetDatabaseSnapshot(id, session); - entitySnapshotsByKey[key] = snapshot ?? NoRow; - return snapshot; - } - } + /// <summary> + /// Get the current state of the entity as known to the underlying + /// database, or null if there is no corresponding row + /// </summary> + public object[] GetDatabaseSnapshot(object id, IEntityPersister persister) + { + EntityKey key = new EntityKey(id, persister, session.EntityMode); + object cached; + if (entitySnapshotsByKey.TryGetValue(key, out cached)) + { + return cached == NoRow ? null : (object[])cached; + } + else + { + object[] snapshot = persister.GetDatabaseSnapshot(id, session); + entitySnapshotsByKey[key] = snapshot ?? NoRow; + return snapshot; + } + } - /// <summary> - /// Retrieve the cached database snapshot for the requested entity key. - /// </summary> - /// <param name="key">The entity key for which to retrieve the cached snapshot </param> - /// <returns> The cached snapshot </returns> - /// <remarks> - /// <list type="bullet"> - /// <listheader><description>This differs from <see cref="GetDatabaseSnapshot"/> is two important respects:</description></listheader> - /// <item><description>no snapshot is obtained from the database if not already cached</description></item> - /// <item><description>an entry of NO_ROW here is interpreted as an exception</description></item> - /// </list> - /// </remarks> - public object[] GetCachedDatabaseSnapshot(EntityKey key) - { - object snapshot; - if (!entitySnapshotsByKey.TryGetValue(key, out snapshot)) - return null; + /// <summary> + /// Retrieve the cached database snapshot for the requested entity key. + /// </summary> + /// <param name="key">The entity key for which to retrieve the cached snapshot </param> + /// <returns> The cached snapshot </returns> + /// <remarks> + /// <list type="bullet"> + /// <listheader><description>This differs from <see cref="GetDatabaseSnapshot"/> is two important respects:</description></listheader> + /// <item><description>no snapshot is obtained from the database if not already cached</description></item> + /// <item><description>an entry of NO_ROW here is interpreted as an exception</description></item> + /// </list> + /// </remarks> + public object[] GetCachedDatabaseSnapshot(EntityKey key) + { + object snapshot; + if (!entitySnapshotsByKey.TryGetValue(key, out snapshot)) + return null; - if (snapshot == NoRow) - { - throw new HibernateException("persistence context reported no row snapshot for " + MessageHelper.InfoString(key.EntityName, key.Identifier)); - } - return (object[])snapshot; - } + if (snapshot == NoRow) + { + throw new HibernateException("persistence context reported no row snapshot for " + MessageHelper.InfoString(key.EntityName, key.Identifier)); + } + return (object[])snapshot; + } - /// <summary> - /// Get the values of the natural id fields as known to the underlying - /// database, or null if the entity has no natural id or there is no - /// corresponding row. - /// </summary> - public object[] GetNaturalIdSnapshot(object id, IEntityPersister persister) - { - if (!persister.HasNaturalIdentifier) - { - return null; - } + /// <summary> + /// Get the values of the natural id fields as known to the underlying + /// database, or null if the entity has no natural id or there is no + /// corresponding row. + /// </summary> + public object[] GetNaturalIdSnapshot(object id, IEntityPersister persister) + { + if (!persister.HasNaturalIdentifier) + { + return null; + } - // if the natural-id is marked as non-mutable, it is not retrieved during a - // normal database-snapshot operation... - int[] props = persister.NaturalIdentifierProperties; - bool[] updateable = persister.PropertyUpdateability; - bool allNatualIdPropsAreUpdateable = true; - for (int i = 0; i < props.Length; i++) - { - if (!updateable[props[i]]) - { - allNatualIdPropsAreUpdateable = false; - break; - } - } + // if the natural-id is marked as non-mutable, it is not retrieved during a + // normal database-snapshot operation... + int[] props = persister.NaturalIdentifierProperties; + bool[] updateable = persister.PropertyUpdateability; + bool allNatualIdPropsAreUpdateable = true; + for (int i = 0; i < props.Length; i++) + { + if (!updateable[props[i]]) + { + allNatualIdPropsAreUpdateable = false; + break; + } + } - if (allNatualIdPropsAreUpdateable) - { - // do this when all the properties are updateable since there is - // a certain likelihood that the information will already be - // snapshot-cached. - object[] entitySnapshot = GetDatabaseSnapshot(id, persister); - if (entitySnapshot == NoRow) - { - return null; - } - object[] naturalIdSnapshot = new object[props.Length]; - for (int i = 0; i < props.Length; i++) - { - naturalIdSnapshot[i] = entitySnapshot[props[i]]; - } - return naturalIdSnapshot; - } - else - { - return persister.GetNaturalIdentifierSnapshot(id, session); - } - } + if (allNatualIdPropsAreUpdateable) + { + // do this when all the properties are updateable since there is + // a certain likelihood that the information will already be + // snapshot-cached. + object[] entitySnapshot = GetDatabaseSnapshot(id, persister); + if (entitySnapshot == NoRow) + { + return null; + } + object[] naturalIdSnapshot = new object[props.Length]; + for (int i = 0; i < props.Length; i++) + { + naturalIdSnapshot[i] = entitySnapshot[props[i]]; + } + return naturalIdSnapshot; + } + else + { + return persister.GetNaturalIdentifierSnapshot(id, session); + } + } - /// <summary> Add a canonical mapping from entity key to entity instance</summary> - public void AddEntity(EntityKey key, object entity) - { - entitiesByKey[key] = entity; - BatchFetchQueue.RemoveBatchLoadableEntityKey(key); - } + /// <summary> Add a canonical mapping from entity key to entity instance</summary> + public void AddEntity(EntityKey key, object entity) + { + entitiesByKey[key] = entity; + BatchFetchQueue.RemoveBatchLoadableEntityKey(key); + } - /// <summary> - /// Get the entity instance associated with the given <tt>EntityKey</tt> - /// </summary> - public object GetEntity(EntityKey key) - { - object result; - entitiesByKey.TryGetValue(key, out result); - return result; - } + /// <summary> + /// Get the entity instance associated with the given <tt>EntityKey</tt> + /// </summary> + public object GetEntity(EntityKey key) + { + object result; + entitiesByKey.TryGetValue(key, out result); + return result; + } - /// <summary> Is there an entity with the given key in the persistence context</summary> - public bool ContainsEntity(EntityKey key) - { - return entitiesByKey.ContainsKey(key); - } + /// <summary> Is there an entity with the given key in the persistence context</summary> + public bool ContainsEntity(EntityKey key) + { + return entitiesByKey.ContainsKey(key); + } - /// <summary> - /// Remove an entity from the session cache, also clear - /// up other state associated with the entity, all except - /// for the <tt>EntityEntry</tt> - /// </summary> - public object RemoveEntity(EntityKey key) - { - object tempObject = entitiesByKey[key]; - entitiesByKey.Remove(key); - object entity = tempObject; - List<EntityUniqueKey> toRemove = new List<EntityUniqueKey>(); - foreach (KeyValuePair<EntityUniqueKey, object> pair in entitiesByUniqueKey) - { - if (pair.Value == entity) toRemove.Add(pair.Key); - } - foreach (EntityUniqueKey uniqueKey in toRemove) - { - entitiesByUniqueKey.Remove(uniqueKey); - } + /// <summary> + /// Remove an entity from the session cache, also clear + /// up other state associated with the entity, all except + /// for the <tt>EntityEntry</tt> + /// </summary> + public object RemoveEntity(EntityKey key) + { + object tempObject = entitiesByKey[key]; + entitiesByKey.Remove(key); + object entity = tempObject; + List<EntityUniqueKey> toRemove = new List<EntityUniqueKey>(); + foreach (KeyValuePair<EntityUniqueKey, object> pair in entitiesByUniqueKey) + { + if (pair.Value == entity) toRemove.Add(pair.Key); + } + foreach (EntityUniqueKey uniqueKey in toRemove) + { + entitiesByUniqueKey.Remove(uniqueKey); + } - entitySnapshotsByKey.Remove(key); - nullifiableEntityKeys.Remove(key); - BatchFetchQueue.RemoveBatchLoadableEntityKey(key); - BatchFetchQueue.RemoveSubselect(key); - return entity; - } + entitySnapshotsByKey.Remove(key); + nullifiableEntityKeys.Remove(key); + BatchFetchQueue.RemoveBatchLoadableEntityKey(key); + BatchFetchQueue.RemoveSubselect(key); + return entity; + } - /// <summary> Get an entity cached by unique key</summary> - public object GetEntity(EntityUniqueKey euk) - { - object result; - entitiesByUniqueKey.TryGetValue(euk, out result); - return result; - } + /// <summary> Get an entity cached by unique key</summary> + public object GetEntity(EntityUniqueKey euk) + { + object result; + entitiesByUniqueKey.TryGetValue(euk, out result); + return result; + } - /// <summary> Add an entity to the cache by unique key</summary> - public void AddEntity(EntityUniqueKey euk, object entity) - { - entitiesByUniqueKey[euk] = entity; - } + /// <summary> Add an entity to the cache by unique key</summary> + public void AddEntity(EntityUniqueKey euk, object entity) + { + entitiesByUniqueKey[euk] = entity; + } - /// <summary> - /// Retrieve the EntityEntry representation of the given entity. - /// </summary> - /// <param name="entity">The entity for which to locate the EntityEntry. </param> - /// <returns> The EntityEntry for the given entity. </returns> - public EntityEntry GetEntry(object entity) - { - return (EntityEntry)entityEntries[entity]; - } + /// <summary> + /// Retrieve the EntityEntry representation of the given entity. + /// </summary> + /// <param name="entity">The entity for which to locate the EntityEntry. </param> + /// <returns> The EntityEntry for the given entity. </returns> + public EntityEntry GetEntry(object entity) + { + return (EntityEntry)entityEntries[entity]; + } - /// <summary> Remove an entity entry from the session cache</summary> - public EntityEntry RemoveEntry(object entity) - { - EntityEntry tempObject = (EntityEntry)entityEntries[entity]; - entityEntries.Remove(entity); - return tempObject; - } + /// <summary> Remove an entity entry from the session cache</summary> + public EntityEntry RemoveEntry(object entity) + { + EntityEntry tempObject = (EntityEntry)entityEntries[entity]; + entityEntries.Remove(entity); + return tempObject; + } - /// <summary> Is there an EntityEntry for this instance?</summary> - public bool IsEntryFor(object entity) - { - return entityEntries.Contains(entity); - } + /// <summary> Is there an EntityEntry for this instance?</summary> + public bool IsEntryFor(object entity) + { + return entityEntries.Contains(entity); + } - /// <summary> Get the collection entry for a persistent collection</summary> - public CollectionEntry GetCollectionEntry(IPersistentCollection coll) - { - return (CollectionEntry)collectionEntries[coll]; - } + /// <summary> Get the collection entry for a persistent collection</summary> + public CollectionEntry GetCollectionEntry(IPersistentCollection coll) + { + return (CollectionEntry)collectionEntries[coll]; + } - /// <summary> Adds an entity to the internal caches.</summary> - public EntityEntry AddEntity(object entity, Status status, object[] loadedState, EntityKey entityKey, object version, - LockMode lockMode, bool existsInDatabase, IEntityPersister persister, - bool disableVersionIncrement, bool lazyPropertiesAreUnfetched) - { - AddEntity(entityKey, entity); + /// <summary> Adds an entity to the internal caches.</summary> + public EntityEntry AddEntity(object entity, Status status, object[] loadedState, EntityKey entityKey, object version, + LockMode lockMode, bool existsInDatabase, IEntityPersister persister, + bool disableVersionIncrement, bool lazyPropertiesAreUnfetched) + { + AddEntity(entityKey, entity); - return AddEntry(entity, status, loadedState, null, entityKey.Identifier, version, lockMode, existsInDatabase, persister, disableVersionIncrement, lazyPropertiesAreUnfetched); - } + return AddEntry(entity, status, loadedState, null, entityKey.Identifier, version, lockMode, existsInDatabase, persister, disableVersionIncrement, lazyPropertiesAreUnfetched); + } - /// <summary> - /// Generates an appropriate EntityEntry instance and adds it - /// to the event source's internal caches. - /// </summary> - public EntityEntry AddEntry(object entity, Status status, object[] loadedState, object rowId, object id, - object version, LockMode lockMode, bool existsInDatabase, IEntityPersister persister, - bool disableVersionIncrement, bool lazyPropertiesAreUnfetched) - { - EntityEntry e = - new EntityEntry(status, loadedState, rowId, id, version, lockMode, existsInDatabase, persister, session.EntityMode, - disableVersionIncrement, lazyPropertiesAreUnfetched); - entityEntries[entity] = e; + /// <summary> + /// Generates an appropriate EntityEntry instance and adds it + /// to the event source's internal caches. + /// </summary> + public EntityEntry AddEntry(object entity, Status status, object[] loadedState, object rowId, object id, + object version, LockMode lockMode, bool existsInDatabase, IEntityPersister persister, + bool disableVersionIncrement, bool lazyPropertiesAreUnfetched) + { + EntityEntry e = + new EntityEntry(status, loadedState, rowId, id, version, lockMode, existsInDatabase, persister, session.EntityMode, + disableVersionIncrement, lazyPropertiesAreUnfetched); + entityEntries[entity] = e; - SetHasNonReadOnlyEnties(status); - return e; - } + SetHasNonReadOnlyEnties(status); + return e; + } - /// <summary> Is the given collection associated with this persistence context?</summary> - public bool ContainsCollection(IPersistentCollection collection) - { - return collectionEntries.Contains(collection); - } + /// <summary> Is the given collection associated with this persistence context?</summary> + public bool ContainsCollection(IPersistentCollection collection) + { + return collectionEntries.Contains(collection); + } - /// <summary> Is the given proxy associated with this persistence context?</summary> - public bool ContainsProxy(INHibernateProxy proxy) - { - return proxiesByKey.ContainsValue(proxy); - } + /// <summary> Is the given proxy associated with this persistence context?</summary> + public bool ContainsProxy(INHibernateProxy proxy) + { + return proxiesByKey.ContainsValue(proxy); + } - /// <summary> - /// Takes the given object and, if it represents a proxy, reassociates it with this event source. - /// </summary> - /// <param name="value">The possible proxy to be reassociated. </param> - /// <returns> Whether the passed value represented an actual proxy which got initialized. </returns> - public bool ReassociateIfUninitializedProxy(object value) - { - // TODO H3.2 Not ported - //ElementWrapper wrapper = value as ElementWrapper; - //if (wrapper != null) - //{ - // value = wrapper.Element; - //} + /// <summary> + /// Takes the given object and, if it represents a proxy, reassociates it with this event source. + /// </summary> + /// <param name="value">The possible proxy to be reassociated. </param> + /// <returns> Whether the passed value represented an actual proxy which got initialized. </returns> + public bool ReassociateIfUninitializedProxy(object value) + { + // TODO H3.2 Not ported + //ElementWrapper wrapper = value as ElementWrapper; + //if (wrapper != null) + //{ + // value = wrapper.Element; + //} - if (!NHibernateUtil.IsInitialized(value)) - { - INHibernateProxy proxy = (INHibernateProxy)value; - ReassociateProxy(proxy.HibernateLazyInitializer, proxy); - return true; - } - else - { - return false; - } - } + if (!NHibernateUtil.IsInitialized(value)) + { + INHibernateProxy proxy = (INHibernateProxy)value; + ReassociateProxy(proxy.HibernateLazyInitializer, proxy); + return true; + } + else + { + return false; + } + } - /// <summary> - /// If a deleted entity instance is re-saved, and it has a proxy, we need to - /// reset the identifier of the proxy - /// </summary> - public void ReassociateProxy(object value, object id) - { - // TODO H3.2 Not ported - //ElementWrapper wrapper = value as ElementWrapper; - //if (wrapper != null) - //{ - // value = wrapper.Element; - //} + /// <summary> + /// If a deleted entity instance is re-saved, and it has a proxy, we need to + /// reset the identifier of the proxy + /// </summary> + public void ReassociateProxy(object value, object id) + { + // TODO H3.2 Not ported + //ElementWrapper wrapper = value as ElementWrapper; + //if (wrapper != null) + //{ + // value = wrapper.Element; + //} - if (value is INHibernateProxy) - { - if (log.IsDebugEnabled) - { - log.Debug("setting proxy identifier: " + id); - } - INHibernateProxy proxy = (INHibernateProxy)value; - ILazyInitializer li = proxy.HibernateLazyInitializer; - li.Identifier = id; - ReassociateProxy(li, proxy); - } - } + INHibernateProxy proxy = value as INHibernateProxy; + if (proxy != null && proxy.HibernateLazyInitializer != null) + { + if (log.IsDebugEnabled) + { + log.Debug("setting proxy identifier: " + id); + } + ILazyInitializer li = proxy.HibernateLazyInitializer; + li.Identifier = id; + ReassociateProxy(li, proxy); + } + } - /// <summary> - /// Associate a proxy that was instantiated by another session with this session - /// </summary> - /// <param name="li">The proxy initializer. </param> - /// <param name="proxy">The proxy to reassociate. </param> - private void ReassociateProxy(ILazyInitializer li, INHibernateProxy proxy) - { - if (li.Session != Session) - { - IEntityPersister persister = session.Factory.GetEntityPersister(li.EntityName); - EntityKey key = new EntityKey(li.Identifier, persister, session.EntityMode); - // any earlier proxy takes precedence - if (!proxiesByKey.ContainsKey(key)) - { - proxiesByKey[key] = proxy; - } - proxy.HibernateLazyInitializer.Session = Session; - } - } + /// <summary> + /// Associate a proxy that was instantiated by another session with this session + /// </summary> + /// <param name="li">The proxy initializer. </param> + /// <param name="proxy">The proxy to reassociate. </param> + private void ReassociateProxy(ILazyInitializer li, INHibernateProxy proxy) + { + if (li.Session != Session) + { + IEntityPersister persister = session.Factory.GetEntityPersister(li.EntityName); + EntityKey key = new EntityKey(li.Identifier, persister, session.EntityMode); + // any earlier proxy takes precedence + if (!proxiesByKey.ContainsKey(key)) + { + proxiesByKey[key] = proxy; + } + proxy.HibernateLazyInitializer.Session = Session; + } + } - /// <summary> - /// Get the entity instance underlying the given proxy, throwing - /// an exception if the proxy is uninitialized. If the given object - /// is not a proxy, simply return the argument. - /// </summary> - public object Unproxy(object maybeProxy) - { - // TODO H3.2 Not ported - //ElementWrapper wrapper = maybeProxy as ElementWrapper; - //if (wrapper != null) - //{ - // maybeProxy = wrapper.Element; - //} + /// <summary> + /// Get the entity instance underlying the given proxy, throwing + /// an exception if the proxy is uninitialized. If the given object + /// is not a proxy, simply return the argument. + /// </summary> + public object Unproxy(object maybeProxy) + { + // TODO H3.2 Not ported + //ElementWrapper wrapper = maybeProxy as ElementWrapper; + //if (wrapper != null) + //{ + // maybeProxy = wrapper.Element; + //} - INHibernateProxy proxy = maybeProxy as INHibernateProxy; - if (proxy != null) - { - ILazyInitializer li = proxy.HibernateLazyInitializer; - if (li.IsUninitialized) - throw new PersistentObjectException("object was an uninitialized proxy for " + li.PersistentClass.FullName); + INHibernateProxy proxy = maybeProxy as INHibernateProxy; + if (proxy != null) + { + ILazyInitializer li = proxy.HibernateLazyInitializer; + if (li.IsUninitialized) + throw new PersistentObjectException("object was an uninitialized proxy for " + li.PersistentClass.FullName); - return li.GetImplementation(); // unwrap the object - } - else - { - return maybeProxy; - } - } + return li.GetImplementation(); // unwrap the object + } + else + { + return maybeProxy; + } + } - /// <summary> - /// Possibly unproxy the given reference and reassociate it with the current session. - /// </summary> - /// <param name="maybeProxy">The reference to be unproxied if it currently represents a proxy. </param> - /// <returns> The unproxied instance. </returns> - public object UnproxyAndReassociate(object maybeProxy) - { - // TODO H3.2 Not ported - //ElementWrapper wrapper = maybeProxy as ElementWrapper; - //if (wrapper != null) - //{ - // maybeProxy = wrapper.Element; - //} + /// <summary> + /// Possibly unproxy the given reference and reassociate it with the current session. + /// </summary> + /// <param name="maybeProxy">The reference to be unproxied if it currently represents a proxy. </param> + /// <returns> The unproxied instance. </returns> + public object UnproxyAndReassociate(object maybeProxy) + { + // TODO H3.2 Not ported + //ElementWrapper wrapper = maybeProxy as ElementWrapper; + //if (wrapper != null) + //{ + // maybeProxy = wrapper.Element; + //} - if (maybeProxy is INHibernateProxy) - { - INHibernateProxy proxy = (INHibernateProxy)maybeProxy; - ILazyInitializer li = proxy.HibernateLazyInitializer; - ReassociateProxy(li, proxy); - return li.GetImplementation(); //initialize + unwrap the object - } - else - { - return maybeProxy; - } - } + INHibernateProxy proxy = maybeProxy as INHibernateProxy; + if (proxy != null && proxy.HibernateLazyInitializer != null) + { + ILazyInitializer li = proxy.HibernateLazyInitializer; + ReassociateProxy(li, proxy); + return li.GetImplementation(); //initialize + unwrap the object + } + else + { + return maybeProxy; + } + } - /// <summary> - /// Attempts to check whether the given key represents an entity already loaded within the - /// current session. - /// </summary> - /// <param name="obj">The entity reference against which to perform the uniqueness check.</param> - /// <param name="key">The entity key.</param> - public void CheckUniqueness(EntityKey key, object obj) - { - object entity = GetEntity(key); - if (entity == obj) - { - throw new AssertionFailure("object already associated, but no entry was found"); - } - if (entity != null) - { - throw new NonUniqueObjectException(key.Identifier, key.EntityName); - } - } + /// <summary> + /// Attempts to check whether the given key represents an entity already loaded within the + /// current session. + /// </summary> + /// <param name="obj">The entity reference against which to perform the uniqueness check.</param> + /// <param name="key">The entity key.</param> + public void CheckUniqueness(EntityKey key, object obj) + { + object entity = GetEntity(key); + if (entity == obj) + { + throw new AssertionFailure("object already associated, but no entry was found"); + } + if (entity != null) + { + throw new NonUniqueObjectException(key.Identifier, key.EntityName); + } + } - /// <summary> - /// If the existing proxy is insufficiently "narrow" (derived), instantiate a new proxy - /// and overwrite the registration of the old one. This breaks == and occurs only for - /// "class" proxies rather than "interface" proxies. Also init the proxy to point to - /// the given target implementation if necessary. - /// </summary> - /// <param name="proxy">The proxy instance to be narrowed. </param> - /// <param name="persister">The persister for the proxied entity. </param> - /// <param name="key">The internal cache key for the proxied entity. </param> - /// <param name="obj">(optional) the actual proxied entity instance. </param> - /// <returns> An appropriately narrowed instance. </returns> - public object NarrowProxy(INHibernateProxy proxy, IEntityPersister persister, EntityKey key, object obj) - { - bool alreadyNarrow = persister.GetConcreteProxyClass(session.EntityMode).IsAssignableFrom(proxy.GetType()); + /// <summary> + /// If the existing proxy is insufficiently "narrow" (derived), instantiate a new proxy + /// and overwrite the registration of the old one. This breaks == and occurs only for + /// "class" proxies rather than "interface" proxies. Also init the proxy to point to + /// the given target implementation if necessary. + /// </summary> + /// <param name="proxy">The proxy instance to be narrowed. </param> + /// <param name="persister">The persister for the proxied entity. </param> + /// <param name="key">The internal cache key for the proxied entity. </param> + /// <param name="obj">(optional) the actual proxied entity instance. </param> + /// <returns> An appropriately narrowed instance. </returns> + public object NarrowProxy(INHibernateProxy proxy, IEntityPersister persister, EntityKey key, object obj) + { + bool alreadyNarrow = persister.GetConcreteProxyClass(session.EntityMode).IsAssignableFrom(proxy.GetType()); - if (!alreadyNarrow) - { - if (ProxyWarnLog.IsWarnEnabled) - { - ProxyWarnLog.Warn("Narrowing proxy to " + persister.GetConcreteProxyClass(session.EntityMode) + " - this operation breaks =="); - } + if (!alreadyNarrow) + { + if (ProxyWarnLog.IsWarnEnabled) + { + ProxyWarnLog.Warn("Narrowing proxy to " + persister.GetConcreteProxyClass(session.EntityMode) + " - this operation breaks =="); + } - if (obj != null) - { - proxiesByKey.Remove(key); - return obj; //return the proxied object - } - else - { - proxy = (INHibernateProxy)persister.CreateProxy(key.Identifier, session); - proxiesByKey[key] = proxy; //overwrite old proxy - return proxy; - } - } - else - { - if (obj != null) - { - proxy.HibernateLazyInitializer.SetImplementation(obj); - } - return proxy; - } - } + if (obj != null) + { + proxiesByKey.Remove(key); + return obj; //return the proxied object + } + else + { + proxy = (INHibernateProxy)persister.CreateProxy(key.Identifier, session); + proxiesByKey[key] = proxy; //overwrite old proxy + return proxy; + } + } + else + { + if (obj != null) + { + proxy.HibernateLazyInitializer.SetImplementation(obj); + } + return proxy; + } + } - /// <summary> - /// Return the existing proxy associated with the given <tt>EntityKey</tt>, or the - /// third argument (the entity associated with the key) if no proxy exists. Init - /// the proxy to the target implementation, if necessary. - /// </summary> - public object ProxyFor(IEntityPersister persister, EntityKey key, object impl) - { - if (!persister.HasProxy || key == null) - return impl; + /// <summary> + /// Return the existing proxy associated with the given <tt>EntityKey</tt>, or the + /// third argument (the entity associated with the key) if no proxy exists. Init + /// the proxy to the target implementation, if necessary. + /// </summary> + public object ProxyFor(IEntityPersister persister, EntityKey key, object impl) + { + if (!persister.HasProxy || key == null) + return impl; - INHibernateProxy proxy; - if (proxiesByKey.TryGetValue(key, out proxy)) - { - return NarrowProxy(proxy, persister, key, impl); - } - else - { - return impl; - } - } + INHibernateProxy proxy; + if (proxiesByKey.TryGetValue(key, out proxy)) + { + return NarrowProxy(proxy, persister, key, impl); + } + else + { + return impl; + } + } - /// <summary> - /// Return the existing proxy associated with the given <tt>EntityKey</tt>, or the - /// argument (the entity associated with the key) if no proxy exists. - /// (slower than the form above) - /// </summary> - public object ProxyFor(object impl) - { - EntityEntry e = GetEntry(impl); - IEntityPersister p = e.Persister; - return ProxyFor(p, new EntityKey(e.Id, p, session.EntityMode), impl); - } + /// <summary> + /// Return the existing proxy associated with the given <tt>EntityKey</tt>, or the + /// arg... [truncated message content] |