Example #1
0
        private object ProcessArrayOrNewCollection(object collection, CollectionType collectionType)
        {
            if (collection == null)
            {
                //do nothing
                return(null);
            }

            ISessionImplementor session = Session;

            ICollectionPersister persister = session.Factory.GetCollectionPersister(collectionType.Role);

            IPersistenceContext persistenceContext = session.PersistenceContext;

            //TODO: move into collection type, so we can use polymorphism!

            if (collectionType.HasHolder(session.EntityMode))
            {
                if (collection == CollectionType.UnfetchedCollection)
                {
                    return(null);
                }

                IPersistentCollection ah = persistenceContext.GetCollectionHolder(collection);
                if (ah == null)
                {
                    ah = collectionType.Wrap(session, collection);
                    persistenceContext.AddNewCollection(persister, ah);
                    persistenceContext.AddCollectionHolder(ah);
                }
                return(null);
            }
            else
            {
                IPersistentCollection persistentCollection = collectionType.Wrap(session, collection);
                persistenceContext.AddNewCollection(persister, persistentCollection);

                if (log.IsDebugEnabled)
                {
                    log.Debug("Wrapped collection in role: " + collectionType.Role);
                }

                return(persistentCollection);                //Force a substitution!
            }
        }