コード例 #1
0
		/// <summary>
		/// 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)
		/// </summary>
		/// <param name="coll"></param>
		/// <param name="entry"></param>
		private void PrepareCollectionForUpdate( PersistentCollection coll, CollectionEntry entry )
		{
			if( entry.processed )
			{
				throw new AssertionFailure( "collection was processed twice by flush()" );
			}

			entry.processed = true;

			// it is or was referenced _somewhere_
			if( entry.loadedPersister != null || entry.currentPersister != null )
			{
				if(
					entry.loadedPersister != entry.currentPersister || //if either its role changed,
						!entry.currentPersister.KeyType.Equals( entry.loadedKey, entry.currentKey ) // or its key changed
					)
				{
					// do a check
					if(
						entry.loadedPersister != null &&
							entry.currentPersister != null &&
							entry.loadedPersister.HasOrphanDelete )
					{
						throw new HibernateException( "Don't dereference a collection with cascade=\"all-delete-orphan\": " + coll.CollectionSnapshot.Role );
					}

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

					if( entry.loadedPersister != null )
					{
						entry.doremove = true; // we will need to remove the old entres
						if( entry.dorecreate )
						{
							log.Debug( "forcing collection initialization" );
							coll.ForceInitialization();
						}
					}
				}
				else if( entry.Dirty )
				{
					// else if it's elements changed
					entry.doupdate = true;
				}
			}
		}