/// <summary>
		/// Initializes a new instance of <see cref="ScheduledCollectionAction"/>.
		/// </summary>
		/// <param name="persister">The <see cref="ICollectionPersister"/> that is responsible for the persisting the Collection.</param>
		/// <param name="id">The identifier of the Collection owner.</param>
		/// <param name="session">The <see cref="ISessionImplementor"/> that the Action is occuring in.</param>
		public ScheduledCollectionAction(ICollectionPersister persister, object id, ISessionImplementor session)
		{
			this.persister = persister;
			this.session = session;
			this.id = id;
			this.collectionRole = persister.Role;
		}
		protected override object CopyElement(ICollectionPersister persister, object element, ISessionImplementor session, object owner, IDictionary copiedAlready)
		{
			DictionaryEntry de = ( DictionaryEntry ) element;
			return new DictionaryEntry(
				persister.IndexType.Copy( de.Key, null, session, owner, copiedAlready ),
				persister.ElementType.Copy( de.Value, null, session, owner, copiedAlready ) );
		}
		/// <summary>
		/// Initializes a new instance of <see cref="ScheduledCollectionUpdate"/>.
		/// </summary>
		/// <param name="collection">The <see cref="IPersistentCollection"/> to update.</param>
		/// <param name="persister">The <see cref="ICollectionPersister"/> that is responsible for the persisting the Collection.</param>
		/// <param name="id">The identifier of the Collection owner.</param>
		/// <param name="emptySnapshot">Indicates if the Collection was empty when it was loaded.</param>
		/// <param name="session">The <see cref="ISessionImplementor"/> that the Action is occuring in.</param>
		public ScheduledCollectionUpdate(IPersistentCollection collection, ICollectionPersister persister, object id,
		                                 bool emptySnapshot, ISessionImplementor session)
			: base(persister, id, session)
		{
			_collection = collection;
			_emptySnapshot = emptySnapshot;
		}
		public LoadingCollectionEntry(IDataReader resultSet, ICollectionPersister persister, object key, IPersistentCollection collection)
		{
			this.resultSet = resultSet;
			this.persister = persister;
			this.key = key;
			this.collection = collection;
		}
 public CollectionUpdateAction(
     IPersistentCollection collection, ICollectionPersister persister,
     object key, bool emptySnapshot, ISessionImplementor session)
     : base(persister, collection, key, session)
 {
     this.emptySnapshot = emptySnapshot;
 }
		public override object ReadFrom(IDataReader reader, ICollectionPersister role, ICollectionAliases descriptor,
		                                object owner)
		{
			object element = role.ReadElement(reader, owner, descriptor.SuffixedElementAliases, Session);
			bag.Add(element);
			return element;
		}
		/// <summary> Try to initialize a collection from the cache</summary>
		private bool InitializeCollectionFromCache(object id, ICollectionPersister persister, IPersistentCollection collection, ISessionImplementor source)
		{

			if (!(source.EnabledFilters.Count == 0) && persister.IsAffectedByEnabledFilters(source))
			{
				log.Debug("disregarding cached version (if any) of collection due to enabled filters ");
				return false;
			}

			bool useCache = persister.HasCache && ((source.CacheMode & CacheMode.Get) == CacheMode.Get);

			if (!useCache)
			{
				return false;
			}
			else
			{
				ISessionFactoryImplementor factory = source.Factory;

				CacheKey ck = new CacheKey(id, persister.KeyType, persister.Role, source.EntityMode, factory);
				object ce = persister.Cache.Get(ck, source.Timestamp);

				if (factory.Statistics.IsStatisticsEnabled)
				{
					if (ce == null)
					{
						factory.StatisticsImplementor.SecondLevelCacheMiss(persister.Cache.RegionName);
					}
					else
					{
						factory.StatisticsImplementor.SecondLevelCacheHit(persister.Cache.RegionName);
					}
				}

				if (ce == null)
				{
					log.DebugFormat("Collection cache miss: {0}", ck);
				}
				else
				{
					log.DebugFormat("Collection cache hit: {0}", ck);
				}

				if (ce == null)
				{
					return false;
				}
				else
				{
					IPersistenceContext persistenceContext = source.PersistenceContext;

					CollectionCacheEntry cacheEntry = (CollectionCacheEntry)persister.CacheEntryStructure.Destructure(ce, factory);
					cacheEntry.Assemble(collection, persister, persistenceContext.GetCollectionOwner(id, persister));

					persistenceContext.GetCollectionEntry(collection).PostInitialize(collection);
					return true;
				}
			}
		}
		/// <summary> Constructs an AbstractCollectionEvent object. </summary>
		/// <param name="collectionPersister">The collection persister.</param>
		/// <param name="collection">The collection </param>
		/// <param name="source">The Session source </param>
		/// <param name="affectedOwner">The owner that is affected by this event; can be null if unavailable </param>
		/// <param name="affectedOwnerId">
		/// The ID for the owner that is affected by this event; can be null if unavailable
		/// that is affected by this event; can be null if unavailable
		/// </param>
		protected AbstractCollectionEvent(ICollectionPersister collectionPersister, IPersistentCollection collection,
		                               IEventSource source, object affectedOwner, object affectedOwnerId) : base(source)
		{
			this.collection = collection;
			this.affectedOwner = affectedOwner;
			this.affectedOwnerId = affectedOwnerId;
			affectedOwnerEntityName = GetAffectedOwnerEntityName(collectionPersister, affectedOwner, source);
		}
		/// <summary> 
		/// Schedules a collection for deletion. 
		/// </summary>
		/// <param name="role">The persister representing the collection to be removed. </param>
		/// <param name="collectionKey">The collection key (differs from owner-id in the case of property-refs). </param>
		/// <param name="source">The session from which the request originated. </param>
		internal void RemoveCollection(ICollectionPersister role, object collectionKey, IEventSource source)
		{
			if (log.IsDebugEnabled)
			{
				log.Debug("collection dereferenced while transient " + MessageHelper.CollectionInfoString(role, ownerIdentifier, source.Factory));
			}
			source.ActionQueue.AddAction(new CollectionRemoveAction(owner, role, collectionKey, false, source));
		}
