コード例 #1
0
 /// <summary>
 /// Sets the flush mode.
 /// </summary>
 /// <param name="session">The session.</param>
 protected void SetFlushMode(ISession session)
 {
     if (FlushAction == FlushAction.Auto)
     {
         session.FlushMode = FlushMode.Auto;
     }
     else if (FlushAction == FlushAction.Never)
     {
         session.FlushMode = FlushMode.Never;
     }
     else if (FlushAction == FlushAction.Config)
     {
         DefaultFlushType behaviour = ActiveRecordStarter.ConfigurationSource.DefaultFlushType;
         session.FlushMode = (behaviour == DefaultFlushType.Classic || behaviour == DefaultFlushType.Auto) ?
                             FlushMode.Auto :
                             (behaviour == DefaultFlushType.Leave) ?
                             FlushMode.Commit :
                             FlushMode.Never;
     }
 }
コード例 #2
0
        private static void AssertConfig(string xmlConfig, Type webinfotype, Type sessionFactoryHolderType, bool isDebug,
                                         DefaultFlushType defaultFlushType)
        {
            StringReader sr = new StringReader(xmlConfig);

            XmlActiveRecordConfiguration c = new XmlActiveRecordConfiguration(sr);

            if (null != webinfotype)
            {
                Assert.IsTrue(c.ThreadScopeInfoImplementation == webinfotype,
                              "Expected {0}, Got {1}", webinfotype, c.ThreadScopeInfoImplementation);
            }

            if (null != sessionFactoryHolderType)
            {
                Assert.IsTrue(c.SessionFactoryHolderImplementation == sessionFactoryHolderType,
                              "Expected {0}, Got {1}", sessionFactoryHolderType, c.SessionFactoryHolderImplementation);
            }

            Assert.IsTrue(c.Debug == isDebug);
            Assert.IsTrue(c.DefaultFlushType == defaultFlushType);
        }
コード例 #3
0
        private void TestBehaviour(DefaultFlushType flushType, FlushMode sessionScopeMode, FlushMode transactionScopeMode)
        {
            ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Post), typeof(Blog));
            Recreate();

            Post.DeleteAll();
            Blog.DeleteAll();

            DefaultFlushType originalDefaultFlushType = ActiveRecordStarter.ConfigurationSource.DefaultFlushType;

            try
            {
                ((InPlaceConfigurationSource)ActiveRecordStarter.ConfigurationSource).DefaultFlushType = flushType;

                Blog blog = new Blog();                 // just for CurrentSession

                using (new SessionScope())
                {
                    Blog.FindAll();
                    Assert.AreEqual(sessionScopeMode, blog.CurrentSession.FlushMode);

                    using (new TransactionScope())
                    {
                        Blog.FindAll();
                        Assert.AreEqual(transactionScopeMode, blog.CurrentSession.FlushMode);
                    }

                    // Properly reset?
                    Blog.FindAll();
                    Assert.AreEqual(sessionScopeMode, blog.CurrentSession.FlushMode);
                }
            }
            finally
            {
                // Restore Default Flush type we corrupted before.
                ((InPlaceConfigurationSource)ActiveRecordStarter.ConfigurationSource).DefaultFlushType = originalDefaultFlushType;
            }
        }
コード例 #4
0
        /// <summary>
        /// Ensures that a transaction exist, creating one if neccecary
        /// </summary>
        /// <param name="session">The session.</param>
        protected internal void EnsureHasTransaction(ISession session)
        {
            if (!transactions.ContainsKey(session))
            {
                DefaultFlushType mode = ActiveRecordStarter.ConfigurationSource.DefaultFlushType;
                session.FlushMode = (mode == DefaultFlushType.Auto || mode == DefaultFlushType.Transaction) ?
                                    FlushMode.Auto :
                                    FlushMode.Commit;

                ITransaction transaction;

                if (isolationLevel == IsolationLevel.Unspecified)
                {
                    transaction = session.BeginTransaction();
                }
                else
                {
                    transaction = session.BeginTransaction(isolationLevel);
                }

                transactions.Add(session, transaction);
            }
        }
コード例 #5
0
        private void TestBehaviour(DefaultFlushType flushType, FlushMode sessionScopeMode, FlushMode transactionScopeMode)
        {
            using (new SessionScope()) {
                Post.DeleteAll();
                Blog.DeleteAll();
            }

            var originalDefaultFlushType = AR.Holder.ConfigurationSource.DefaultFlushType;

            try
            {
                AR.Holder.ConfigurationSource.Flush(flushType);

                var blog = new Blog(); // just for CurrentSession

                using (new SessionScope())
                {
                    Blog.FindAll();
                    Assert.AreEqual(sessionScopeMode, blog.GetCurrentSession().FlushMode);

                    using (new TransactionScope())
                    {
                        Blog.FindAll();
                        Assert.AreEqual(transactionScopeMode, blog.GetCurrentSession().FlushMode);
                    }

                    // Properly reset?
                    Blog.FindAll();
                    Assert.AreEqual(sessionScopeMode, blog.GetCurrentSession().FlushMode);
                }
            }
            finally
            {
                // Restore Default Flush type we corrupted before.
                AR.Holder.ConfigurationSource.Flush(originalDefaultFlushType);
            }
        }
