Esempio n. 1
0
        public void IncrementTimestampVersion()
        {
            ISession     s = OpenSession();
            ITransaction t = s.BeginTransaction();

            var entity = new TimestampVersioned {
                Name = "ts-vers"
            };

            s.Save(entity);
            t.Commit();
            s.Close();

            DateTime initialVersion = entity.Version;

            Thread.Sleep(300);

            s = OpenSession();
            t = s.BeginTransaction();
            int count = s.CreateQuery("update versioned TimestampVersioned set name = name").ExecuteUpdate();

            Assert.That(count, Is.EqualTo(1), "incorrect exec count");
            t.Commit();

            t      = s.BeginTransaction();
            entity = s.Load <TimestampVersioned>(entity.Id);
            Assert.That(entity.Version, Is.GreaterThan(initialVersion), "version not incremented");

            s.Delete(entity);
            t.Commit();
            s.Close();
        }
        public void InsertWithGeneratedTimestampVersion()
        {
            // Make sure the env supports bulk inserts with generated ids...
            IEntityPersister     persister = Sfi.GetEntityPersister(typeof(TimestampVersioned).FullName);
            IIdentifierGenerator generator = persister.IdentifierGenerator;

            if (!HqlSqlWalker.SupportsIdGenWithBulkInsertion(generator))
            {
                return;
            }

            ISession     s = OpenSession();
            ITransaction t = s.BeginTransaction();

            var entity = new TimestampVersioned {
                Name = "int-vers"
            };

            s.Save(entity);
            s.CreateQuery("select id, name, version from TimestampVersioned").List();
            t.Commit();
            s.Close();

            long initialId = entity.Id;

            //Date initialVersion = entity.getVersion();

            s = OpenSession();
            t = s.BeginTransaction();
            int count =
                s.CreateQuery(
                    "insert into TimestampVersioned ( name, Data ) select name, Data from TimestampVersioned where id = :id")
                .SetInt64("id", entity.Id)
                .ExecuteUpdate();

            t.Commit();
            s.Close();

            Assert.That(count, Is.EqualTo(1), "unexpected insertion count");

            s = OpenSession();
            t = s.BeginTransaction();
            var created =
                (TimestampVersioned)
                s.CreateQuery("from TimestampVersioned where id <> :initialId").SetInt64("initialId", initialId).UniqueResult();

            t.Commit();
            s.Close();

            Assert.That(created.Version, Is.GreaterThan(DateTime.Today));

            s = OpenSession();
            t = s.BeginTransaction();
            s.CreateQuery("delete TimestampVersioned").ExecuteUpdate();
            t.Commit();
            s.Close();
        }
        public void IncrementTimestampVersion()
        {
            TimestampVersioned entity;

            using (ISession s = OpenSession())
                using (ITransaction t = s.BeginTransaction())
                {
                    entity = new TimestampVersioned {
                        Name = "ts-vers", Data = "foo"
                    };
                    s.Save(entity);
                    t.Commit();
                }

            DateTime initialVersion = entity.Version;

            Thread.Sleep(1300);

            using (ISession s = OpenSession())
            {
                using (ITransaction t = s.BeginTransaction())
                {
                    // Note: Update more than one column to showcase NH-3624, which involved losing some columns. /2014-07-26
                    int count = s.CreateQuery("update versioned TimestampVersioned set name = concat(name, 'upd'), Data = concat(Data, 'upd')")
                                .ExecuteUpdate();
                    Assert.That(count, Is.EqualTo(1), "incorrect exec count");
                    t.Commit();
                }

                using (ITransaction t = s.BeginTransaction())
                {
                    entity = s.Load <TimestampVersioned>(entity.Id);
                    s.Delete(entity);
                    t.Commit();
                }
            }

            Assert.That(entity.Version, Is.GreaterThan(initialVersion), "version not incremented");
            Assert.That(entity.Name, Is.EqualTo("ts-versupd"));
            Assert.That(entity.Data, Is.EqualTo("fooupd"));
        }
		public void IncrementTimestampVersion()
		{
			TimestampVersioned entity;

			using (ISession s = OpenSession())
			using(ITransaction t = s.BeginTransaction())
			{
				entity = new TimestampVersioned { Name = "ts-vers", Data = "foo" };
				s.Save(entity);
				t.Commit();
			}

			DateTime initialVersion = entity.Version;

			Thread.Sleep(1300);

			using (ISession s = OpenSession())
			{
				using (ITransaction t = s.BeginTransaction())
				{
					// Note: Update more than one column to showcase NH-3624, which involved losing some columns. /2014-07-26
					int count = s.CreateQuery("update versioned TimestampVersioned set name = concat(name, 'upd'), Data = concat(Data, 'upd')")
						.ExecuteUpdate();
					Assert.That(count, Is.EqualTo(1), "incorrect exec count");
					t.Commit();
				}

				using (ITransaction t = s.BeginTransaction())
				{
					entity = s.Load<TimestampVersioned>(entity.Id);
					s.Delete(entity);
					t.Commit();
				}
			}

			Assert.That(entity.Version, Is.GreaterThan(initialVersion), "version not incremented");
			Assert.That(entity.Name, Is.EqualTo("ts-versupd"));
			Assert.That(entity.Data, Is.EqualTo("fooupd"));
		}
		public void InsertWithGeneratedTimestampVersion()
		{
			// Make sure the env supports bulk inserts with generated ids...
			IEntityPersister persister = sessions.GetEntityPersister(typeof (TimestampVersioned).FullName);
			IIdentifierGenerator generator = persister.IdentifierGenerator;
			if (!HqlSqlWalker.SupportsIdGenWithBulkInsertion(generator))
			{
				return;
			}

			ISession s = OpenSession();
			ITransaction t = s.BeginTransaction();

			var entity = new TimestampVersioned {Name = "int-vers"};
			s.Save(entity);
			s.CreateQuery("select id, name, version from TimestampVersioned").List();
			t.Commit();
			s.Close();

			long initialId = entity.Id;
			//Date initialVersion = entity.getVersion();

			s = OpenSession();
			t = s.BeginTransaction();
			int count =
				s.CreateQuery(
					"insert into TimestampVersioned ( name, Data ) select name, Data from TimestampVersioned where id = :id")
					.SetInt64("id", entity.Id)
					.ExecuteUpdate();
			t.Commit();
			s.Close();

			Assert.That(count, Is.EqualTo(1), "unexpected insertion count");

			s = OpenSession();
			t = s.BeginTransaction();
			var created =
				(TimestampVersioned)
				s.CreateQuery("from TimestampVersioned where id <> :initialId").SetInt64("initialId", initialId).UniqueResult();
			t.Commit();
			s.Close();

			Assert.That(created.Version, Is.GreaterThan(DateTime.Today));

			s = OpenSession();
			t = s.BeginTransaction();
			s.CreateQuery("delete TimestampVersioned").ExecuteUpdate();
			t.Commit();
			s.Close();
		}
		public void IncrementTimestampVersion()
		{
			ISession s = OpenSession();
			ITransaction t = s.BeginTransaction();

			var entity = new TimestampVersioned {Name = "ts-vers"};
			s.Save(entity);
			t.Commit();
			s.Close();

			DateTime initialVersion = entity.Version;

			Thread.Sleep(300);

			s = OpenSession();
			t = s.BeginTransaction();
			int count = s.CreateQuery("update versioned TimestampVersioned set name = name").ExecuteUpdate();
			Assert.That(count, Is.EqualTo(1), "incorrect exec count");
			t.Commit();

			t = s.BeginTransaction();
			entity = s.Load<TimestampVersioned>(entity.Id);
			Assert.That(entity.Version, Is.GreaterThan(initialVersion), "version not incremented");

			s.Delete(entity);
			t.Commit();
			s.Close();
		}