Exemple #1
0
        public void NestedTransactionsTest()
        {
            var obj = new TestObj {
                Text = "Matthew"
            };

            using (var db = new OrmTestSession())
            {
                db.CreateTable <TestObj>();

                using (var trans1 = db.BeginTransaction())
                {
                    trans1.CreateSavepoint("First");
                    db.Insert(obj);

                    using (var trans2 = db.BeginTransaction())
                    {
                        // rollback on the second trans affects the first as
                        // it is the same transaction
                        trans2.RollbackSavepoint("First");
                    }

                    Assert.AreEqual(db.Table <TestObj>().Count(), 0);
                }
            }
        }
Exemple #2
0
        public void InsertUsingInterweavingSavePoints()
        {
            var obj = new TestObj {
                Text = "Matthew"
            };

            using (var db = new OrmTestSession())
            {
                db.CreateTable <TestObj>();

                using (var trans = db.BeginTransaction())
                {
                    db.Insert(obj);
                    Assert.AreEqual(db.Table <TestObj>().Count(), 1);

                    trans.CreateSavepoint("First");
                    db.Insert(obj);
                    Assert.AreEqual(db.Table <TestObj>().Count(), 2);

                    trans.CreateSavepoint("Second");
                    db.Insert(obj);
                    Assert.AreEqual(db.Table <TestObj>().Count(), 3);

                    trans.RollbackSavepoint("First");

                    trans.Commit();
                }

                Assert.AreEqual(db.Table <TestObj>().Count(), 1);
            }
        }
Exemple #3
0
        public void NestedTransactionsTest()
        {
            int oneTrans;
            int nestedTrans;

            // one transaction
            using (var db = new OrmTestSession())
            {
                SqliteSession.Trace = false;
                db.CreateTable <TestObj>();

                var start = Environment.TickCount;

                const int             n = 500 * 500;
                IEnumerable <TestObj> q = Enumerable.Range(1, n).Select(x => new TestObj {
                    Text = "I am"
                });
                TestObj[] objs  = q.ToArray();
                int       numIn = db.InsertAll(objs);

                oneTrans = Environment.TickCount - start;
            }

            // nested transactions
            using (var db = new OrmTestSession())
            {
                SqliteSession.Trace = false;
                db.CreateTable <TestObj>();

                var start = Environment.TickCount;

                using (var trans = db.BeginTransaction())
                {
                    for (var i = 0; i < 500; ++i)
                    {
                        const int             n = 500;
                        IEnumerable <TestObj> q = Enumerable.Range(1, n).Select(x => new TestObj {
                            Text = "I am"
                        });
                        TestObj[] objs  = q.ToArray();
                        int       numIn = db.InsertAll(objs);
                    }

                    trans.Commit();
                }

                nestedTrans = Environment.TickCount - start;
            }

            System.Diagnostics.Debug.WriteLine("Single tranasction: " + oneTrans);
            System.Diagnostics.Debug.WriteLine("Nested tranasction: " + nestedTrans);
            System.Diagnostics.Debug.WriteLine("Difference: " + Math.Abs(nestedTrans - oneTrans));

            // this is a really dodgy test to use the execution time...
            Assert.IsTrue(Math.Abs(oneTrans - nestedTrans) <= 100);
        }
Exemple #4
0
        public void InsertUsingSavePointsOnACommittedTransaction()
        {
            var obj = new TestObj {
                Text = "Matthew"
            };

            using (var db = new OrmTestSession())
            {
                db.CreateTable <TestObj>();

                var trans = db.BeginTransaction();
                trans.CreateSavepoint("First");
                trans.Commit();

#if SILVERLIGHT || MS_TEST
                ExceptionAssert.Throws <SqliteException>(() => trans.RollbackSavepoint("First"));
#elif NETFX_CORE
                Assert.ThrowsException <SqliteException>(() => trans.RollbackSavepoint("First"));
#else
                Assert.Catch <SqliteException>(() => trans.RollbackSavepoint("First"));
#endif
            }
        }
