public SystemUserSession(IDatabase database, ITransaction transaction, string currentSchema)
 {
     Database = database;
     CurrentSchema =currentSchema;
     Transaction = transaction;
     SessionInfo = new SessionInfo(User.System, transaction.Isolation);
 }
Exemple #2
0
        /// <summary>
        /// Constructs the session for the given user and transaction to the
        /// given database.
        /// </summary>
        /// <param name="database">The database to which the user is connected.</param>
        /// <param name="transaction">A transaction that handles the commands issued by
        /// the user during the session.</param>
        /// <param name="sessionInfo">The information about the session to be created (user, 
        /// connection endpoint, statistics, etc.)</param>
        /// <seealso cref="ITransaction"/>
        /// <seealso cref="SessionInfo"/>
        public UserSession(IDatabase database, ITransaction transaction, SessionInfo sessionInfo)
        {
            if (database == null)
                throw new ArgumentNullException("database");
            if (transaction == null)
                throw new ArgumentNullException("transaction");
            if (sessionInfo == null)
                throw new ArgumentNullException("sessionInfo");

            if (sessionInfo.User.IsSystem ||
                sessionInfo.User.IsPublic)
                throw new ArgumentException(String.Format("Cannot open a session for user '{0}'.", sessionInfo.User.Name));

            Database = database;
            Transaction = transaction;

            Database.DatabaseContext.Sessions.Add(this);

            SessionInfo = sessionInfo;
        }
        public static IUserSession CreateUserSession(this IDatabase database, SessionInfo sessionInfo)
        {
            if (sessionInfo == null)
                throw new ArgumentNullException("sessionInfo");

            // TODO: if the isolation is not specified, use a configured default one
            var isolation = sessionInfo.Isolation;
            if (isolation == IsolationLevel.Unspecified)
                isolation = IsolationLevel.Serializable;

            if (sessionInfo.CommitId >= 0)
                throw new ArgumentException("Cannot create a session that reference an existing commit state.");

            var transaction = database.CreateTransaction(isolation);
            return new UserSession(database, transaction, sessionInfo);
        }
        public static IUserSession OpenUserSession(this IDatabase database, SessionInfo sessionInfo)
        {
            if (sessionInfo == null)
                throw new ArgumentNullException("sessionInfo");

            var commitId = sessionInfo.CommitId;

            if (commitId < 0)
                throw new ArgumentException("Invalid commit reference specified.");

            var transaction = database.FindTransactionById(commitId);
            if (transaction == null)
                throw new InvalidOperationException(String.Format("The request transaction with ID '{0}' is not open.", commitId));

            return new UserSession(database, transaction, sessionInfo);
        }