public void StaleObjectStateCheckWithEntityPersisterAndOptimisticLock()
        {
            Optimistic optimistic = new Optimistic();

            optimistic.String = "original string";

            try
            {
                using (ISession session = OpenSession())
                {
                    session.Save(optimistic);
                    session.Flush();

                    using (ISession concurrentSession = OpenSession())
                    {
                        Optimistic sameOptimistic = (Optimistic)concurrentSession.Get(typeof(Optimistic), optimistic.Id);
                        sameOptimistic.String = "another string";
                        concurrentSession.Flush();
                    }

                    optimistic.String = "new string";
                    Assert.Throws <StaleObjectStateException>(() => session.Flush());
                }
            }
            finally
            {
                using (ISession session = OpenSession())
                {
                    session.Delete("from Optimistic");
                    session.Flush();
                }
            }
        }
Пример #2
0
        private long AddOptimistic()
        {
            using (var unitOfWork = this.unitOfWorkFactory.Create())
            {
                var optimistic = new Optimistic();

                unitOfWork.Add(optimistic);

                unitOfWork.Save();

                return(optimistic.ID);
            }
        }
        public void DeleteOptimistic()
        {
            using (ISession s = OpenSession())
            {
                Optimistic op = new Optimistic();
                op.Bag = new ArrayList();
                op.Bag.Add("xyz");

                s.Save(op);
            }

            using (ISession s = OpenSession())
            {
                s.Delete("from Optimistic");
                s.Flush();
            }
        }
Пример #4
0
        public async Task DeleteOptimisticAsync()
        {
            using (ISession s = OpenSession())
            {
                Optimistic op = new Optimistic();
                op.Bag = new List <string> {
                    "xyz"
                };

                await(s.SaveAsync(op));
            }

            using (ISession s = OpenSession())
            {
                await(s.DeleteAsync("from Optimistic"));
                await(s.FlushAsync());
            }
        }
        public void DeleteOptimistic()
        {
            using (ISession s = OpenSession())
            {
                Optimistic op = new Optimistic();
                op.Bag = new List <string> {
                    "xyz"
                };

                s.Save(op);
            }

            using (ISession s = OpenSession())
            {
                s.Delete("from Optimistic");
                s.Flush();
            }
        }
Пример #6
0
        public void ExceptionThrownIfIgnoreVersionConventionNotRegistered()
        {
            using (var sessionFactory = this.configuration.CreateSessionFactory())
            {
                using (var unitOfWorkFactory = new SQLiteUnitOfWorkFactory(this.configuration, sessionFactory, null, null, null, null, new ConsoleLogger()))
                {
                    using (var unitOfWork = unitOfWorkFactory.Create())
                    {
                        var safeUnitOfWork = unitOfWork;

                        var optimistic = new Optimistic {
                            StringValue = "test"
                        };

                        Assert.That(() => safeUnitOfWork.Add(optimistic), Throws.InstanceOf <PropertyValueException>());
                    }
                }
            }
        }
Пример #7
0
        public async Task StaleObjectStateCheckWithEntityPersisterAndOptimisticLockAsync()
        {
            Optimistic optimistic = new Optimistic();

            optimistic.String = "original string";

            try
            {
                using (ISession session = OpenSession())
                {
                    await(session.SaveAsync(optimistic));
                    await(session.FlushAsync());

                    using (ISession concurrentSession = OpenSession())
                    {
                        Optimistic sameOptimistic = (Optimistic)await(concurrentSession.GetAsync(typeof(Optimistic), optimistic.Id));
                        sameOptimistic.String = "another string";
                        await(concurrentSession.FlushAsync());
                    }

                    optimistic.String = "new string";

                    var expectedException = Sfi.Settings.IsBatchVersionedDataEnabled
                                                ? Throws.InstanceOf <StaleStateException>()
                                                : Throws.InstanceOf <StaleObjectStateException>();

                    Assert.That(() => session.FlushAsync(), expectedException);
                }
            }
            finally
            {
                using (ISession session = OpenSession())
                {
                    await(session.DeleteAsync("from Optimistic"));
                    await(session.FlushAsync());
                }
            }
        }
        public void StaleObjectStateCheckWithEntityPersisterAndOptimisticLock()
        {
            Optimistic optimistic = new Optimistic();

            optimistic.String = "original string";

            try
            {
                using (ISession session = OpenSession())
                {
                    session.Save(optimistic);
                    session.Flush();

                    using (ISession concurrentSession = OpenSession())
                    {
                        Optimistic sameOptimistic = (Optimistic)concurrentSession.Get(typeof(Optimistic), optimistic.Id);
                        sameOptimistic.String = "another string";
                        concurrentSession.Flush();
                    }

                    optimistic.String = "new string";

                    var expectedException = Sfi.Settings.IsBatchVersionedDataEnabled
                                                ? (IResolveConstraint)Throws.InstanceOf <StaleStateException>().And.Message.Contains("UPDATE Optimistic")
                                                : Throws.InstanceOf <StaleObjectStateException>();

                    Assert.That(() => session.Flush(), expectedException);
                }
            }
            finally
            {
                using (ISession session = OpenSession())
                {
                    session.Delete("from Optimistic");
                    session.Flush();
                }
            }
        }