Beispiel #1
0
        internal override object ProcessCollection(object collection, CollectionType type)
        {
            ISessionImplementor  session   = Session;
            ICollectionPersister persister = session.Factory.GetCollectionPersister(type.Role);

            if (collection == null)
            {
                //do nothing
            }
            else
            {
                IPersistentCollection persistentCollection = collection as IPersistentCollection;
                if (persistentCollection != null)
                {
                    if (persistentCollection.SetCurrentSession(session))
                    {
                        if (IsOwnerUnchanged(persistentCollection, persister, ExtractCollectionKeyFromOwner(persister)))
                        {
                            // a "detached" collection that originally belonged to the same entity
                            if (persistentCollection.IsDirty)
                            {
                                throw new HibernateException("reassociated object has dirty collection: " + persistentCollection.Role);
                            }
                            ReattachCollection(persistentCollection, type);
                        }
                        else
                        {
                            // a "detached" collection that belonged to a different entity
                            throw new HibernateException("reassociated object has dirty collection reference: " + persistentCollection.Role);
                        }
                    }
                    else
                    {
                        // a collection loaded in the current session
                        // can not possibly be the collection belonging
                        // to the entity passed to update()
                        throw new HibernateException("reassociated object has dirty collection reference: " + persistentCollection.Role);
                    }
                }
                else
                {
                    // brand new collection
                    //TODO: or an array!! we can't lock objects with arrays now??
                    throw new HibernateException("reassociated object has dirty collection reference (or an array)");
                }
            }
            return(null);
        }
Beispiel #2
0
        internal override object ProcessCollection(object collection, CollectionType collectionType)
        {
            IPersistentCollection coll = collection as IPersistentCollection;

            if (coll != null)
            {
                ISessionImplementor session = Session;
                if (coll.SetCurrentSession(session))
                {
                    ReattachCollection(coll, collectionType);
                }
                return(null);
            }
            else
            {
                return(ProcessArrayOrNewCollection(collection, collectionType));
            }
        }
Beispiel #3
0
        internal override object ProcessCollection(object collection, CollectionType type)
        {
            if (collection == CollectionType.UnfetchedCollection)
            {
                return(null);
            }

            IEventSource         session   = Session;
            ICollectionPersister persister = session.Factory.GetCollectionPersister(type.Role);

            object collectionKey          = ExtractCollectionKeyFromOwner(persister);
            IPersistentCollection wrapper = collection as IPersistentCollection;

            if (wrapper != null)
            {
                if (wrapper.SetCurrentSession(session))
                {
                    //a "detached" collection!
                    if (!IsOwnerUnchanged(wrapper, persister, collectionKey))
                    {
                        // if the collection belonged to a different entity,
                        // clean up the existing state of the collection
                        RemoveCollection(persister, collectionKey, session);
                    }
                    ReattachCollection(wrapper, type);
                }
                else
                {
                    // a collection loaded in the current session
                    // can not possibly be the collection belonging
                    // to the entity passed to update()
                    RemoveCollection(persister, collectionKey, session);
                }
            }
            else
            {
                // null or brand new collection
                // this will also (inefficiently) handle arrays, which have
                // no snapshot, so we can't do any better
                RemoveCollection(persister, collectionKey, session);
            }

            return(null);
        }
Beispiel #4
0
        internal override object ProcessCollection(object collection, CollectionType type)
        {
            if (collection == CollectionType.UnfetchedCollection)
            {
                return(null);
            }

            IEventSource         session   = Session;
            ICollectionPersister persister = session.Factory.GetCollectionPersister(type.Role);

            if (isUpdate)
            {
                RemoveCollection(persister, ExtractCollectionKeyFromOwner(persister), session);
            }
            IPersistentCollection wrapper = collection as IPersistentCollection;

            if (wrapper != null)
            {
                wrapper.SetCurrentSession(session);
                if (wrapper.WasInitialized)
                {
                    session.PersistenceContext.AddNewCollection(persister, wrapper);
                }
                else
                {
                    ReattachCollection(wrapper, type);
                }
            }
            else
            {
                // otherwise a null or brand new collection
                // this will also (inefficiently) handle arrays, which
                // have no snapshot, so we can't do any better
                //processArrayOrNewCollection(collection, type);
            }

            return(null);
        }
Beispiel #5
0
        /// <summary>
        /// Checks if the collection is still associated with it's session and is not initialized.
        /// Creates a new one if it is not.
        /// </summary>
        /// <param name="collection">The collection to check.</param>
        /// <param name="initialized">Is the collection initialized yet.</param>
        /// <param name="Session">The session to which the collection is linked.</param>
        /// <param name="sessionConfirmed">Used to remember if this method has already created a new session for this collection.</param>
        /// <returns>The newly created session, if one is required.</returns>
        internal static ISession checkSession(this IPersistentCollection collection, bool initialized, ISessionImplementor Session, ref bool sessionConfirmed)
        {
            if (sessionConfirmed)
            {
                return(null);
            }

            if (!initialized)
            {
                //If the session has been disconnected, reconnect before continuing with the initialization.
                if (Session == null ||
                    !Session.IsOpen ||
                    !Session.PersistenceContext.ContainsCollection(collection) ||
                    !Session.IsConnected)
                {
                    var ret = ActiveRecordMediator.GetSessionFactoryHolder().CreateSession(collection.Owner.GetType());
                    sessionConfirmed = true;
                    collection.SetCurrentSession(ret.GetSessionImplementation());
                    ret.Lock(collection.Owner, LockMode.None);
                    return(ret);
                }
            }
            return(null);
        }