Example #1
0
 /// <summary>
 /// Realiza o Build de um ISession
 /// </summary>
 /// <param name="interceptor"></param>
 /// <returns></returns>
 private NH.ISession BuildSession(NH.IInterceptor interceptor)
 {
     NH.ISessionFactory sessionFactory = this.ContextAttribute.SessionFactoryBuilder.BuildSessionFactory();
     NH.ISessionBuilder sessionBuilder = sessionFactory.WithOptions();
     if (interceptor != null)
     {
         sessionBuilder = sessionBuilder.Interceptor(interceptor);
     }
     sessionBuilder = sessionBuilder.FlushMode(this.IsTransactional ? this.ContextAttribute.SessionFactoryBuilder.TransactionFlushMode : this.ContextAttribute.SessionFactoryBuilder.DefaultFlushMode);
     NH.ISession session = sessionBuilder.OpenSession();
     return(session);
 }
Example #2
0
        /// <summary>
        ///     To facilitate unit testing, this method will reset this object back to its
        ///     original state before it was configured.
        /// </summary>
        public static void Reset()
        {
            if (Storage != null)
            {
                foreach (var session in Storage.GetAllSessions())
                {
                    session.Dispose();
                }
            }

            SessionFactories.Clear();

            Storage = null;
            _registeredInterceptor = null;
        }
Example #3
0
        public static void RegisterInterceptor(NHibernateOrg.IInterceptor interceptor)
        {
            Check.Require(interceptor != null, "interceptor may not be null");

            _registeredInterceptor = interceptor;
        }
Example #4
0
 public NHContext(NHContextAttribute contextAttribute, NH.IInterceptor interceptor, Stack <AbstractContext <NHContextAttribute> > contextStack)
     : base(contextAttribute, contextStack)
 {
     this.Session     = this.BuildSession(interceptor);
     this.Transaction = this.BuildTransaction();
 }
        /// <summary>
        /// Gets a session with or without an interceptor.  This method is not called directly; instead,
        /// it gets invoked from other public methods.
        /// </summary>
        private ISession GetSession(IInterceptor interceptor)
        {
            ISession session = ContextSession;

            if (session == null)
            {
                if (interceptor != null)
                {
                    session = sessionFactory.OpenSession(interceptor);
                }
                else
                {
                    session = sessionFactory.OpenSession();
                }

                ContextSession = session;

                // enable filter of
                //ContextSession.EnableFilter("ActiveData").SetParameter("InactiveCompany", Guid.Empty);
                //ContextSession.EnableFilter("InactiveName");
            }

            return session;
        }
        /// <summary>
        /// Allows you to register an interceptor on a new session.  This may not be called if there is already
        /// an open session attached to the HttpContext.  If you have an interceptor to be used, modify
        /// the HttpModule to call this before calling BeginTransaction().
        /// </summary>
        public void RegisterInterceptor(IInterceptor interceptor)
        {
            ISession session = ContextSession;

            if (session != null && session.IsOpen)
            {
                throw new CacheException("You cannot register an interceptor once a session has already been opened");
            }

            GetSession(interceptor);
        }