Exemple #5
0
        public void InsertAllWithinATransactionSucceeds()
        {
            var db = new OrmTestSession();

            db.CreateTable <TestObj>();

            var first = new TestObj {
                Text = "First"
            };
            var second = new TestObj {
                Text = "Second"
            };
            var third = new TestObj {
                Text = "Third"
            };

            using (var trans = db.BeginTransaction())
            {
                var inObjs = db.InsertAll(new[] { first, second, third }, false);
                trans.Commit();
            }

            Assert.AreEqual(3, db.Table <TestObj>().Count());
        }
        public void InsertUsingSavePoints()
        {
            var obj = new TestObj { Text = "Matthew" };

            using (var db = new OrmTestSession())
            {
                db.CreateTable<TestObj>();

                using (var trans = db.BeginTransaction())
                {
                    db.Insert(obj);
                    Assert.AreEqual(db.Table<TestObj>().Count(), 1);

                    trans.CreateSavepoint("First");
                    db.Insert(obj);
                    Assert.AreEqual(db.Table<TestObj>().Count(), 2);

                    trans.RollbackSavepoint("First");

                    trans.Commit();
                }

                Assert.AreEqual(db.Table<TestObj>().Count(), 1);
            }
        }
        public void NestedTransactionsTest()
        {
            var obj = new TestObj { Text = "Matthew" };

            using (var db = new OrmTestSession())
            {
                db.CreateTable<TestObj>();

                using (var trans1 = db.BeginTransaction())
                {
                    trans1.CreateSavepoint("First");
                    db.Insert(obj);

                    using (var trans2 = db.BeginTransaction())
                    {
                        // rollback on the second trans affects the first as 
                        // it is the same transaction 
                        trans2.RollbackSavepoint("First");
                    }

                    Assert.AreEqual(db.Table<TestObj>().Count(), 0);
                }
            }
        }
        public void InsertUsingSavePointsOnACommittedTransaction()
        {
            var obj = new TestObj { Text = "Matthew" };

            using (var db = new OrmTestSession())
            {
                db.CreateTable<TestObj>();

                var trans = db.BeginTransaction();
                trans.CreateSavepoint("First");
                trans.Commit();

#if SILVERLIGHT || MS_TEST
                ExceptionAssert.Throws<SqliteException>(() => trans.RollbackSavepoint("First"));
#elif NETFX_CORE
                Assert.ThrowsException<SqliteException>(() => trans.RollbackSavepoint("First"));
#else
                Assert.Catch<SqliteException>(() => trans.RollbackSavepoint("First"));
#endif
            }
        }
        public void InsertAllWithinATransactionSucceeds()
        {
            var db = new OrmTestSession();
            db.CreateTable<TestObj>();

            var first = new TestObj { Text = "First" };
            var second = new TestObj { Text = "Second" };
            var third = new TestObj { Text = "Third" };

            using (var trans = db.BeginTransaction())
            {
                var inObjs = db.InsertAll(new[] { first, second, third }, false);
                trans.Commit();
            }

            Assert.AreEqual(3, db.Table<TestObj>().Count());
        }
        public void NestedTransactionsTest()
        {
            int oneTrans;
            int nestedTrans;

            // one transaction
            using (var db = new OrmTestSession())
            {
                SqliteSession.Trace = false;
                db.CreateTable<TestObj>();

                var start = Environment.TickCount;

                const int n = 500*500;
                IEnumerable<TestObj> q = Enumerable.Range(1, n).Select(x => new TestObj {Text = "I am"});
                TestObj[] objs = q.ToArray();
                int numIn = db.InsertAll(objs);

                oneTrans = Environment.TickCount - start;
            }

            // nested transactions
            using (var db = new OrmTestSession())
            {
                SqliteSession.Trace = false;
                db.CreateTable<TestObj>();

                var start = Environment.TickCount;

                using (var trans = db.BeginTransaction())
                {
                    for (var i = 0; i < 500; ++i)
                    {
                        const int n = 500;
                        IEnumerable<TestObj> q = Enumerable.Range(1, n).Select(x => new TestObj {Text = "I am"});
                        TestObj[] objs = q.ToArray();
                        int numIn = db.InsertAll(objs);
                    }

                    trans.Commit();
                }

                nestedTrans = Environment.TickCount - start;
            }

            System.Diagnostics.Debug.WriteLine("Single tranasction: " + oneTrans);
            System.Diagnostics.Debug.WriteLine("Nested tranasction: " + nestedTrans);
            System.Diagnostics.Debug.WriteLine("Difference: " + Math.Abs(nestedTrans - oneTrans));

            // this is a really dodgy test to use the execution time...
            Assert.IsTrue(Math.Abs(oneTrans - nestedTrans) <= 100);
        }