Spring.Data.NHibernate.SessionFactoryUtils.GetNewSession C# (CSharp) Method

GetNewSession() public static method

Get a new Hibernate Session from the given SessionFactory. Will return a new Session even if there already is a pre-bound Session for the given SessionFactory.
Within a transaction, this method will create a new Session that shares the transaction's ADO.NET Connection. More specifically, it will use the same ADO.NET Connection as the pre-bound Hibernate Session.
If could not open Hibernate session
public static GetNewSession ( ISessionFactory sessionFactory, IInterceptor interceptor ) : ISession
sessionFactory ISessionFactory The session factory to create the session with.
interceptor IInterceptor The Hibernate entity interceptor, or null if none.
return ISession
	    public static ISession GetNewSession(ISessionFactory sessionFactory, IInterceptor interceptor)
	    {
            try 
            {
                SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.GetResource(sessionFactory);
                if (sessionHolder != null && !sessionHolder.IsEmpty) 
                {
                    if (interceptor != null) 
                    {
                        return sessionFactory.OpenSession(sessionHolder.AnySession.Connection, interceptor);
                    }
                    else 
                    {
                        return sessionFactory.OpenSession(sessionHolder.AnySession.Connection);
                    }
                }
                else 
                {
                    if (interceptor != null) 
                    {
                        return sessionFactory.OpenSession(interceptor);
                    }
                    else 
                    {
                        return sessionFactory.OpenSession();
                    }
                }
            }
            catch (HibernateException ex) 
            {
                throw new DataAccessResourceFailureException("Could not open Hibernate Session", ex);
            }
	    }