Пример #1
0
		public OneToOneType(string referencedEntityName, ForeignKeyDirection foreignKeyType, string uniqueKeyPropertyName, bool lazy, bool unwrapProxy, bool isEmbeddedInXML, string entityName, string propertyName)
			: base(referencedEntityName, uniqueKeyPropertyName, !lazy, isEmbeddedInXML, unwrapProxy)
		{
			foreignKeyDirection = foreignKeyType;
			this.propertyName = propertyName;
			this.entityName = entityName;
		}
Пример #2
0
		public OneToOneType(
			System.Type persistentClass,
			ForeignKeyDirection foreignKeyDirection,
			string uniqueKeyPropertyName,
			bool lazy)
			: base(
				persistentClass,
				uniqueKeyPropertyName,
				!lazy)
		{
			this.foreignKeyDirection = foreignKeyDirection;
		}
		// Association Types

		/// <summary>
		/// A one-to-one association type for the given class and cascade style.
		/// </summary>
		public static EntityType OneToOne(string persistentClass, ForeignKeyDirection foreignKeyType, string uniqueKeyPropertyName,
			bool lazy, bool unwrapProxy, bool isEmbeddedInXML, string entityName, string propertyName)
		{
			return
				new OneToOneType(persistentClass, foreignKeyType, uniqueKeyPropertyName, lazy, unwrapProxy, isEmbeddedInXML,
												 entityName, propertyName);
		}
		public virtual object Replace(object original, object target, ISessionImplementor session, object owner, IDictionary copyCache,
		                      ForeignKeyDirection foreignKeyDirection)
		{
			bool include;
			if (IsAssociationType)
			{
				IAssociationType atype = (IAssociationType)this;
				include = atype.ForeignKeyDirection == foreignKeyDirection;
			}
			else
			{
				include = ForeignKeyDirection.ForeignKeyFromParent.Equals(foreignKeyDirection);
			}
			return include ? Replace(original, target, session, owner, copyCache) : target;
		}
Пример #5
0
 /// <summary> 
 /// Apply the <see cref="IType.Replace(object, object, ISessionImplementor, object, IDictionary, ForeignKeyDirection)"/> 
 /// operation across a series of values, as
 /// long as the corresponding <see cref="IType"/> is an association.
 /// </summary>
 /// <param name="original">The source of the state </param>
 /// <param name="target">The target into which to replace the source values. </param>
 /// <param name="types">The value types </param>
 /// <param name="session">The orginating session </param>
 /// <param name="owner">The entity "owning" the values </param>
 /// <param name="copyCache">A map representing a cache of already replaced state </param>
 /// <param name="foreignKeyDirection">FK directionality to be applied to the replacement </param>
 /// <returns> The replaced state </returns>
 /// <remarks>
 /// If the corresponding type is a component type, then apply <see cref="ReplaceAssociations"/>
 /// accross the component subtypes but do not replace the component value itself.
 /// </remarks>
 public static object[] ReplaceAssociations(object[] original, object[] target, IType[] types, 
     ISessionImplementor session, object owner, IDictionary copyCache, ForeignKeyDirection foreignKeyDirection)
 {
     object[] copied = new object[original.Length];
     for (int i = 0; i < types.Length; i++)
     {
         if (original[i] == LazyPropertyInitializer.UnfetchedProperty || original[i] == BackrefPropertyAccessor.Unknown)
         {
             copied[i] = target[i];
         }
         else if (types[i].IsComponentType)
         {
             // need to extract the component values and check for subtype replacements...
             IAbstractComponentType componentType = (IAbstractComponentType) types[i];
             IType[] subtypes = componentType.Subtypes;
             object[] origComponentValues = original[i] == null
                                            	? new object[subtypes.Length]
                                            	: componentType.GetPropertyValues(original[i], session);
             object[] targetComponentValues = componentType.GetPropertyValues(target[i], session);
             ReplaceAssociations(origComponentValues, targetComponentValues, subtypes, session, null, copyCache,
                                 foreignKeyDirection);
             copied[i] = target[i];
         }
         else if (!types[i].IsAssociationType)
         {
             copied[i] = target[i];
         }
         else
         {
             copied[i] = types[i].Replace(original[i], target[i], session, owner, copyCache, foreignKeyDirection);
         }
     }
     return copied;
 }
