Example #1
0
        /// <summary>
        /// Called from <c>Flush()</c>. The return value determines whether the entity is updated
        /// </summary>
        /// <remarks>
        ///		<list>
        ///			<item>an array of property indicies - the entity is dirty</item>
        ///			<item>an empty array - the entity is not dirty</item>
        ///			<item><c>null</c> - use Hibernate's default dirty-checking algorithm</item>
        ///		</list>
        /// </remarks>
        /// <param name="entity">A persistent entity</param>
        /// <param name="currentState"></param>
        /// <param name="id"></param>
        /// <param name="previousState"></param>
        /// <param name="propertyNames"></param>
        /// <param name="types"></param>
        /// <returns>An array of dirty property indicies or <c>null</c> to choose default behavior</returns>
        public override int[] FindDirty(object entity, object id, object[] currentState, object[] previousState, string[] propertyNames, IType[] types)
        {
            ActiveRecordHooksBase hookTarget = entity as ActiveRecordHooksBase;

            if (hookTarget != null)
            {
                return(hookTarget.FindDirty(id, new DictionaryAdapter(propertyNames, previousState), new DictionaryAdapter(propertyNames, currentState), types));
            }

            return(null);
        }
Example #2
0
        /// <summary>
        /// Called when a transient entity is passed to <c>SaveOrUpdate</c>.
        /// </summary>
        /// <remarks>
        ///	The return value determines if the object is saved
        ///	<list>
        ///		<item><see langword="true" /> - the entity is passed to <c>Save()</c>, resulting in an <c>INSERT</c></item>
        ///		<item><see langword="false" /> - the entity is passed to <c>Update()</c>, resulting in an <c>UPDATE</c></item>
        ///		<item><see langword="null" /> - Hibernate uses the <c>unsaved-value</c> mapping to determine if the object is unsaved</item>
        ///	</list>
        /// </remarks>
        /// <param name="entity">A transient entity</param>
        /// <returns>Boolean or <see langword="null" /> to choose default behaviour</returns>
        public override bool?IsTransient(object entity)
        {
            ActiveRecordHooksBase hookTarget = entity as ActiveRecordHooksBase;

            if (hookTarget != null)
            {
                return(hookTarget.IsUnsaved());
            }

            return(null);
        }
Example #3
0
        /// <summary>
        /// Called before an object is saved
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="id"></param>
        /// <param name="propertyNames"></param>
        /// <param name="state"></param>
        /// <param name="types"></param>
        /// <remarks>
        /// The interceptor may modify the <c>state</c>, which will be used for the SQL <c>INSERT</c>
        /// and propagated to the persistent object
        /// </remarks>
        /// <returns><c>true</c> if the user modified the <c>state</c> in any way</returns>
        public override bool OnSave(object entity, object id, object[] state, string[] propertyNames, IType[] types)
        {
            ActiveRecordHooksBase hookTarget = entity as ActiveRecordHooksBase;

            if (hookTarget != null)
            {
                return(hookTarget.BeforeSave(new DictionaryAdapter(propertyNames, state)));
            }

            return(false);
        }
Example #4
0
        /// <summary>
        /// Called after a flush that actually ends in execution of the SQL statements required to
        /// synchronize in-memory state with the database.
        /// </summary>
        /// <param name="entities">The entitites</param>
        public override void PostFlush(ICollection entities)
        {
            foreach (object entity in entities)
            {
                ActiveRecordHooksBase hookTarget = entity as ActiveRecordHooksBase;

                if (hookTarget != null)
                {
                    hookTarget.PostFlush();
                }
            }
        }