Exemple #10
0
		protected override ICollection Snapshot(ICollectionPersister persister)
		{
			Hashtable clonedMap = new Hashtable(map.Count);
			foreach (DictionaryEntry e in map)
			{
				clonedMap[e.Key] = persister.ElementType.DeepCopy(e.Value, EntityMode.Poco, persister.Factory);
			}
			return clonedMap;
		}
		public BatchingCollectionInitializer( ICollectionPersister collPersister, int batchSize, Loader batchLoader, int smallBatchSize, Loader smallBatchLoader, Loader nonBatchLoader )
		{
			this.batchLoader = batchLoader;
			this.nonBatchLoader = nonBatchLoader;
			this.batchSize = batchSize;
			this.collectionPersister = collPersister;
			this.smallBatchLoader = smallBatchLoader;
			this.smallBatchSize = smallBatchSize;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="persister"></param>
		/// <returns></returns>
		protected override ICollection Snapshot( ICollectionPersister persister )
		{
			ArrayList clonedList = new ArrayList( list.Count );
			foreach( object obj in list )
			{
				clonedList.Add( persister.ElementType.DeepCopy( obj ) );
			}
			return clonedList;
		}
 public BatchingCollectionInitializer(
     ICollectionPersister collectionPersister,
     int[] batchSizes,
     Loader[] loaders)
 {
     this.loaders = loaders;
     this.batchSizes = batchSizes;
     this.collectionPersister = collectionPersister;
 }
        /// <summary> 
        /// Finish the process of collection-loading for this bound result set.  Mainly this
        /// involves cleaning up resources and notifying the collections that loading is
        /// complete. 
        /// </summary>
        /// <param name="persister">The persister for which to complete loading. </param>
        public void EndLoadingCollections(ICollectionPersister persister)
        {
            if (!loadContexts.HasLoadingCollectionEntries || (localLoadingCollectionKeys.Count == 0))
            {
                return;
            }

            // in an effort to avoid concurrent-modification-exceptions (from
            // potential recursive calls back through here as a result of the
            // eventual call to PersistentCollection#endRead), we scan the
            // internal loadingCollections map for matches and store those matches
            // in a temp collection.  the temp collection is then used to "drive"
            // the #endRead processing.
            List<CollectionKey> toRemove = new List<CollectionKey>();
            List<LoadingCollectionEntry> matches =new List<LoadingCollectionEntry>();
            foreach (CollectionKey collectionKey in localLoadingCollectionKeys)
            {
                ISessionImplementor session = LoadContext.PersistenceContext.Session;

                LoadingCollectionEntry lce = loadContexts.LocateLoadingCollectionEntry(collectionKey);
                if (lce == null)
                {
                    log.Warn("In CollectionLoadContext#endLoadingCollections, localLoadingCollectionKeys contained [" + collectionKey + "], but no LoadingCollectionEntry was found in loadContexts");
                }
                else if (lce.ResultSet == resultSet && lce.Persister == persister)
                {
                    matches.Add(lce);
                    if (lce.Collection.Owner == null)
                    {
                        session.PersistenceContext.AddUnownedCollection(new CollectionKey(persister, lce.Key, session.EntityMode),
                                                                        lce.Collection);
                    }
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("removing collection load entry [" + lce + "]");
                    }

                    // todo : i'd much rather have this done from #endLoadingCollection(CollectionPersister,LoadingCollectionEntry)...
                    loadContexts.UnregisterLoadingCollectionXRef(collectionKey);
                    toRemove.Add(collectionKey);
                }
            }
            localLoadingCollectionKeys.RemoveAll(toRemove);

            EndLoadingCollections(persister, matches);
            if ((localLoadingCollectionKeys.Count == 0))
            {
                // todo : hack!!!
                // NOTE : here we cleanup the load context when we have no more local
                // LCE entries.  This "works" for the time being because really
                // only the collection load contexts are implemented.  Long term,
                // this cleanup should become part of the "close result set"
                // processing from the (sandbox/jdbc) jdbc-container code.
                loadContexts.Cleanup(resultSet);
            }
        }
		public object ReplaceElements(object original, object target, ICollectionPersister persister, object owner, IDictionary copyCache, ISessionImplementor session)
		{
			IDefaultableList result = (IDefaultableList)target;
			result.Clear();
			foreach (object o in (IDefaultableList)original)
			{
				result.Add(o);
			}
			return result;
		}
		/// <summary> 
		/// Removes a persistent collection from a specified owner. 
		/// </summary>
		/// <param name="affectedOwner">The collection's owner; must be non-null </param>
		/// <param name="persister"> The collection's persister </param>
		/// <param name="id">The collection key </param>
		/// <param name="emptySnapshot">Indicates if the snapshot is empty </param>
		/// <param name="session">The session </param>
		/// <remarks> Use this constructor when the collection to be removed has not been loaded. </remarks>
		public CollectionRemoveAction(object affectedOwner, ICollectionPersister persister, object id, bool emptySnapshot,
		                              ISessionImplementor session) : base(persister, null, id, session)
		{
			if (affectedOwner == null)
			{
				throw new AssertionFailure("affectedOwner == null");
			}
			this.emptySnapshot = emptySnapshot;
			this.affectedOwner = affectedOwner;
		}
		/// <summary>
		/// Returns a Hashtable where the Key &amp; the Value are both a Copy of the
		/// same object.
		/// <see cref="AbstractPersistentCollection.Snapshot(ICollectionPersister)"/>
		/// </summary>
		/// <param name="persister"></param>
		protected override ICollection Snapshot(ICollectionPersister persister)
		{
			Hashtable clonedMap = new Hashtable(internalSet.Count);
			foreach (object obj in internalSet)
			{
				object copied = persister.ElementType.DeepCopy(obj);
				clonedMap[copied] = copied;
			}
			return clonedMap;
		}
		protected void InitClassPersisters( IList associations )
		{
			int joins = CountClassPersisters( associations );

			collectionOwner = -1; // if no collection found
			classPersisters = new ILoadable[ joins + 1 ];
			Owners = new int[ joins + 1 ];
			aliases = new string[ joins + 1 ];
			lockModeArray = CreateLockModeArray( joins + 1, LockMode.None );
			int i = 0;
			foreach( OuterJoinableAssociation oj in associations )
			{
				object subpersister = oj.Joinable;
				if( subpersister is ILoadable )
				{
					classPersisters[ i ] = ( ILoadable ) subpersister;
					Owners[ i ] = ToOwner( oj, joins, oj.IsOneToOne );
					aliases[ i ] = oj.Subalias;
					if( oj.JoinType == JoinType.InnerJoin )
					{
						AddAllToPropertySpaces( classPersisters[ i ].PropertySpaces );
					}
					i++;
				}
				else
				{
					IQueryableCollection collPersister = ( IQueryableCollection ) subpersister;
					// TODO: ?? suppress initialization of collections with a where condition
					if( oj.JoinType == JoinType.LeftOuterJoin )
					{
						collectionPersister = collPersister;
						collectionOwner = ToOwner( oj, joins, true );
					}
					else
					{
						AddToPropertySpaces( collPersister.CollectionSpace );
					}

					if( collPersister.IsOneToMany )
					{
						classPersisters[ i ] = ( ILoadable ) collPersister.ElementPersister;
						aliases[ i ] = oj.Subalias;
						i++;
					}
				}
			}
			classPersisters[ joins ] = persister;
			Owners[ joins ] = -1;
			aliases[ joins ] = alias;

			if( ArrayHelper.IsAllNegative( Owners ) )
			{
				Owners = null;
			}
		}
		void IDeserializationCallback.OnDeserialization(object sender)
		{
			try
			{
				persister = session.Factory.GetCollectionPersister(collectionRole);
			}
			catch (MappingException e)
			{
				throw new IOException("Unable to resolve collection persister on deserialization", e);
			}
		}
		public object ReplaceElements(object original, object target, ICollectionPersister persister, object owner,
		                              IDictionary copyCache, ISessionImplementor session)
		{
			IList<Email> result = (IList<Email>) target;
			result.Clear();

			foreach (object o in ((IEnumerable) original))
				result.Add((Email) o);

			return result;
		}