Пример #6
0
 /// <summary>
 /// Apply the <see cref="IType.Replace(object, object, ISessionImplementor, object, IDictionary, ForeignKeyDirection)"/> 
 /// operation across a series of values.
 /// </summary>
 /// <param name="original">The source of the state </param>
 /// <param name="target">The target into which to replace the source values. </param>
 /// <param name="types">The value types </param>
 /// <param name="session">The orginating session </param>
 /// <param name="owner">The entity "owning" the values </param>
 /// <param name="copyCache">A map representing a cache of already replaced state </param>
 /// <param name="foreignKeyDirection">FK directionality to be applied to the replacement </param>
 /// <returns> The replaced state </returns>
 public static object[] Replace(object[] original, object[] target, IType[] types, 
     ISessionImplementor session, object owner, IDictionary copyCache, ForeignKeyDirection foreignKeyDirection)
 {
     object[] copied = new object[original.Length];
     for (int i = 0; i < types.Length; i++)
     {
         if (original[i] == LazyPropertyInitializer.UnfetchedProperty || original[i] == BackrefPropertyAccessor.Unknown)
         {
             copied[i] = target[i];
         }
         else
             copied[i] = types[i].Replace(original[i], target[i], session, owner, copyCache, foreignKeyDirection);
     }
     return copied;
 }
Пример #7
0
        public override async Task <object> ReplaceAsync(object original, object target, ISessionImplementor session, object owner, IDictionary copyCache, ForeignKeyDirection foreignKeyDirection, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            if (original == null)
            {
                return(null);
            }

            object result = target ?? Instantiate(owner, session);

            object[] values = await(TypeHelper.ReplaceAsync(GetPropertyValues(original), GetPropertyValues(result), propertyTypes, session, owner, copyCache, foreignKeyDirection, cancellationToken)).ConfigureAwait(false);

            SetPropertyValues(result, values);
            return(result);
        }
Пример #8
0
		protected virtual void CopyValues(IEntityPersister persister, object entity, object target,
			ISessionImplementor source, IDictionary copyCache, ForeignKeyDirection foreignKeyDirection)
		{
			object[] copiedValues;

			if (foreignKeyDirection == ForeignKeyDirection.ForeignKeyToParent)
			{
				// this is the second pass through on a merge op, so here we limit the
				// replacement to associations types (value types were already replaced
				// during the first pass)
				copiedValues =
					TypeFactory.ReplaceAssociations(persister.GetPropertyValues(entity, source.EntityMode),
					                                persister.GetPropertyValues(target, source.EntityMode), persister.PropertyTypes,
					                                source, target, copyCache, foreignKeyDirection);
			}
			else
			{
				copiedValues =
					TypeFactory.Replace(persister.GetPropertyValues(entity, source.EntityMode),
					                    persister.GetPropertyValues(target, source.EntityMode), persister.PropertyTypes, source, target,
					                    copyCache, foreignKeyDirection);
			}

			persister.SetPropertyValues(target, copiedValues, source.EntityMode);
		}
Пример #9
0
        public override object Replace(object original, object target, ISessionImplementor session, object owner, IDictionary copyCache, ForeignKeyDirection foreignKeyDirection)
        {
            if (original == null)
            {
                return(null);
            }

            object result = target ?? Instantiate(owner, session);

            object[] values = TypeHelper.Replace(GetPropertyValues(original), GetPropertyValues(result), propertyTypes, session, owner, copyCache, foreignKeyDirection);

            SetPropertyValues(result, values);
            return(result);
        }
