internal StatelessSessionImpl(SessionFactoryImpl factory, ISessionCreationOptions options) : base(factory, options) { // This context is disposed only on session own disposal. This greatly reduces the number of context switches // for most usual session usages. It may cause an irrelevant session id to be set back on disposal, but since all // session entry points are supposed to set it, it should not have any consequences. _context = SessionIdLoggingContext.CreateOrNull(SessionId); try { temporaryPersistenceContext = new StatefulPersistenceContext(this); if (log.IsDebugEnabled()) { log.Debug("[session-id={0}] opened session for session factory: [{1}/{2}]", SessionId, factory.Name, factory.Uuid); } CheckAndUpdateSessionStatus(); } catch { _context?.Dispose(); throw; } }
protected internal AbstractSessionImpl(ISessionFactoryImplementor factory, ISessionCreationOptions options) { _factory = factory; Timestamp = factory.Settings.CacheProvider.NextTimestamp(); _flushMode = options.InitialSessionFlushMode; Interceptor = options.SessionInterceptor ?? EmptyInterceptor.Instance; }
internal StatelessSessionImpl(SessionFactoryImpl factory, ISessionCreationOptions options) : base(factory, options) { using (BeginContext()) { temporaryPersistenceContext = new StatefulPersistenceContext(this); if (log.IsDebugEnabled()) { log.Debug("[session-id={0}] opened session for session factory: [{1}/{2}]", SessionId, factory.Name, factory.Uuid); } CheckAndUpdateSessionStatus(); } }
internal StatelessSessionImpl(SessionFactoryImpl factory, ISessionCreationOptions options) : base(factory, options) { using (BeginContext()) { temporaryPersistenceContext = new StatefulPersistenceContext(this); connectionManager = new ConnectionManager(this, options.UserSuppliedConnection, ConnectionReleaseMode.AfterTransaction, EmptyInterceptor.Instance, options.ShouldAutoJoinTransaction); if (log.IsDebugEnabled()) { log.Debug("[session-id={0}] opened session for session factory: [{1}/{2}]", SessionId, factory.Name, factory.Uuid); } CheckAndUpdateSessionStatus(); } }
protected internal AbstractSessionImpl(ISessionFactoryImplementor factory, ISessionCreationOptions options) { SessionId = factory.Settings.TrackSessionId ? Guid.NewGuid() : Guid.Empty; using (BeginContext()) { _factory = factory; Timestamp = factory.Settings.CacheProvider.NextTimestamp(); _flushMode = options.InitialSessionFlushMode; Interceptor = options.SessionInterceptor ?? EmptyInterceptor.Instance; if (options is ISharedSessionCreationOptions sharedOptions && sharedOptions.IsTransactionCoordinatorShared) { // NH specific implementation: need to port Hibernate transaction management. IsTransactionCoordinatorShared = true; if (options.UserSuppliedConnection != null) { throw new SessionException("Cannot simultaneously share transaction context and specify connection"); } var connectionManager = sharedOptions.ConnectionManager; connectionManager.AddDependentSession(this); ConnectionManager = connectionManager; }
private TenantConfiguration ValidateTenantConfiguration(ISessionFactoryImplementor factory, ISessionCreationOptions options) { if (factory.Settings.MultiTenancyStrategy == MultiTenancyStrategy.None) { return(null); } var tenantConfiguration = ReflectHelper.CastOrThrow <ISessionCreationOptionsWithMultiTenancy>(options, "multi-tenancy").TenantConfiguration; if (string.IsNullOrEmpty(tenantConfiguration?.TenantIdentifier)) { throw new ArgumentException( $"Tenant configuration with `{nameof(TenantConfiguration.TenantIdentifier)}` defined is required for multi-tenancy.", nameof(tenantConfiguration)); } if (_factory.Settings.MultiTenancyConnectionProvider == null) { throw new ArgumentException( $"`{nameof(IMultiTenancyConnectionProvider)}` is required for multi-tenancy." + $" Provide it via '{Cfg.Environment.MultiTenancyConnectionProvider}` session factory setting." + $" You can use `{nameof(AbstractMultiTenancyConnectionProvider)}` as a base."); } return(tenantConfiguration); }