public void IncrementCounterVersion() { ISession s = OpenSession(); ITransaction t = s.BeginTransaction(); var entity = new IntegerVersioned { Name = "int-vers" }; s.Save(entity); t.Commit(); s.Close(); int initialVersion = entity.Version; s = OpenSession(); t = s.BeginTransaction(); int count = s.CreateQuery("update versioned IntegerVersioned set name = name").ExecuteUpdate(); Assert.That(count, Is.EqualTo(1), "incorrect exec count"); t.Commit(); t = s.BeginTransaction(); entity = s.Load <IntegerVersioned>(entity.Id); Assert.That(entity.Version, Is.EqualTo(initialVersion + 1), "version not incremented"); s.Delete(entity); t.Commit(); s.Close(); }
public void InsertWithGeneratedVersionAndId() { // Make sure the env supports bulk inserts with generated ids... IEntityPersister persister = sessions.GetEntityPersister(typeof(IntegerVersioned).FullName); IIdentifierGenerator generator = persister.IdentifierGenerator; if (!HqlSqlWalker.SupportsIdGenWithBulkInsertion(generator)) { return; } ISession s = OpenSession(); ITransaction t = s.BeginTransaction(); var entity = new IntegerVersioned { Name = "int-vers" }; s.Save(entity); s.CreateQuery("select id, name, version from IntegerVersioned").List(); t.Commit(); s.Close(); long initialId = entity.Id; int initialVersion = entity.Version; s = OpenSession(); t = s.BeginTransaction(); int count = s.CreateQuery("insert into IntegerVersioned ( name ) select name from IntegerVersioned").ExecuteUpdate(); t.Commit(); s.Close(); Assert.That(count, Is.EqualTo(1), "unexpected insertion count"); s = OpenSession(); t = s.BeginTransaction(); var created = (IntegerVersioned) s.CreateQuery("from IntegerVersioned where id <> :initialId").SetInt64("initialId", initialId).UniqueResult(); t.Commit(); s.Close(); Assert.That(created.Version, Is.EqualTo(initialVersion), "version was not seeded"); s = OpenSession(); t = s.BeginTransaction(); s.CreateQuery("delete IntegerVersioned").ExecuteUpdate(); t.Commit(); s.Close(); }
public void IncrementCounterVersion() { ISession s = OpenSession(); ITransaction t = s.BeginTransaction(); var entity = new IntegerVersioned {Name = "int-vers"}; s.Save(entity); t.Commit(); s.Close(); int initialVersion = entity.Version; s = OpenSession(); t = s.BeginTransaction(); int count = s.CreateQuery("update versioned IntegerVersioned set name = name").ExecuteUpdate(); Assert.That(count, Is.EqualTo(1), "incorrect exec count"); t.Commit(); t = s.BeginTransaction(); entity = s.Load<IntegerVersioned>(entity.Id); Assert.That(entity.Version, Is.EqualTo(initialVersion + 1), "version not incremented"); s.Delete(entity); t.Commit(); s.Close(); }
public void InsertWithGeneratedVersionAndId() { // Make sure the env supports bulk inserts with generated ids... IEntityPersister persister = sessions.GetEntityPersister(typeof (IntegerVersioned).FullName); IIdentifierGenerator generator = persister.IdentifierGenerator; if (!HqlSqlWalker.SupportsIdGenWithBulkInsertion(generator)) { return; } ISession s = OpenSession(); ITransaction t = s.BeginTransaction(); var entity = new IntegerVersioned {Name = "int-vers"}; s.Save(entity); s.CreateQuery("select id, name, version from IntegerVersioned").List(); t.Commit(); s.Close(); long initialId = entity.Id; int initialVersion = entity.Version; s = OpenSession(); t = s.BeginTransaction(); int count = s.CreateQuery("insert into IntegerVersioned ( name ) select name from IntegerVersioned").ExecuteUpdate(); t.Commit(); s.Close(); Assert.That(count, Is.EqualTo(1), "unexpected insertion count"); s = OpenSession(); t = s.BeginTransaction(); var created = (IntegerVersioned) s.CreateQuery("from IntegerVersioned where id <> :initialId").SetInt64("initialId", initialId).UniqueResult(); t.Commit(); s.Close(); Assert.That(created.Version, Is.EqualTo(initialVersion), "version was not seeded"); s = OpenSession(); t = s.BeginTransaction(); s.CreateQuery("delete IntegerVersioned").ExecuteUpdate(); t.Commit(); s.Close(); }