Пример #10
0
        /// <summary>
        /// Apply the <see cref="IType.ReplaceAsync(object, object, ISessionImplementor, object, IDictionary, ForeignKeyDirection,CancellationToken)" />
        /// operation across a series of values, as long as the corresponding <see cref="IType"/> is an association.
        /// </summary>
        /// <param name="original">The source of the state</param>
        /// <param name="target">The target into which to replace the source values.</param>
        /// <param name="types">The value types</param>
        /// <param name="session">The originating session</param>
        /// <param name="owner">The entity "owning" the values</param>
        /// <param name="copyCache">A map representing a cache of already replaced state</param>
        /// <param name="foreignKeyDirection">FK directionality to be applied to the replacement</param>
        /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
        /// <returns> The replaced state</returns>
        /// <remarks>
        /// If the corresponding type is a component type, then apply <see cref="ReplaceAssociationsAsync(object[],object[],IType[],ISessionImplementor,object,IDictionary,ForeignKeyDirection,CancellationToken)" />
        /// across the component subtypes but do not replace the component value itself.
        /// </remarks>
        public static async Task <object[]> ReplaceAssociationsAsync(object[] original, object[] target, IType[] types,
                                                                     ISessionImplementor session, object owner, IDictionary copyCache, ForeignKeyDirection foreignKeyDirection, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            object[] copied = new object[original.Length];
            for (int i = 0; i < types.Length; i++)
            {
                if (Equals(LazyPropertyInitializer.UnfetchedProperty, original[i]) || Equals(BackrefPropertyAccessor.Unknown, original[i]))
                {
                    copied[i] = target[i];
                }
                else if (types[i].IsComponentType)
                {
                    // need to extract the component values and check for subtype replacements...
                    IAbstractComponentType componentType = (IAbstractComponentType)types[i];
                    IType[]  subtypes              = componentType.Subtypes;
                    object[] origComponentValues   = original[i] == null ? new object[subtypes.Length] : await(componentType.GetPropertyValuesAsync(original[i], session, cancellationToken)).ConfigureAwait(false);
                    object[] targetComponentValues = target[i] == null ? new object[subtypes.Length] : await(componentType.GetPropertyValuesAsync(target[i], session, cancellationToken)).ConfigureAwait(false);

                    object[] componentCopy = await(ReplaceAssociationsAsync(origComponentValues, targetComponentValues, subtypes, session, null, copyCache, foreignKeyDirection, cancellationToken)).ConfigureAwait(false);

                    if (!componentType.IsAnyType && target[i] != null)
                    {
                        componentType.SetPropertyValues(target[i], componentCopy);
                    }

                    copied[i] = target[i];
                }
                else if (!types[i].IsAssociationType)
                {
                    copied[i] = target[i];
                }
                else
                {
                    copied[i] = await(types[i].ReplaceAsync(original[i], target[i], session, owner, copyCache, foreignKeyDirection, cancellationToken)).ConfigureAwait(false);
                }
            }
            return(copied);
        }
Пример #11
0
 /// <summary>
 /// Apply the <see cref="IType.ReplaceAsync(object, object, ISessionImplementor, object, IDictionary, ForeignKeyDirection,CancellationToken)" />
 /// operation across a series of values.
 /// </summary>
 /// <param name="original">The source of the state</param>
 /// <param name="target">The target into which to replace the source values.</param>
 /// <param name="types">The value types</param>
 /// <param name="session">The originating session</param>
 /// <param name="owner">The entity "owning" the values</param>
 /// <param name="copyCache">A map representing a cache of already replaced state</param>
 /// <param name="foreignKeyDirection">FK directionality to be applied to the replacement</param>
 /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
 /// <returns> The replaced state</returns>
 public static async Task <object[]> ReplaceAsync(object[] original, object[] target, IType[] types,
                                                  ISessionImplementor session, object owner, IDictionary copyCache, ForeignKeyDirection foreignKeyDirection, CancellationToken cancellationToken)
 {
     cancellationToken.ThrowIfCancellationRequested();
     object[] copied = new object[original.Length];
     for (int i = 0; i < types.Length; i++)
     {
         if (Equals(LazyPropertyInitializer.UnfetchedProperty, original[i]) || Equals(BackrefPropertyAccessor.Unknown, original[i]))
         {
             copied[i] = target[i];
         }
         else if (target[i] == LazyPropertyInitializer.UnfetchedProperty)
         {
             // Should be no need to check for target[i] == PropertyAccessStrategyBackRefImpl.UNKNOWN
             // because PropertyAccessStrategyBackRefImpl.get( object ) returns
             // PropertyAccessStrategyBackRefImpl.UNKNOWN, so target[i] == original[i].
             //
             // We know from above that original[i] != LazyPropertyInitializer.UNFETCHED_PROPERTY &&
             // original[i] != PropertyAccessStrategyBackRefImpl.UNKNOWN;
             // This is a case where the entity being merged has a lazy property
             // that has been initialized. Copy the initialized value from original.
             if (types[i].IsMutable)
             {
                 copied[i] = types[i].DeepCopy(original[i], session.Factory);
             }
             else
             {
                 copied[i] = original[i];
             }
         }
         else
         {
             copied[i] = await(types[i].ReplaceAsync(original[i], target[i], session, owner, copyCache, foreignKeyDirection, cancellationToken)).ConfigureAwait(false);
         }
     }
     return(copied);
 }
