VoteCommit() public method

Votes to commit the transaction
public VoteCommit ( ) : void
return void
コード例 #1
0
        public void ExplicitFlushInsideSecondTransactionProblem()
        {
            var comp1 = new Company("comp1");
            var comp2 = new Company("comp2");
            using(new SessionScope())
            {
                comp1.Create();
                comp2.Create();
            }

            using(new SessionScope(FlushAction.Never))
            {
                using(var tx = new TransactionScope(ondispose: OnDispose.Rollback))
                {
                    var comp2a = Company.Find(comp2.Id);
                    comp2a.Name = "changed";
                    tx.VoteCommit();
                }

                using(var scope = new TransactionScope(ondispose: OnDispose.Rollback))
                {
                    var changedCompanies = AR.FindAllByProperty<Company>("Name", "changed");
                    Assert.AreEqual(1, changedCompanies.Count());
                    var e2a = changedCompanies.First();
                    e2a.Delete();

                    scope.Flush();

                    Assert.AreEqual(0, AR.FindAllByProperty<Company>("Name", "changed").Count());
                }
            }
        }
コード例 #2
0
        public void LotsOfNestedTransactionWithDifferentConfigurations()
        {
            using(var root = new TransactionScope())
            {
                using(var t1 = new TransactionScope()) // Isolated
                {
                    var blog = new Blog();

                    Blog.FindAll(); // Just to force a session association

                    using(new TransactionScope(TransactionMode.Inherits))
                    {
                        Blog.FindAll(); // Just to force a session association

                        blog.Author = "hammett";
                        blog.Name = "some name";
                        blog.Save();
                    }

                    using(new TransactionScope(TransactionMode.Inherits))
                    {
                        var post = new Post(blog, "title", "post contents", "Castle");

                        post.Save();
                    }

                    t1.VoteRollBack();
                }

                Blog.FindAll(); // Cant be locked

                using(new TransactionScope())
                {
                    var blog = new Blog();
                    Blog.FindAll(); // Just to force a session association

                    using(new TransactionScope())
                    {
                        Blog.FindAll(); // Just to force a session association

                        blog.Author = "hammett";
                        blog.Name = "some name";
                        blog.Save();
                    }

                    using(var t1n = new TransactionScope(TransactionMode.Inherits))
                    {
                        var post = new Post(blog, "title", "post contents", "Castle");

                        try
                        {
                            post.SaveWithException();
                        }
                        catch(Exception)
                        {
                            t1n.VoteRollBack();
                        }
                    }
                }

                root.VoteCommit();
            }

            using (new SessionScope()) {
                var blogs = Blog.FindAll().ToArray();
                Assert.AreEqual(1, blogs.Length);

                var posts = Post.FindAll().ToArray();
                Assert.AreEqual(0, posts.Length);
            }
        }
コード例 #3
0
        public void NestedTransactionWithRollbackOnDispose()
        {
            using(new TransactionScope())
            {
                var blog = new Blog();

                using(var t1 = new TransactionScope(TransactionMode.Inherits, ondispose: OnDispose.Rollback))
                {
                    blog.Author = "hammett";
                    blog.Name = "some name";
                    blog.Save();

                    t1.VoteCommit();
                }

                using(var t2 = new TransactionScope(TransactionMode.Inherits, ondispose: OnDispose.Rollback))
                {
                    var post = new Post(blog, "title", "post contents", "Castle");

                    try
                    {
                        post.SaveWithException();

                        t2.VoteCommit(); // Will never be called
                    }
                    catch(Exception)
                    {
                        // t2.VoteRollBack();
                    }
                }
            }

            using (new SessionScope()) {
                var blogs = Blog.FindAll().ToArray();
                Assert.AreEqual(0, blogs.Length);

                var posts = Post.FindAll().ToArray();
                Assert.AreEqual(0, posts.Length);
            }
        }