Exemple #21
0
		/// <summary>
		/// Return a new snapshot of the current state.
		/// </summary>
		/// <param name="persister">The <see cref="ICollectionPersister"/> for this Collection.</param>
		/// <returns>
		/// A new <see cref="ArrayList"/> that contains Deep Copies of the 
		/// Elements stored in this wrapped collection.
		/// </returns>
		protected override ICollection Snapshot(ICollectionPersister persister)
		{
			EntityMode entityMode = Session.EntityMode;

			ArrayList clonedList = new ArrayList(list.Count);
			foreach (object obj in list)
			{
				clonedList.Add(persister.ElementType.DeepCopy(obj,entityMode, persister.Factory));
			}
			return clonedList;
		}
		/// <summary> 
		/// This version is slightly different in that here we need to assume that
		/// the owner is not yet associated with the session, and thus we cannot
		/// rely on the owner's EntityEntry snapshot... 
		/// </summary>
		/// <param name="role">The persister for the collection role being processed. </param>
		/// <returns> </returns>
		internal object ExtractCollectionKeyFromOwner(ICollectionPersister role)
		{
			if (role.CollectionType.UseLHSPrimaryKey)
			{
				return ownerIdentifier;
			}
			else
			{
				return role.OwnerEntityPersister.GetPropertyValue(owner, role.CollectionType.LHSPropertyName, Session.EntityMode);
			}
		}
		public override ICollection GetSnapshot(ICollectionPersister persister)
		{
			EntityMode entityMode = Session.EntityMode;
			Hashtable clonedMap = new Hashtable(map.Count);
			foreach (DictionaryEntry e in map)
			{
				object copy = persister.ElementType.DeepCopy(e.Value, entityMode, persister.Factory);
				clonedMap[e.Key] = copy;
			}
			return clonedMap;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="persister"></param>
		/// <returns></returns>
		protected override ICollection Snapshot( ICollectionPersister persister )
		{
			SortedList clonedMap = new SortedList( comparer );
			foreach( DictionaryEntry de in map )
			{
				object copy = persister.ElementType.DeepCopy( de.Value );
				clonedMap.Add( de.Key, copy );
			}

			return clonedMap;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="persister"></param>
		/// <returns></returns>
		protected override ICollection Snapshot( ICollectionPersister persister )
		{
			SortedList clonedSet = new SortedList( comparer, internalSet.Count );
			foreach( object obj in internalSet )
			{
				object copy = persister.ElementType.DeepCopy( obj );
				clonedSet.Add( copy, copy );
			}

			return clonedSet;
		}
		/// <summary>
		/// Initializes this Bag from the cached values.
		/// </summary>
		/// <param name="persister">The CollectionPersister to use to reassemble the PersistentIdentifierBag.</param>
		/// <param name="disassembled">The disassembled PersistentIdentifierBag.</param>
		/// <param name="owner">The owner object.</param>
		public override void InitializeFromCache(ICollectionPersister persister, object disassembled, object owner)
		{
			object[] array = (object[]) disassembled;
			int size = array.Length;
			BeforeInitialize(persister, size);
			for (int i = 0; i < size; i += 2)
			{
				identifiers[i / 2] = persister.IdentifierType.Assemble(array[i], Session, owner);
				values.Add(persister.ElementType.Assemble(array[i + 1], Session, owner));
			}
		}
Exemple #27
0
		/// <summary>
		/// Returns a Hashtable where the Key &amp; the Value are both a Copy of the
		/// same object.
		/// <see cref="AbstractPersistentCollection.Snapshot(ICollectionPersister)"/>
		/// </summary>
		/// <param name="persister"></param>
		protected override ICollection Snapshot(ICollectionPersister persister)
		{
			EntityMode entityMode = Session.EntityMode;

			Hashtable clonedMap = new Hashtable(internalSet.Count);
			foreach (object obj in internalSet)
			{
				object copied = persister.ElementType.DeepCopy(obj, entityMode, persister.Factory);
				clonedMap[copied] = copied;
			}
			return clonedMap;
		}
		public override ICollection GetSnapshot(ICollectionPersister persister)
		{
			EntityMode entityMode = Session.EntityMode;

			List<object> clonedList = new List<object>(list.Count);
			foreach (object current in list)
			{
				object deepCopy = persister.ElementType.DeepCopy(current, entityMode, persister.Factory);
				clonedList.Add(deepCopy);
			}
			return clonedList;
		}
		/// <summary> 
		/// Removes a persistent collection from its loaded owner. 
		/// </summary>
		/// <param name="collection">The collection to to remove; must be non-null </param>
		/// <param name="persister"> The collection's persister </param>
		/// <param name="id">The collection key </param>
		/// <param name="emptySnapshot">Indicates if the snapshot is empty </param>
		/// <param name="session">The session </param>
		/// <remarks>Use this constructor when the collection is non-null.</remarks>
		public CollectionRemoveAction(IPersistentCollection collection, ICollectionPersister persister, object id,
		                              bool emptySnapshot, ISessionImplementor session)
			: base(persister, collection, id, session)
		{
			if (collection == null)
			{
				throw new AssertionFailure("collection == null");
			}

			this.emptySnapshot = emptySnapshot;
			affectedOwner = session.PersistenceContext.GetLoadedCollectionOwnerOrNull(collection);
		}
		public override object ReadFrom(IDataReader reader, ICollectionPersister role, ICollectionAliases descriptor,
		                                object owner)
		{
			// note that if we load this collection from a cartesian product
			// the multiplicity would be broken ... so use an idbag instead
			object element = role.ReadElement(reader, owner, descriptor.SuffixedElementAliases, Session);
			// NH Different behavior : we don't check for null
			// The NH-750 test show how checking for null we are ignoring the not-found tag and
			// the DB may have some records ignored by NH. This issue may need some more deep consideration.
			//if (element != null)
				bag.Add(element);
			return element;
		}
Exemple #31
0
 public abstract object GetSnapshot(ICollectionPersister persister);
Exemple #32
0
 public override void BeforeInitialize(ICollectionPersister persister, int anticipatedSize)
 {
     set = (ISet)persister.CollectionType.Instantiate(anticipatedSize);
 }
Exemple #33
0
 public abstract bool EqualsSnapshot(ICollectionPersister persister);
Exemple #34
0
 /// <summary>
 /// Called before inserting rows, to ensure that any surrogate keys are fully generated
 /// </summary>
 /// <param name="persister"></param>
 public virtual void PreInsert(ICollectionPersister persister)
 {
 }
Exemple #35
0
 /// <summary>
 /// Called before any elements are read into the collection,
 /// allowing appropriate initializations to occur.
 /// </summary>
 /// <param name="persister">The underlying collection persister. </param>
 /// <param name="anticipatedSize">The anticipated size of the collection after initilization is complete. </param>
 public abstract void BeforeInitialize(ICollectionPersister persister, int anticipatedSize);
 public override IPersistentCollection Instantiate(ISessionImplementor session, ICollectionPersister persister, object key)
 {
     return(new PersistentObservableGenericList <T>(session));
 }
Exemple #37
0
 /// <summary>
 /// Disassemble the collection, ready for the cache
 /// </summary>
 /// <param name="persister"></param>
 /// <returns></returns>
 public abstract object Disassemble(ICollectionPersister persister);
 public override IEnumerable Entries(ICollectionPersister persister)
 {
     return(WrappedList);
 }
 public override void BeforeInitialize(ICollectionPersister persister, int anticipatedSize)
 {
     base.BeforeInitialize(persister, anticipatedSize);
     CaptureEventHandlers();
 }
 void IDeserializationCallback.OnDeserialization(object sender)
 {
     persister = session.Factory.GetCollectionPersister(collectionRole);
 }
 public override void BeforeInitialize(ICollectionPersister persister, int anticipatedSize)
 {
     WrappedList = (IList <T>)persister.CollectionType.Instantiate(anticipatedSize);
 }
 public override void BeforeInitialize(ICollectionPersister persister, int anticipatedSize)
 {
     base.BeforeInitialize(persister, anticipatedSize);
     ((INotifyCollectionChanged)this).CollectionChanged += OnCollectionChanged;
 }
Exemple #43
0
 public override object GetIndex(object entry, int i, ICollectionPersister persister)
 {
     throw new NotSupportedException("Sets don't have indexes");
 }
 public override IPersistentCollection Instantiate(ISessionImplementor session, ICollectionPersister persister, object key)
 {
     return(new PersistentCiccioSet <T>(session));
 }
Exemple #45
0
 public abstract IEnumerable Entries(ICollectionPersister persister);
 public PreCollectionRecreateEvent(ICollectionPersister collectionPersister, IPersistentCollection collection,
                                   IEventSource source)
     : base(collectionPersister, collection, source, collection.Owner, GetOwnerIdOrNull(collection.Owner, source))
 {
 }
Exemple #47
0
 /// <summary>
 /// Get all the elements that need deleting
 /// </summary>
 public abstract IEnumerable GetDeletes(ICollectionPersister persister, bool indexIsFormula);
Exemple #48
0
 /// <summary>
 /// Get the index of the given collection entry
 /// </summary>
 public abstract object GetIndex(object entry, int i, ICollectionPersister persister);
 public MapQueueOperationTracker(ICollectionPersister collectionPersister)
 {
     _collectionPersister = collectionPersister;
 }
        private static Task ProcessDereferencedCollectionAsync(IPersistentCollection coll, ISessionImplementor session, CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return(Task.FromCanceled <object>(cancellationToken));
            }
            try
            {
                IPersistenceContext  persistenceContext = session.PersistenceContext;
                CollectionEntry      entry           = persistenceContext.GetCollectionEntry(coll);
                ICollectionPersister loadedPersister = entry.LoadedPersister;

                if (log.IsDebugEnabled() && loadedPersister != null)
                {
                    log.Debug("Collection dereferenced: {0}", MessageHelper.CollectionInfoString(loadedPersister, coll, entry.LoadedKey, session));
                }

                // do a check
                bool hasOrphanDelete = loadedPersister != null && loadedPersister.HasOrphanDelete;
                if (hasOrphanDelete)
                {
                    object ownerId = loadedPersister.OwnerEntityPersister.GetIdentifier(coll.Owner);
                    // TODO NH Different behavior
                    //if (ownerId == null)
                    //{
                    //  // the owning entity may have been deleted and its identifier unset due to
                    //  // identifier-rollback; in which case, try to look up its identifier from
                    //  // the persistence context
                    //  if (session.Factory.Settings.IsIdentifierRollbackEnabled)
                    //  {
                    //    EntityEntry ownerEntry = persistenceContext.GetEntry(coll.Owner);
                    //    if (ownerEntry != null)
                    //    {
                    //      ownerId = ownerEntry.Id;
                    //    }
                    //  }
                    //  if (ownerId == null)
                    //  {
                    //    throw new AssertionFailure("Unable to determine collection owner identifier for orphan-delete processing");
                    //  }
                    //}
                    EntityKey key   = session.GenerateEntityKey(ownerId, loadedPersister.OwnerEntityPersister);
                    object    owner = persistenceContext.GetEntity(key);
                    if (owner == null)
                    {
                        return(Task.FromException <object>(new AssertionFailure("collection owner not associated with session: " + loadedPersister.Role)));
                    }
                    EntityEntry e = persistenceContext.GetEntry(owner);
                    //only collections belonging to deleted entities are allowed to be dereferenced in the case of orphan delete
                    if (e != null && e.Status != Status.Deleted && e.Status != Status.Gone)
                    {
                        return(Task.FromException <object>(new HibernateException("A collection with cascade=\"all-delete-orphan\" was no longer referenced by the owning entity instance: " + loadedPersister.Role)));
                    }
                }

                // do the work
                entry.CurrentPersister = null;
                entry.CurrentKey       = null;
                return(PrepareCollectionForUpdateAsync(coll, entry, session.Factory, cancellationToken));
            }
            catch (System.Exception ex)
            {
                return(Task.FromException <object>(ex));
            }
        }
Exemple #51
0
 /// <summary>
 /// Called after inserting a row, to fetch the natively generated id
 /// </summary>
 public virtual void AfterRowInsert(ICollectionPersister persister, object entry, int i, object id)
 {
 }
 public override bool AfterInitialize(ICollectionPersister persister)
 {
     Assert.That(InternalValues, Is.InstanceOf <CustomList <string> >());
     return(base.AfterInitialize(persister));
 }
Exemple #53
0
 /// <summary>
 /// Gets a <see cref="Boolean"/> indicating if the rows for this collection
 /// need to be recreated in the table.
 /// </summary>
 /// <param name="persister">The <see cref="ICollectionPersister"/> for this Collection.</param>
 /// <returns>
 /// <see langword="false" /> by default since most collections can determine which rows need to be
 /// individually updated/inserted/deleted.  Currently only <see cref="PersistentBag"/>'s for <c>many-to-many</c>
 /// need to be recreated.
 /// </returns>
 public virtual bool NeedsRecreate(ICollectionPersister persister)
 {
     return(false);
 }
Exemple #54
0
 /// <summary>
 /// Read the state of the collection from a disassembled cached value.
 /// </summary>
 /// <param name="persister"></param>
 /// <param name="disassembled"></param>
 /// <param name="owner"></param>
 public abstract void InitializeFromCache(ICollectionPersister persister, object disassembled, object owner);
 public override object GetIndex(object entry, int i, ICollectionPersister persister)
 {
     return(i);
 }
 public BatchingCollectionInitializer(ICollectionPersister collectionPersister, int[] batchSizes, Loader[] loaders)
 {
     this.loaders             = loaders;
     this.batchSizes          = batchSizes;
     this.collectionPersister = collectionPersister;
 }
Exemple #57
0
        private static bool IsBag(ICollectionPersister collectionPersister)
        {
            var type = collectionPersister.CollectionType.GetType();

            return(type.IsGenericType && type.GetGenericTypeDefinition() == typeof(GenericBagType <>));
        }
        private static Task PrepareCollectionForUpdateAsync(IPersistentCollection collection, CollectionEntry entry, ISessionFactoryImplementor factory, CancellationToken cancellationToken)
        {
            //1. record the collection role that this collection is referenced by
            //2. decide if the collection needs deleting/creating/updating (but don't actually schedule the action yet)

            if (entry.IsProcessed)
            {
                throw new AssertionFailure("collection was processed twice by flush()");
            }
            if (cancellationToken.IsCancellationRequested)
            {
                return(Task.FromCanceled <object>(cancellationToken));
            }
            try
            {
                entry.IsProcessed = true;

                ICollectionPersister loadedPersister  = entry.LoadedPersister;
                ICollectionPersister currentPersister = entry.CurrentPersister;
                if (loadedPersister != null || currentPersister != null)
                {
                    // it is or was referenced _somewhere_
                    bool ownerChanged = loadedPersister != currentPersister ||
                                        !currentPersister.KeyType.IsEqual(entry.LoadedKey, entry.CurrentKey, factory);

                    if (ownerChanged)
                    {
                        // do a check
                        bool orphanDeleteAndRoleChanged = loadedPersister != null &&
                                                          currentPersister != null && loadedPersister.HasOrphanDelete;

                        if (orphanDeleteAndRoleChanged)
                        {
                            return(Task.FromException <object>(new HibernateException("Don't change the reference to a collection with cascade=\"all-delete-orphan\": " + loadedPersister.Role)));
                        }

                        // do the work
                        if (currentPersister != null)
                        {
                            entry.IsDorecreate = true;                             // we will need to create new entries
                        }

                        if (loadedPersister != null)
                        {
                            entry.IsDoremove = true;                             // we will need to remove ye olde entries
                            if (entry.IsDorecreate)
                            {
                                log.Debug("Forcing collection initialization");
                                return(collection.ForceInitializationAsync(cancellationToken));                                // force initialize!
                            }
                        }
                    }
                    else if (collection.IsDirty)
                    {
                        // else if it's elements changed
                        entry.IsDoupdate = true;
                    }
                }
                return(Task.CompletedTask);
            }
            catch (System.Exception ex)
            {
                return(Task.FromException <object>(ex));
            }
        }
 protected override bool IsCollectionPersisterCacheable(ICollectionPersister collectionPersister)
 {
     return(!_uncacheableCollectionPersisters.Contains(collectionPersister));
 }
Exemple #60
0
 /// <summary>
 /// Reads the row from the <see cref="IDataReader"/>.
 /// </summary>
 /// <param name="reader">The IDataReader that contains the value of the Identifier</param>
 /// <param name="role">The persister for this Collection.</param>
 /// <param name="descriptor">The descriptor providing result set column names</param>
 /// <param name="owner">The owner of this Collection.</param>
 /// <returns>The object that was contained in the row.</returns>
 public abstract object ReadFrom(IDataReader reader, ICollectionPersister role, ICollectionAliases descriptor,
                                 object owner);