Пример #12
0
 /// <summary>
 /// Apply the <see cref="IType.Replace(object, object, ISessionImplementor, object, IDictionary, ForeignKeyDirection)" />
 /// operation across a series of values.
 /// </summary>
 /// <param name="original">The source of the state</param>
 /// <param name="target">The target into which to replace the source values.</param>
 /// <param name="types">The value types</param>
 /// <param name="session">The originating session</param>
 /// <param name="owner">The entity "owning" the values</param>
 /// <param name="copyCache">A map representing a cache of already replaced state</param>
 /// <param name="foreignKeyDirection">FK directionality to be applied to the replacement</param>
 /// <returns> The replaced state</returns>
 public static object[] Replace(object[] original, object[] target, IType[] types,
                                ISessionImplementor session, object owner, IDictionary copyCache, ForeignKeyDirection foreignKeyDirection)
 {
     object[] copied = new object[original.Length];
     for (int i = 0; i < types.Length; i++)
     {
         if (Equals(LazyPropertyInitializer.UnfetchedProperty, original[i]) || Equals(BackrefPropertyAccessor.Unknown, original[i]))
         {
             copied[i] = target[i];
         }
         else
         {
             copied[i] = types[i].Replace(original[i], target[i], session, owner, copyCache, foreignKeyDirection);
         }
     }
     return(copied);
 }
Пример #13
0
        /// <summary>
        /// Apply the <see cref="IType.Replace(object, object, ISessionImplementor, object, IDictionary, ForeignKeyDirection)" />
        /// operation across a series of values, as long as the corresponding <see cref="IType"/> is an association.
        /// </summary>
        /// <param name="original">The source of the state</param>
        /// <param name="target">The target into which to replace the source values.</param>
        /// <param name="types">The value types</param>
        /// <param name="session">The originating session</param>
        /// <param name="owner">The entity "owning" the values</param>
        /// <param name="copyCache">A map representing a cache of already replaced state</param>
        /// <param name="foreignKeyDirection">FK directionality to be applied to the replacement</param>
        /// <returns> The replaced state</returns>
        /// <remarks>
        /// If the corresponding type is a component type, then apply <see cref="ReplaceAssociations" />
        /// across the component subtypes but do not replace the component value itself.
        /// </remarks>
        public static object[] ReplaceAssociations(object[] original, object[] target, IType[] types,
                                                   ISessionImplementor session, object owner, IDictionary copyCache, ForeignKeyDirection foreignKeyDirection)
        {
            object[] copied = new object[original.Length];
            for (int i = 0; i < types.Length; i++)
            {
                if (original[i] == LazyPropertyInitializer.UnfetchedProperty || original[i] == BackrefPropertyAccessor.Unknown)
                {
                    copied[i] = target[i];
                }
                else if (types[i].IsComponentType)
                {
                    // need to extract the component values and check for subtype replacements...
                    IAbstractComponentType componentType = (IAbstractComponentType)types[i];
                    IType[]  subtypes              = componentType.Subtypes;
                    object[] origComponentValues   = original[i] == null ? new object[subtypes.Length] : componentType.GetPropertyValues(original[i], session);
                    object[] targetComponentValues = target[i] == null ? new object[subtypes.Length] : componentType.GetPropertyValues(target[i], session);

                    object[] componentCopy = ReplaceAssociations(origComponentValues, targetComponentValues, subtypes, session, null, copyCache, foreignKeyDirection);

                    if (!componentType.IsAnyType && target[i] != null)
                    {
                        componentType.SetPropertyValues(target[i], componentCopy, session.EntityMode);
                    }

                    copied[i] = target[i];
                }
                else if (!types[i].IsAssociationType)
                {
                    copied[i] = target[i];
                }
                else
                {
                    copied[i] = types[i].Replace(original[i], target[i], session, owner, copyCache, foreignKeyDirection);
                }
            }
            return(copied);
        }