コード例 #6
0
        private void TestBehaviour(DefaultFlushType flushType, FlushMode sessionScopeMode, FlushMode transactionScopeMode)
        {
            ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Post), typeof(Blog));
            Recreate();

            Post.DeleteAll();
            Blog.DeleteAll();

            DefaultFlushType originalDefaultFlushType = ActiveRecordStarter.ConfigurationSource.DefaultFlushType;
            try
            {
                ((InPlaceConfigurationSource)ActiveRecordStarter.ConfigurationSource).DefaultFlushType = flushType;

                Blog blog = new Blog(); // just for CurrentSession

                using (new SessionScope())
                {
                    Blog.FindAll();
                    Assert.AreEqual(sessionScopeMode, blog.CurrentSession.FlushMode);

                    using (new TransactionScope())
                    {
                        Blog.FindAll();
                        Assert.AreEqual(transactionScopeMode, blog.CurrentSession.FlushMode);
                    }

                    // Properly reset?
                    Blog.FindAll();
                    Assert.AreEqual(sessionScopeMode, blog.CurrentSession.FlushMode);
                }
            }
            finally
            {
                // Restore Default Flush type we corrupted before.
                ((InPlaceConfigurationSource)ActiveRecordStarter.ConfigurationSource).DefaultFlushType = originalDefaultFlushType;
            }
        }
コード例 #7
0
        private void TestBehaviour(DefaultFlushType flushType, FlushMode sessionScopeMode, FlushMode transactionScopeMode)
        {
            using (new SessionScope()) {
                Post.DeleteAll();
                Blog.DeleteAll();
            }

            var originalDefaultFlushType = AR.Holder.ConfigurationSource.DefaultFlushType;
            try
            {
                AR.Holder.ConfigurationSource.Flush(flushType);

                var blog = new Blog(); // just for CurrentSession

                using (new SessionScope())
                {
                    Blog.FindAll();
                    Assert.AreEqual(sessionScopeMode, blog.GetCurrentSession().FlushMode);

                    using (new TransactionScope())
                    {
                        Blog.FindAll();
                        Assert.AreEqual(transactionScopeMode, blog.GetCurrentSession().FlushMode);
                    }

                    // Properly reset?
                    Blog.FindAll();
                    Assert.AreEqual(sessionScopeMode, blog.GetCurrentSession().FlushMode);
                }
            }
            finally
            {
                // Restore Default Flush type we corrupted before.
                AR.Holder.ConfigurationSource.Flush(originalDefaultFlushType);
            }
        }
コード例 #8
0
        public void IsUniqueDoesNotDeadlockOnAutoflushTransaction()
        {
            InPlaceConfigurationSource source       = (InPlaceConfigurationSource)GetConfigSource();
            DefaultFlushType           originalType = source.DefaultFlushType;

            try
            {
                ActiveRecordStarter.Initialize(source, typeof(Blog2));
                Recreate();
                source.DefaultFlushType = DefaultFlushType.Auto;

                using (new TransactionScope())
                {
                    Blog2.DeleteAll();
                    Blog2 blog = new Blog2();
                    blog.Name = "FooBar";
                    blog.Save();
                }
            }
            finally
            {
                source.DefaultFlushType = originalType;
            }
        }
コード例 #9
0
        private static void AssertConfig(string xmlConfig, Type webinfotype, Type sessionFactoryHolderType, bool isDebug,
            bool pluralize, bool verifyModelsAgainstDBSchema, DefaultFlushType defaultFlushType, bool searchable)
        {
            StringReader sr = new StringReader(xmlConfig);

            XmlConfigurationSource c = new XmlConfigurationSource(sr);

            if (null != webinfotype)
            {
                Assert.IsTrue(c.ThreadScopeInfoImplementation == webinfotype,
                              "Expected {0}, Got {1}", webinfotype, c.ThreadScopeInfoImplementation);
            }

            if (null != sessionFactoryHolderType)
            {
                Assert.IsTrue(c.SessionFactoryHolderImplementation == sessionFactoryHolderType,
                              "Expected {0}, Got {1}", sessionFactoryHolderType, c.SessionFactoryHolderImplementation);
            }

            Assert.IsTrue(c.Debug == isDebug);
            Assert.IsTrue(c.PluralizeTableNames == pluralize);
            Assert.IsTrue(c.VerifyModelsAgainstDBSchema == verifyModelsAgainstDBSchema);
            Assert.IsTrue(c.DefaultFlushType == defaultFlushType);
            Assert.IsTrue(c.Searchable == searchable);
        }
コード例 #10
0
 private static void AssertConfig(string xmlConfig, Type webinfotype, Type sessionFactoryHolderType, bool isDebug,
     bool pluralize, bool verifyModelsAgainstDBSchema, DefaultFlushType defaultFlushType)
 {
     AssertConfig(xmlConfig, webinfotype, sessionFactoryHolderType, isDebug, pluralize, verifyModelsAgainstDBSchema, defaultFlushType, false);
 }
