コード例 #1
0
        /// <summary>
        /// Invokes the specified delegate passing a valid
        /// NHibernate session. Used for custom NHibernate queries.
        /// </summary>
        /// <param name="targetType">The target ActiveRecordType</param>
        /// <param name="call">The delegate instance</param>
        /// <param name="instance">The ActiveRecord instance</param>
        /// <returns>Whatever is returned by the delegate invocation</returns>
        protected internal static object Execute(Type targetType, NHibernateDelegate call, object instance)
        {
            if (targetType == null)
            {
                throw new ArgumentNullException("targetType", "Target type must be informed");
            }
            if (call == null)
            {
                throw new ArgumentNullException("call", "Delegate must be passed");
            }

            EnsureInitialized(targetType);

            ISession session = _holder.CreateSession(targetType);

            try
            {
                return(call(session, instance));
            }
            catch (Exception ex)
            {
                throw new ActiveRecordException("Error performing Execute for " + targetType.Name, ex);
            }
            finally
            {
                _holder.ReleaseSession(session);
            }
        }
コード例 #2
0
        /// <summary>
        /// Invokes the specified delegate passing a valid
        /// NHibernate session. Used for custom NHibernate queries.
        /// </summary>
        /// <param name="call">The delegate instance</param>
        /// <param name="instance">The ActiveRecord instance</param>
        /// <returns>Whatever is returned by the delegate invocation</returns>
        public object Execute(NHibernateDelegate call, T instance)
        {
            var dados = DetachedCriteria.For <ClasseModelo>();

            var targetType = instance.GetType();

            if (targetType == null)
            {
                throw new ArgumentNullException("targetType", "Target type must be informed");
            }
            if (call == null)
            {
                throw new ArgumentNullException("call", "Delegate must be passed");
            }

            EnsureInitialized(targetType);

            var holder = ActiveRecordMediator.GetSessionFactoryHolder();

            ISession session = holder.CreateSession(targetType);

            try
            {
                return(call(session, instance));
            }
            catch (ValidationException)
            {
                holder.FailSession(session);

                throw;
            }
            catch (Exception ex)
            {
                holder.FailSession(session);

                throw new ActiveRecordException("Error performing Execute for " + targetType.Name, ex);
            }
            finally
            {
                holder.ReleaseSession(session);
            }
        }
コード例 #3
0
 /// <summary>
 /// Invokes the specified delegate passing a valid
 /// NHibernate session. Used for custom NHibernate queries.
 /// </summary>
 /// <param name="targetType">The target ActiveRecordType</param>
 /// <param name="call">The delegate instance</param>
 /// <param name="instance">The ActiveRecord instance</param>
 /// <returns>Whatever is returned by the delegate invocation</returns>
 public static object Execute(Type targetType, NHibernateDelegate call, object instance)
 {
     return ActiveRecordBase.Execute(targetType, call, instance);
 }
コード例 #4
0
        /// <summary>
        /// Invokes the specified delegate passing a valid 
        /// NHibernate session. Used for custom NHibernate queries.
        /// </summary>
        /// <param name="targetType">The target ActiveRecordType</param>
        /// <param name="call">The delegate instance</param>
        /// <param name="instance">The ActiveRecord instance</param>
        /// <returns>Whatever is returned by the delegate invocation</returns>
        protected internal static object Execute(Type targetType, NHibernateDelegate call, object instance)
        {
            if (targetType == null) throw new ArgumentNullException("targetType", "Target type must be informed");
            if (call == null) throw new ArgumentNullException("call", "Delegate must be passed");

            EnsureInitialized(targetType);

            ISession session = holder.CreateSession(targetType);

            try
            {
                return call(session, instance);
            }
            catch (ValidationException)
            {
                holder.FailSession(session);

                throw;
            }
            catch (Exception ex)
            {
                holder.FailSession(session);

                throw new ActiveRecordException("Error performing Execute for " + targetType.Name, ex);
            }
            finally
            {
                holder.ReleaseSession(session);
            }
        }
コード例 #5
0
 /// <summary>
 /// Invokes the specified delegate passing a valid 
 /// NHibernate session. Used for custom NHibernate queries.
 /// </summary>
 /// <param name="call">The delegate instance</param>
 /// <returns>Whatever is returned by the delegate invocation</returns>
 protected internal virtual object Execute(NHibernateDelegate call)
 {
     return Execute(GetType(), call, this);
 }
コード例 #6
0
        public IEnumerable Filter(object collection, string filterString)
        {
            NHibernateDelegate call = (session, obj) => session.CreateFilter(collection, filterString).List();

            return((IEnumerable)ActiveRecordMediator.Execute(typeof(ActiveRecordBase), call, null));
        }
コード例 #7
0
 public virtual object Execute(NHibernateDelegate call)
 {
     return(ActiveRecordBase.Execute(typeof(T), call, this));
 }
コード例 #8
0
 /// <summary>
 /// Invokes the specified delegate passing a valid
 /// NHibernate session. Used for custom NHibernate queries.
 /// </summary>
 /// <param name="targetType">The target ActiveRecordType</param>
 /// <param name="call">The delegate instance</param>
 /// <param name="instance">The ActiveRecord instance</param>
 /// <returns>Whatever is returned by the delegate invocation</returns>
 public static object Execute(Type targetType, NHibernateDelegate call, object instance)
 {
     return(ActiveRecordBase.Execute(targetType, call, instance));
 }
コード例 #9
0
 /// <summary>
 /// Invokes the specified delegate passing a valid
 /// NHibernate session. Used for custom NHibernate queries.
 /// </summary>
 /// <param name="call">The delegate instance</param>
 /// <returns>Whatever is returned by the delegate invocation</returns>
 protected internal object Execute(NHibernateDelegate call)
 {
     return(Execute(this.GetType(), call, this));
 }
コード例 #10
0
 /// <summary>
 /// Invokes the specified delegate passing a valid
 /// NHibernate session. Used for custom NHibernate queries.
 /// </summary>
 /// <param name="call">The delegate instance</param>
 /// <param name="instance">The ActiveRecord instance</param>
 /// <returns>Whatever is returned by the delegate invocation</returns>
 protected static object Execute(NHibernateDelegate call, object instance)
 {
     return(Execute(typeof(T), call, instance));
 }
コード例 #11
0
 /// <summary>
 /// Invokes the specified delegate passing a valid
 /// NHibernate session. Used for custom NHibernate queries.
 /// </summary>
 /// <param name="call">The delegate instance</param>
 /// <param name="instance">The ActiveRecord instance</param>
 /// <returns>Whatever is returned by the delegate invocation</returns>
 public static object Execute(NHibernateDelegate call, T instance)
 {
     return(Execute(typeof(T), call, instance));
 }
コード例 #12
0
 public static void Execute(T instnace, NHibernateDelegate call)
 {
     ActiveRecordBase.Execute(typeof(T), call, instnace);
 }
コード例 #13
0
 protected static R Execute <R>(NHibernateDelegate call)
 {
     return((R)Execute(call, null));
 }