Пример #14
0
 /// <summary>
 /// Apply the <see cref="IType.ReplaceAsync(object, object, ISessionImplementor, object, IDictionary, ForeignKeyDirection,CancellationToken)" />
 /// operation across a series of values.
 /// </summary>
 /// <param name="original">The source of the state</param>
 /// <param name="target">The target into which to replace the source values.</param>
 /// <param name="types">The value types</param>
 /// <param name="session">The originating session</param>
 /// <param name="owner">The entity "owning" the values</param>
 /// <param name="copyCache">A map representing a cache of already replaced state</param>
 /// <param name="foreignKeyDirection">FK directionality to be applied to the replacement</param>
 /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
 /// <returns> The replaced state</returns>
 public static async Task <object[]> ReplaceAsync(object[] original, object[] target, IType[] types,
                                                  ISessionImplementor session, object owner, IDictionary copyCache, ForeignKeyDirection foreignKeyDirection, CancellationToken cancellationToken)
 {
     cancellationToken.ThrowIfCancellationRequested();
     object[] copied = new object[original.Length];
     for (int i = 0; i < types.Length; i++)
     {
         if (Equals(LazyPropertyInitializer.UnfetchedProperty, original[i]) || Equals(BackrefPropertyAccessor.Unknown, original[i]))
         {
             copied[i] = target[i];
         }
         else
         {
             copied[i] = await(types[i].ReplaceAsync(original[i], target[i], session, owner, copyCache, foreignKeyDirection, cancellationToken)).ConfigureAwait(false);
         }
     }
     return(copied);
 }
		public SpecialOneToOneType(string referencedEntityName, ForeignKeyDirection foreignKeyType, string uniqueKeyPropertyName, bool lazy, bool unwrapProxy, string entityName, string propertyName)
			: base(referencedEntityName, foreignKeyType, uniqueKeyPropertyName, lazy, unwrapProxy, true, entityName, propertyName)
		{
		}
			public object Replace(object original, object target, ISessionImplementor session, object owner, IDictionary copyCache, ForeignKeyDirection foreignKeyDirection)
			{
				throw new InvalidOperationException();
			}
Пример #17
0
			public object Replace(object original, object target, ISessionImplementor session, object owner, IDictionary copyCache, ForeignKeyDirection foreignKeyDirection)
			{
				return RealType.Replace(original, target, session, owner, copyCache, foreignKeyDirection);
			}
Пример #18
0
		public override object Replace(object original, object target, ISessionImplementor session, object owner, IDictionary copyCache, ForeignKeyDirection foreignKeyDirection)
		{
			if (original == null)
				return null;

			object result = target ?? Instantiate(owner, session);

			EntityMode entityMode = session.EntityMode;
			object[] values = TypeHelper.Replace(GetPropertyValues(original, entityMode), GetPropertyValues(result, entityMode), propertyTypes, session, owner, copyCache, foreignKeyDirection);

			SetPropertyValues(result, values, entityMode);
			return result;
		}
 public SpecialOneToOneType(string referencedEntityName, ForeignKeyDirection foreignKeyType, string uniqueKeyPropertyName, bool lazy, bool unwrapProxy, string entityName, string propertyName)
     : base(referencedEntityName, foreignKeyType, uniqueKeyPropertyName, lazy, unwrapProxy, entityName, propertyName)
 {
 }