Esempio n. 1
0
        public virtual async Task OnMergeAsync(MergeEvent @event, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            EventCache copyCache = new EventCache();

            await(OnMergeAsync(@event, copyCache, cancellationToken)).ConfigureAwait(false);

            // transientCopyCache may contain parent and child entities in random order.
            // Child entities occurring ahead of their respective transient parents may fail
            // to get merged in one iteration.
            // Retries are necessary as more and more children may be able to merge on subsequent iterations.
            // Iteratively get transient entities and retry merge until one of the following conditions is true:
            //   1) transientCopyCache.size() == 0
            //   2) transientCopyCache.size() is not decreasing

            // TODO: find out if retrying can add entities to copyCache (don't think it can...)
            // For now, just retry once; throw TransientObjectException if there are still any transient entities

            IDictionary transientCopyCache = await(this.GetTransientCopyCacheAsync(@event, copyCache, cancellationToken)).ConfigureAwait(false);

            while (transientCopyCache.Count > 0)
            {
                var initialTransientCount = transientCopyCache.Count;

                await(RetryMergeTransientEntitiesAsync(@event, transientCopyCache, copyCache, cancellationToken)).ConfigureAwait(false);

                // find any entities that are still transient after retry
                transientCopyCache = await(this.GetTransientCopyCacheAsync(@event, copyCache, cancellationToken)).ConfigureAwait(false);

                // if a retry did nothing, the remaining transient entities
                // cannot be merged due to references to other transient entities
                // that are not part of the merge
                if (transientCopyCache.Count == initialTransientCount)
                {
                    ISet <string> transientEntityNames = new HashSet <string>();

                    foreach (object transientEntity in transientCopyCache.Keys)
                    {
                        string transientEntityName = @event.Session.GuessEntityName(transientEntity);

                        transientEntityNames.Add(transientEntityName);

                        log.Info(
                            "transient instance could not be processed by merge: {0} [{1}]",
                            transientEntityName,
                            transientEntity.ToString());
                    }

                    throw new TransientObjectException("one or more objects is an unsaved transient instance - save transient instance(s) before merging: " + String.Join(",", transientEntityNames.ToArray()));
                }
            }

            copyCache.Clear();
        }
		public virtual void OnMerge(MergeEvent @event)
		{
			EventCache copyCache = new EventCache();
			
			OnMerge(@event, copyCache);
			
			// TODO: iteratively get transient entities and retry merge until one of the following conditions:
			//   1) transientCopyCache.size() == 0
			//   2) transientCopyCache.size() is not decreasing and copyCache.size() is not increasing
			
			// TODO: find out if retrying can add entities to copyCache (don't think it can...)
			// For now, just retry once; throw TransientObjectException if there are still any transient entities
			
			IDictionary transientCopyCache = this.GetTransientCopyCache(@event, copyCache);
			
			if (transientCopyCache.Count > 0)
			{
				RetryMergeTransientEntities(@event, transientCopyCache, copyCache);
				
				// find any entities that are still transient after retry
				transientCopyCache = this.GetTransientCopyCache(@event, copyCache);
				
				if (transientCopyCache.Count > 0)
				{
					ISet<string> transientEntityNames = new HashedSet<string>();
					
					foreach (object transientEntity in transientCopyCache.Keys)
					{
						string transientEntityName = @event.Session.GuessEntityName(transientEntity);
						
						transientEntityNames.Add(transientEntityName);
						
						log.InfoFormat(
							"transient instance could not be processed by merge: {0} [{1}]",
							transientEntityName,
							transientEntity.ToString());
					}
					
					throw new TransientObjectException("one or more objects is an unsaved transient instance - save transient instance(s) before merging: " + transientEntityNames);
				}
			}

			copyCache.Clear();
			copyCache = null;
		}
Esempio n. 3
0
        public virtual void OnMerge(MergeEvent @event)
        {
            EventCache copyCache = new EventCache();

            OnMerge(@event, copyCache);

            // TODO: iteratively get transient entities and retry merge until one of the following conditions:
            //   1) transientCopyCache.size() == 0
            //   2) transientCopyCache.size() is not decreasing and copyCache.size() is not increasing

            // TODO: find out if retrying can add entities to copyCache (don't think it can...)
            // For now, just retry once; throw TransientObjectException if there are still any transient entities

            IDictionary transientCopyCache = this.GetTransientCopyCache(@event, copyCache);

            if (transientCopyCache.Count > 0)
            {
                RetryMergeTransientEntities(@event, transientCopyCache, copyCache);

                // find any entities that are still transient after retry
                transientCopyCache = this.GetTransientCopyCache(@event, copyCache);

                if (transientCopyCache.Count > 0)
                {
                    ISet <string> transientEntityNames = new HashedSet <string>();

                    foreach (object transientEntity in transientCopyCache.Keys)
                    {
                        string transientEntityName = @event.Session.GuessEntityName(transientEntity);

                        transientEntityNames.Add(transientEntityName);

                        log.InfoFormat(
                            "transient instance could not be processed by merge: {0} [{1}]",
                            transientEntityName,
                            transientEntity.ToString());
                    }

                    throw new TransientObjectException("one or more objects is an unsaved transient instance - save transient instance(s) before merging: " + transientEntityNames);
                }
            }

            copyCache.Clear();
            copyCache = null;
        }
		public virtual void OnMerge(MergeEvent @event)
		{
			EventCache copyCache = new EventCache();
			
			OnMerge(@event, copyCache);

			// transientCopyCache may contain parent and child entities in random order.
			// Child entities occurring ahead of their respective transient parents may fail 
			// to get merged in one iteration.
			// Retries are necessary as more and more children may be able to merge on subsequent iterations.
			// Iteratively get transient entities and retry merge until one of the following conditions is true:
			//   1) transientCopyCache.size() == 0
			//   2) transientCopyCache.size() is not decreasing
			
			// TODO: find out if retrying can add entities to copyCache (don't think it can...)
			// For now, just retry once; throw TransientObjectException if there are still any transient entities
			
			IDictionary transientCopyCache = this.GetTransientCopyCache(@event, copyCache);
			
			while (transientCopyCache.Count > 0)
			{
				var initialTransientCount = transientCopyCache.Count;

				RetryMergeTransientEntities(@event, transientCopyCache, copyCache);
				
				// find any entities that are still transient after retry
				transientCopyCache = this.GetTransientCopyCache(@event, copyCache);

				// if a retry did nothing, the remaining transient entities 
				// cannot be merged due to references to other transient entities 
				// that are not part of the merge
				if (transientCopyCache.Count == initialTransientCount)
				{
					ISet<string> transientEntityNames = new HashSet<string>();
					
					foreach (object transientEntity in transientCopyCache.Keys)
					{
						string transientEntityName = @event.Session.GuessEntityName(transientEntity);
						
						transientEntityNames.Add(transientEntityName);
						
						log.InfoFormat(
							"transient instance could not be processed by merge: {0} [{1}]",
							transientEntityName,
							transientEntity.ToString());
					}

					throw new TransientObjectException("one or more objects is an unsaved transient instance - save transient instance(s) before merging: " + String.Join(",",  transientEntityNames.ToArray()));
				}
			}

			copyCache.Clear();
		}