コード例 #11
0
 public static IActiveRecordConfiguration Flush(this IActiveRecordConfiguration source, DefaultFlushType flushType)
 {
     source.DefaultFlushType = flushType;
     return(source);
 }
コード例 #12
0
 private static void AssertConfig(string xmlConfig, Type webinfotype, Type sessionFactoryHolderType, bool isDebug,
                                  bool pluralize, DefaultFlushType defaultFlushType)
 {
     AssertConfig(xmlConfig, webinfotype, sessionFactoryHolderType, isDebug, defaultFlushType);
 }
コード例 #13
0
 /// <summary>
 /// Sets the value indicating the default flush behaviour.
 /// </summary>
 /// <param name="flushType">The chosen default behaviour.</param>
 protected void SetDefaultFlushType(DefaultFlushType flushType)
 {
     defaultFlushType = flushType;
 }
コード例 #14
0
 /// <summary>
 /// Sets the flush behaviour for <see cref="ISessionScope"/> when no
 /// other behaviour is specified in the scope itself. The default for
 /// this configuration is <see cref="DefaultFlushType.Classic"/>. See
 /// <see cref="DefaultFlushType"/> for what the options mean.
 /// </summary>
 /// <param name="flushType">The default flushing behaviour to set.</param>
 /// <returns>The fluent configuration itself.</returns>
 public FluentActiveRecordConfiguration Flush(DefaultFlushType flushType)
 {
     DefaultFlushType = flushType;
     return(this);
 }
コード例 #15
0
        private static void AssertConfig(string xmlConfig, Type webinfotype, Type sessionFactoryHolderType, bool isDebug,
                                         bool pluralize, bool verifyModelsAgainstDBSchema, DefaultFlushType defaultFlushType, bool searchable)
        {
            StringReader sr = new StringReader(xmlConfig);

            XmlConfigurationSource c = new XmlConfigurationSource(sr);

            if (null != webinfotype)
            {
                Assert.IsTrue(c.ThreadScopeInfoImplementation == webinfotype,
                              "Expected {0}, Got {1}", webinfotype, c.ThreadScopeInfoImplementation);
            }

            if (null != sessionFactoryHolderType)
            {
                Assert.IsTrue(c.SessionFactoryHolderImplementation == sessionFactoryHolderType,
                              "Expected {0}, Got {1}", sessionFactoryHolderType, c.SessionFactoryHolderImplementation);
            }

            Assert.IsTrue(c.Debug == isDebug);
            Assert.IsTrue(c.PluralizeTableNames == pluralize);
            Assert.IsTrue(c.VerifyModelsAgainstDBSchema == verifyModelsAgainstDBSchema);
            Assert.IsTrue(c.DefaultFlushType == defaultFlushType);
            Assert.IsTrue(c.Searchable == searchable);
        }
コード例 #16
0
 private static void AssertConfig(string xmlConfig, Type webinfotype, Type sessionFactoryHolderType, bool isDebug,
                                  bool pluralize, bool verifyModelsAgainstDBSchema, DefaultFlushType defaultFlushType)
 {
     AssertConfig(xmlConfig, webinfotype, sessionFactoryHolderType, isDebug, pluralize, verifyModelsAgainstDBSchema, defaultFlushType, false);
 }
コード例 #17
0
 private static void AssertConfig(string xmlConfig, Type webinfotype, Type sessionFactoryHolderType, bool isDebug,
     bool pluralize, DefaultFlushType defaultFlushType)
 {
     AssertConfig(xmlConfig, webinfotype, sessionFactoryHolderType, isDebug, defaultFlushType);
 }
コード例 #18
0
		/// <summary>
		/// Sets the value determining flush behaviour
		/// </summary>
		/// <param name="flushType">The chosen default behaviour.</param>
		protected void SetDefaultFlushType(DefaultFlushType flushType)
		{
			defaultFlushType = flushType;
		}
コード例 #19
0
        private static void AssertConfig(string xmlConfig, Type webinfotype, Type sessionFactoryHolderType, bool isDebug,
            DefaultFlushType defaultFlushType)
        {
            StringReader sr = new StringReader(xmlConfig);

            XmlActiveRecordConfiguration c = new XmlActiveRecordConfiguration(sr);

            if (null != webinfotype)
            {
                Assert.IsTrue(c.ThreadScopeInfoImplementation == webinfotype,
                              "Expected {0}, Got {1}", webinfotype, c.ThreadScopeInfoImplementation);
            }

            if (null != sessionFactoryHolderType)
            {
                Assert.IsTrue(c.SessionFactoryHolderImplementation == sessionFactoryHolderType,
                              "Expected {0}, Got {1}", sessionFactoryHolderType, c.SessionFactoryHolderImplementation);
            }

            Assert.IsTrue(c.Debug == isDebug);
            Assert.IsTrue(c.DefaultFlushType == defaultFlushType);
        }