public async Task GetChildMakeReadOnlyThenMergeDetachedChildWithNewParentAsync() { VersionedNode child = new VersionedNode("child", "child"); using (ISession s = OpenSession()) { s.BeginTransaction(); await(s.PersistAsync(child)); await(s.Transaction.CommitAsync()); } ClearCounts(); child.Name = "new child name"; VersionedNode parent = new VersionedNode("parent", "parent"); parent.AddChild(child); using (ISession s = OpenSession()) { s.BeginTransaction(); VersionedNode childManaged = await(s.GetAsync <VersionedNode>(child.Id)); s.SetReadOnly(childManaged, true); VersionedNode childMerged = (VersionedNode)await(s.MergeAsync(child)); Assert.That(childManaged, Is.SameAs(childMerged)); await(s.Transaction.CommitAsync()); } AssertUpdateCount(0); // NH-specific: Hibernate issues a separate UPDATE for the version number AssertInsertCount(1); ClearCounts(); using (ISession s = OpenSession()) { s.BeginTransaction(); parent = await(s.GetAsync <VersionedNode>(parent.Id)); child = await(s.GetAsync <VersionedNode>(child.Id)); Assert.That(child.Name, Is.EqualTo("child")); Assert.That(child.Parent, Is.Null); Assert.That(child.Version, Is.EqualTo(1)); Assert.That(parent, Is.Not.Null); Assert.That(parent.Children.Count, Is.EqualTo(0)); Assert.That(parent.Version, Is.EqualTo(1)); // NH-specific: Hibernate incorrectly increments version number, NH does not s.SetReadOnly(parent, true); s.SetReadOnly(child, true); await(s.DeleteAsync(parent)); await(s.DeleteAsync(child)); await(s.Transaction.CommitAsync()); } AssertUpdateCount(0); AssertDeleteCount(2); }
public async Task GetParentMakeReadOnlyThenMergeDetachedParentWithNewChildCAsync() { VersionedNode parent = new VersionedNode("parent", "parent"); using (ISession s = OpenSession()) { s.BeginTransaction(); await(s.PersistAsync(parent)); await(s.Transaction.CommitAsync()); } ClearCounts(); parent.Name = "new parent name"; VersionedNode child = new VersionedNode("child", "child"); parent.AddChild(child); using (var s = OpenSession()) { s.BeginTransaction(); VersionedNode parentManaged = await(s.GetAsync <VersionedNode>(parent.Id)); s.SetReadOnly(parentManaged, true); VersionedNode parentMerged = (VersionedNode)await(s.MergeAsync(parent)); Assert.That(parentManaged, Is.SameAs(parentMerged)); await(s.Transaction.CommitAsync()); } AssertUpdateCount(1); AssertInsertCount(1); ClearCounts(); using (var s = OpenSession()) { s.BeginTransaction(); parent = await(s.GetAsync <VersionedNode>(parent.Id)); child = await(s.GetAsync <VersionedNode>(child.Id)); Assert.That(parent.Name, Is.EqualTo("parent")); Assert.That(parent.Children.Count, Is.EqualTo(1)); Assert.That(parent.Version, Is.EqualTo(2)); Assert.That(child.Parent, Is.SameAs(parent)); Assert.That(parent.Children.First(), Is.SameAs(child)); Assert.That(child.Version, Is.EqualTo(1)); await(s.DeleteAsync(parent)); await(s.DeleteAsync(child)); await(s.Transaction.CommitAsync()); } AssertUpdateCount(0); AssertDeleteCount(2); }
public async Task UpdateChildWithNewParentCommitWithReadOnlyChildAsync() { VersionedNode child = new VersionedNode("child", "child"); using (ISession s = OpenSession()) { s.BeginTransaction(); await(s.PersistAsync(child)); await(s.Transaction.CommitAsync()); } ClearCounts(); child.Name = "new child name"; VersionedNode parent = new VersionedNode("parent", "parent"); parent.AddChild(child); using (ISession s = OpenSession()) { s.BeginTransaction(); await(s.UpdateAsync(child)); s.SetReadOnly(child, true); await(s.Transaction.CommitAsync()); } AssertUpdateCount(0); AssertInsertCount(1); ClearCounts(); using (ISession s = OpenSession()) { s.BeginTransaction(); parent = await(s.GetAsync <VersionedNode>(parent.Id)); child = await(s.GetAsync <VersionedNode>(child.Id)); Assert.That(child.Name, Is.EqualTo("child")); Assert.That(child.Parent, Is.Null); Assert.That(child.Version, Is.EqualTo(1)); Assert.That(parent, Is.Not.Null); Assert.That(parent.Children.Count, Is.EqualTo(0)); Assert.That(parent.Version, Is.EqualTo(1)); s.SetReadOnly(parent, true); s.SetReadOnly(child, true); await(s.DeleteAsync(parent)); await(s.DeleteAsync(child)); await(s.Transaction.CommitAsync()); } AssertUpdateCount(0); AssertDeleteCount(2); }
public void GetParentMakeReadOnlyThenMergeDetachedParentWithNewChildC() { ISession s = OpenSession(); s.BeginTransaction(); VersionedNode parent = new VersionedNode("parent", "parent"); s.Persist(parent); s.Transaction.Commit(); s.Close(); ClearCounts(); parent.Name = "new parent name"; VersionedNode child = new VersionedNode("child", "child"); parent.AddChild(child); s = OpenSession(); s.BeginTransaction(); VersionedNode parentManaged = s.Get <VersionedNode>(parent.Id); s.SetReadOnly(parentManaged, true); VersionedNode parentMerged = (VersionedNode)s.Merge(parent); Assert.That(parentManaged, Is.SameAs(parentMerged)); s.Transaction.Commit(); s.Close(); AssertUpdateCount(1); AssertInsertCount(1); ClearCounts(); s = OpenSession(); s.BeginTransaction(); parent = s.Get <VersionedNode>(parent.Id); child = s.Get <VersionedNode>(child.Id); Assert.That(parent.Name, Is.EqualTo("parent")); Assert.That(parent.Children.Count, Is.EqualTo(1)); Assert.That(parent.Version, Is.EqualTo(2)); Assert.That(child.Parent, Is.SameAs(parent)); Assert.That(parent.Children.First(), Is.SameAs(child)); Assert.That(child.Version, Is.EqualTo(1)); s.Delete(parent); s.Delete(child); s.Transaction.Commit(); s.Close(); AssertUpdateCount(0); AssertDeleteCount(2); }
public void MergeDetachedChildWithNewParentCommitWithReadOnlyChild() { VersionedNode child = new VersionedNode("child", "child"); using (ISession s = OpenSession()) { s.BeginTransaction(); s.Persist(child); s.Transaction.Commit(); } ClearCounts(); child.Name = "new child name"; VersionedNode parent = new VersionedNode("parent", "parent"); parent.AddChild(child); using (ISession s = OpenSession()) { s.BeginTransaction(); child = (VersionedNode)s.Merge(child); s.SetReadOnly(child, true); s.Transaction.Commit(); } AssertUpdateCount(0); // NH-specific: Hibernate issues a separate UPDATE for the version number AssertInsertCount(1); ClearCounts(); using (ISession s = OpenSession()) { s.BeginTransaction(); parent = s.Get <VersionedNode>(parent.Id); child = s.Get <VersionedNode>(child.Id); Assert.That(child.Name, Is.EqualTo("child")); Assert.That(child.Parent, Is.Null); Assert.That(child.Version, Is.EqualTo(1)); Assert.That(parent, Is.Not.Null); Assert.That(parent.Children.Count, Is.EqualTo(0)); Assert.That(parent.Version, Is.EqualTo(1)); s.SetReadOnly(parent, true); s.SetReadOnly(child, true); s.Delete(parent); s.Delete(child); s.Transaction.Commit(); } AssertUpdateCount(0); AssertDeleteCount(2); }
public void UpdateParentWithNewChildCommitWithReadOnlyParent() { VersionedNode parent = new VersionedNode("parent", "parent"); using (ISession s = OpenSession()) { s.BeginTransaction(); s.Persist(parent); s.Transaction.Commit(); } ClearCounts(); parent.Name = "new parent name"; VersionedNode child = new VersionedNode("child", "child"); parent.AddChild(child); using (ISession s = OpenSession()) { s.BeginTransaction(); s.Update(parent); s.SetReadOnly(parent, true); s.Transaction.Commit(); } AssertUpdateCount(1); AssertInsertCount(1); ClearCounts(); using (ISession s = OpenSession()) { s.BeginTransaction(); parent = s.Get <VersionedNode>(parent.Id); child = s.Get <VersionedNode>(child.Id); Assert.That(parent.Name, Is.EqualTo("parent")); Assert.That(parent.Children.Count, Is.EqualTo(1)); Assert.That(parent.Version, Is.EqualTo(2)); Assert.That(child.Parent, Is.SameAs(parent)); Assert.That(parent.Children.First(), Is.SameAs(child)); Assert.That(child.Version, Is.EqualTo(1)); s.SetReadOnly(parent, true); s.SetReadOnly(child, true); s.Delete(parent); s.Delete(child); s.Transaction.Commit(); } AssertUpdateCount(0); AssertDeleteCount(2); }
public void UpdateChildWithNewParentCommitWithReadOnlyChild() { ISession s = OpenSession(); s.BeginTransaction(); VersionedNode child = new VersionedNode("child", "child"); s.Persist(child); s.Transaction.Commit(); s.Close(); ClearCounts(); child.Name = "new child name"; VersionedNode parent = new VersionedNode("parent", "parent"); parent.AddChild(child); s = OpenSession(); s.BeginTransaction(); s.Update(child); s.SetReadOnly(child, true); s.Transaction.Commit(); s.Close(); AssertUpdateCount(0); AssertInsertCount(1); ClearCounts(); s = OpenSession(); s.BeginTransaction(); parent = s.Get <VersionedNode>(parent.Id); child = s.Get <VersionedNode>(child.Id); Assert.That(child.Name, Is.EqualTo("child")); Assert.That(child.Parent, Is.Null); Assert.That(child.Version, Is.EqualTo(1)); Assert.That(parent, Is.Not.Null); Assert.That(parent.Children.Count, Is.EqualTo(0)); Assert.That(parent.Version, Is.EqualTo(1)); s.SetReadOnly(parent, true); s.SetReadOnly(child, true); s.Delete(parent); s.Delete(child); s.Transaction.Commit(); s.Close(); AssertUpdateCount(0); AssertDeleteCount(2); }
public void AddNewParentToReadOnlyChild() { VersionedNode child = new VersionedNode("child", "child"); using (ISession s = OpenSession()) { s.BeginTransaction(); s.Persist(child); s.Transaction.Commit(); } ClearCounts(); VersionedNode parent = new VersionedNode("parent", "parent"); using (ISession s = OpenSession()) { s.BeginTransaction(); VersionedNode childManaged = s.Get <VersionedNode>(child.Id); s.SetReadOnly(childManaged, true); childManaged.Name = "new child name"; parent.AddChild(childManaged); s.Transaction.Commit(); } AssertUpdateCount(0); AssertInsertCount(1); using (ISession s = OpenSession()) { s.BeginTransaction(); child = s.Get <VersionedNode>(child.Id); Assert.That(child.Name, Is.EqualTo("child")); Assert.That(child.Parent, Is.Null); Assert.That(child.Version, Is.EqualTo(1)); parent = s.Get <VersionedNode>(parent.Id); Assert.That(parent, Is.Not.Null); s.SetReadOnly(child, true); s.Delete(child); s.Transaction.Commit(); } AssertUpdateCount(0); AssertDeleteCount(1); }
public async Task AddNewChildToReadOnlyParentAsync() { VersionedNode parent = new VersionedNode("parent", "parent"); using (var s = OpenSession()) using (var t = s.BeginTransaction()) { s.CacheMode = CacheMode.Ignore; await(s.PersistAsync(parent)); await(t.CommitAsync()); } ClearCounts(); VersionedNode child = new VersionedNode("child", "child"); using (var s = OpenSession()) using (var t = s.BeginTransaction()) { s.CacheMode = CacheMode.Ignore; VersionedNode parentManaged = await(s.GetAsync <VersionedNode>(parent.Id)); s.SetReadOnly(parentManaged, true); parentManaged.Name = "new parent name"; parentManaged.AddChild(child); await(s.SaveAsync(parentManaged)); await(t.CommitAsync()); } AssertUpdateCount(1); AssertInsertCount(1); using (var s = OpenSession()) using (var t = s.BeginTransaction()) { s.CacheMode = CacheMode.Ignore; parent = await(s.GetAsync <VersionedNode>(parent.Id)); Assert.That(parent.Name, Is.EqualTo("parent")); Assert.That(parent.Children.Count, Is.EqualTo(1)); Assert.That(parent.Version, Is.EqualTo(2)); child = await(s.GetAsync <VersionedNode>(child.Id)); Assert.That(child, Is.Not.Null); await(s.DeleteAsync(parent)); await(t.CommitAsync()); } }
public async Task AddNewParentToReadOnlyChildAsync() { VersionedNode child = new VersionedNode("child", "child"); using (var s = OpenSession()) using (var t = s.BeginTransaction()) { await(s.PersistAsync(child)); await(t.CommitAsync()); } ClearCounts(); VersionedNode parent = new VersionedNode("parent", "parent"); using (var s = OpenSession()) using (var t = s.BeginTransaction()) { VersionedNode childManaged = await(s.GetAsync <VersionedNode>(child.Id)); s.SetReadOnly(childManaged, true); childManaged.Name = "new child name"; parent.AddChild(childManaged); await(t.CommitAsync()); } AssertUpdateCount(0); AssertInsertCount(1); using (var s = OpenSession()) using (var t = s.BeginTransaction()) { child = await(s.GetAsync <VersionedNode>(child.Id)); Assert.That(child.Name, Is.EqualTo("child")); Assert.That(child.Parent, Is.Null); Assert.That(child.Version, Is.EqualTo(1)); parent = await(s.GetAsync <VersionedNode>(parent.Id)); Assert.That(parent, Is.Not.Null); s.SetReadOnly(child, true); await(s.DeleteAsync(child)); await(t.CommitAsync()); } AssertUpdateCount(0); AssertDeleteCount(1); }
public void AddNewChildToReadOnlyParent() { ISession s = OpenSession(); s.CacheMode = CacheMode.Ignore; s.BeginTransaction(); VersionedNode parent = new VersionedNode("parent", "parent"); s.Persist(parent); s.Transaction.Commit(); s.Close(); ClearCounts(); s = OpenSession(); s.CacheMode = CacheMode.Ignore; s.BeginTransaction(); VersionedNode parentManaged = s.Get <VersionedNode>(parent.Id); s.SetReadOnly(parentManaged, true); parentManaged.Name = "new parent name"; VersionedNode child = new VersionedNode("child", "child"); parentManaged.AddChild(child); s.Save(parentManaged); s.Transaction.Commit(); s.Close(); AssertUpdateCount(1); AssertInsertCount(1); s = OpenSession(); s.CacheMode = CacheMode.Ignore; s.BeginTransaction(); parent = s.Get <VersionedNode>(parent.Id); Assert.That(parent.Name, Is.EqualTo("parent")); Assert.That(parent.Children.Count, Is.EqualTo(1)); Assert.That(parent.Version, Is.EqualTo(2)); child = s.Get <VersionedNode>(child.Id); Assert.That(child, Is.Not.Null); s.Delete(parent); s.Transaction.Commit(); s.Close(); }
public async Task UpdateSetModifiableAsync() { VersionedNode node = new VersionedNode("node", "node"); using (ISession s = OpenSession()) { s.BeginTransaction(); await(s.PersistAsync(node)); await(s.Transaction.CommitAsync()); } ClearCounts(); using (var s = OpenSession()) { s.BeginTransaction(); node = await(s.GetAsync <VersionedNode>(node.Id)); node.Name = "node-name"; s.SetReadOnly(node, false); await(s.Transaction.CommitAsync()); } AssertUpdateCount(1); AssertInsertCount(0); ClearCounts(); using (var s = OpenSession()) { s.BeginTransaction(); node = await(s.GetAsync <VersionedNode>(node.Id)); Assert.That(node.Name, Is.EqualTo("node-name")); Assert.That(node.Version, Is.EqualTo(2)); //s.SetReadOnly(node, true); await(s.DeleteAsync(node)); await(s.Transaction.CommitAsync()); } AssertUpdateCount(0); AssertDeleteCount(1); }
public void UpdateSetReadOnlyTwice() { VersionedNode node = new VersionedNode("node", "node"); using (ISession s = OpenSession()) { s.BeginTransaction(); s.Persist(node); s.Transaction.Commit(); } ClearCounts(); using (ISession s = OpenSession()) { s.BeginTransaction(); node = s.Get <VersionedNode>(node.Id); node.Name = "node-name"; s.SetReadOnly(node, true); s.SetReadOnly(node, true); s.Transaction.Commit(); } AssertUpdateCount(0); AssertInsertCount(0); using (ISession s = OpenSession()) { s.BeginTransaction(); node = s.Get <VersionedNode>(node.Id); Assert.That(node.Name, Is.EqualTo("node")); Assert.That(node.Version, Is.EqualTo(1)); s.SetReadOnly(node, true); s.Delete(node); s.Transaction.Commit(); } AssertUpdateCount(0); AssertDeleteCount(1); }
public void UpdateSetModifiable() { ISession s = OpenSession(); s.BeginTransaction(); VersionedNode node = new VersionedNode("node", "node"); s.Persist(node); s.Transaction.Commit(); s.Close(); ClearCounts(); s = OpenSession(); s.BeginTransaction(); node = s.Get <VersionedNode>(node.Id); node.Name = "node-name"; s.SetReadOnly(node, false); s.Transaction.Commit(); s.Close(); s.Dispose(); AssertUpdateCount(1); AssertInsertCount(0); ClearCounts(); s = OpenSession(); s.BeginTransaction(); node = s.Get <VersionedNode>(node.Id); Assert.That(node.Name, Is.EqualTo("node-name")); Assert.That(node.Version, Is.EqualTo(2)); //s.SetReadOnly(node, true); s.Delete(node); s.Transaction.Commit(); s.Close(); AssertUpdateCount(0); AssertDeleteCount(1); }
public void SetReadOnlyUpdateSetModifiableFailureExpected() { VersionedNode node = new VersionedNode("node", "node"); using (var s = OpenSession()) using (var t = s.BeginTransaction()) { s.Persist(node); t.Commit(); s.Close(); } ClearCounts(); using (var s = OpenSession()) using (var t = s.BeginTransaction()) { node = s.Get <VersionedNode>(node.Id); s.SetReadOnly(node, true); node.Name = "node-name"; s.SetReadOnly(node, false); t.Commit(); s.Close(); } AssertUpdateCount(1); AssertInsertCount(0); using (var s = OpenSession()) using (var t = s.BeginTransaction()) { node = s.Get <VersionedNode>(node.Id); Assert.That(node.Name, Is.EqualTo("node-name")); Assert.That(node.Version, Is.EqualTo(2)); s.Delete(node); t.Commit(); s.Close(); } }
public void SetReadOnlyTrueAndFalse() { ISession s = OpenSession(); s.BeginTransaction(); VersionedNode node = new VersionedNode("node", "node"); s.Persist(node); s.Transaction.Commit(); s.Close(); ClearCounts(); s = OpenSession(); s.BeginTransaction(); node = s.Get <VersionedNode>(node.Id); s.SetReadOnly(node, true); node.Name = "node-name"; s.Transaction.Commit(); AssertUpdateCount(0); AssertInsertCount(0); // the changed name is still in node Assert.That(node.Name, Is.EqualTo("node-name")); s.BeginTransaction(); node = s.Get <VersionedNode>(node.Id); // the changed name is still in the session Assert.That(node.Name, Is.EqualTo("node-name")); s.Refresh(node); // after refresh, the name reverts to the original value Assert.That(node.Name, Is.EqualTo("node")); node = s.Get <VersionedNode>(node.Id); Assert.That(node.Name, Is.EqualTo("node")); s.Transaction.Commit(); s.Close(); AssertUpdateCount(0); AssertInsertCount(0); s = OpenSession(); s.BeginTransaction(); node = s.Get <VersionedNode>(node.Id); Assert.That(node.Name, Is.EqualTo("node")); s.SetReadOnly(node, true); node.Name = "diff-node-name"; s.Flush(); Assert.That(node.Name, Is.EqualTo("diff-node-name")); s.Refresh(node); Assert.That(node.Name, Is.EqualTo("node")); s.SetReadOnly(node, false); node.Name = "diff-node-name"; s.Transaction.Commit(); s.Close(); AssertUpdateCount(1); AssertInsertCount(0); ClearCounts(); s = OpenSession(); s.BeginTransaction(); node = s.Get <VersionedNode>(node.Id); Assert.That(node.Name, Is.EqualTo("diff-node-name")); Assert.That(node.Version, Is.EqualTo(2)); s.SetReadOnly(node, true); s.Delete(node); s.Transaction.Commit(); s.Close(); AssertUpdateCount(0); AssertDeleteCount(1); }
public void UpdateParentWithNewChildCommitWithReadOnlyParent() { VersionedNode parent = new VersionedNode("parent", "parent"); using (ISession s = OpenSession()) { s.BeginTransaction(); s.Persist(parent); s.Transaction.Commit(); } ClearCounts(); parent.Name = "new parent name"; VersionedNode child = new VersionedNode("child", "child"); parent.AddChild(child); using (ISession s = OpenSession()) { s.BeginTransaction(); s.Update(parent); s.SetReadOnly(parent, true); s.Transaction.Commit(); } AssertUpdateCount(1); AssertInsertCount(1); ClearCounts(); using (ISession s = OpenSession()) { s.BeginTransaction(); parent = s.Get<VersionedNode>(parent.Id); child = s.Get<VersionedNode>(child.Id); Assert.That(parent.Name, Is.EqualTo("parent")); Assert.That(parent.Children.Count, Is.EqualTo(1)); Assert.That(parent.Version, Is.EqualTo(2)); Assert.That(child.Parent, Is.SameAs(parent)); Assert.That(parent.Children.First(), Is.SameAs(child)); Assert.That(child.Version, Is.EqualTo(1)); s.SetReadOnly(parent, true); s.SetReadOnly(child, true); s.Delete(parent); s.Delete(child); s.Transaction.Commit(); } AssertUpdateCount(0); AssertDeleteCount(2); }
public void MergeDetachedChildWithNewParentCommitWithReadOnlyChild() { VersionedNode child = new VersionedNode("child", "child"); using (ISession s = OpenSession()) { s.BeginTransaction(); s.Persist(child); s.Transaction.Commit(); } ClearCounts(); child.Name = "new child name"; VersionedNode parent = new VersionedNode("parent", "parent"); parent.AddChild(child); using (ISession s = OpenSession()) { s.BeginTransaction(); child = (VersionedNode) s.Merge(child); s.SetReadOnly(child, true); s.Transaction.Commit(); } AssertUpdateCount(0); // NH-specific: Hibernate issues a separate UPDATE for the version number AssertInsertCount(1); ClearCounts(); using (ISession s = OpenSession()) { s.BeginTransaction(); parent = s.Get<VersionedNode>(parent.Id); child = s.Get<VersionedNode>(child.Id); Assert.That(child.Name, Is.EqualTo("child")); Assert.That(child.Parent, Is.Null); Assert.That(child.Version, Is.EqualTo(1)); Assert.That(parent, Is.Not.Null); Assert.That(parent.Children.Count, Is.EqualTo(0)); Assert.That(parent.Version, Is.EqualTo(1)); s.SetReadOnly(parent, true); s.SetReadOnly(child, true); s.Delete(parent); s.Delete(child); s.Transaction.Commit(); } AssertUpdateCount(0); AssertDeleteCount(2); }
public void AddNewParentToReadOnlyChild() { VersionedNode child = new VersionedNode("child", "child"); using (ISession s = OpenSession()) { s.BeginTransaction(); s.Persist(child); s.Transaction.Commit(); } ClearCounts(); VersionedNode parent = new VersionedNode("parent", "parent"); using (ISession s = OpenSession()) { s.BeginTransaction(); VersionedNode childManaged = s.Get<VersionedNode>(child.Id); s.SetReadOnly(childManaged, true); childManaged.Name = "new child name"; parent.AddChild(childManaged); s.Transaction.Commit(); } AssertUpdateCount(0); AssertInsertCount(1); using (ISession s = OpenSession()) { s.BeginTransaction(); child = s.Get<VersionedNode>(child.Id); Assert.That(child.Name, Is.EqualTo("child")); Assert.That(child.Parent, Is.Null); Assert.That(child.Version, Is.EqualTo(1)); parent = s.Get<VersionedNode>(parent.Id); Assert.That(parent, Is.Not.Null); s.SetReadOnly(child, true); s.Delete(child); s.Transaction.Commit(); } AssertUpdateCount(0); AssertDeleteCount(1); }
public void GetChildMakeReadOnlyThenMergeDetachedChildWithNewParent() { ISession s = OpenSession(); s.BeginTransaction(); VersionedNode child = new VersionedNode("child", "child"); s.Persist(child); s.Transaction.Commit(); s.Close(); ClearCounts(); child.Name = "new child name"; VersionedNode parent = new VersionedNode("parent", "parent"); parent.AddChild(child); s = OpenSession(); s.BeginTransaction(); VersionedNode childManaged = s.Get<VersionedNode>(child.Id); s.SetReadOnly(childManaged, true); VersionedNode childMerged = (VersionedNode)s.Merge(child); Assert.That(childManaged, Is.SameAs(childMerged)); s.Transaction.Commit(); s.Close(); AssertUpdateCount(0); // NH-specific: Hibernate issues a seperate UPDATE for the version number AssertInsertCount(1); ClearCounts(); s = OpenSession(); s.BeginTransaction(); parent = s.Get<VersionedNode>(parent.Id); child = s.Get<VersionedNode>(child.Id); Assert.That(child.Name, Is.EqualTo("child")); Assert.That(child.Parent, Is.Null); Assert.That(child.Version, Is.EqualTo(1)); Assert.That(parent, Is.Not.Null); Assert.That(parent.Children.Count, Is.EqualTo(0)); Assert.That(parent.Version, Is.EqualTo(1)); // NH-specific: Hibernate incorrectly increments version number, NH does not s.SetReadOnly(parent, true); s.SetReadOnly(child, true); s.Delete(parent); s.Delete(child); s.Transaction.Commit(); s.Close(); AssertUpdateCount(0); AssertDeleteCount(2); }
public virtual void AddChild(VersionedNode child) { child.Parent = this; children.Add(child); }
public void MergeUnchangedDetachedParentChildren() { ISession s = OpenSession(); s.BeginTransaction(); VersionedNode parent = new VersionedNode("parent", "parent"); VersionedNode child = new VersionedNode("child", "child"); parent.AddChild(child); s.Persist(parent); s.Transaction.Commit(); s.Close(); ClearCounts(); s = OpenSession(); s.BeginTransaction(); parent = (VersionedNode)s.Merge(parent); s.Transaction.Commit(); s.Close(); AssertUpdateCount(0); AssertInsertCount(0); ClearCounts(); s = OpenSession(); s.BeginTransaction(); VersionedNode parentGet = s.Get<VersionedNode>(parent.Id); s.Merge(parent); s.Transaction.Commit(); s.Close(); AssertUpdateCount(0); AssertInsertCount(0); ClearCounts(); s = OpenSession(); s.BeginTransaction(); VersionedNode parentLoad = s.Load<VersionedNode>(parent.Id); s.Merge(parent); s.Transaction.Commit(); s.Close(); AssertUpdateCount(0); AssertInsertCount(0); ClearCounts(); s = OpenSession(); s.BeginTransaction(); parent = s.Get<VersionedNode>(parent.Id); child = s.Get<VersionedNode>(child.Id); Assert.That(parent.Name, Is.EqualTo("parent")); Assert.That(parent.Children.Count, Is.EqualTo(1)); Assert.That(parent.Version, Is.EqualTo(1)); Assert.That(child.Parent, Is.SameAs(parent)); Assert.That(parent.Children.First(), Is.SameAs(child)); Assert.That(child.Version, Is.EqualTo(1)); s.Delete(parent); s.Delete(child); s.Transaction.Commit(); s.Close(); AssertUpdateCount(0); AssertDeleteCount(2); }
public void UpdateSetModifiable() { VersionedNode node = new VersionedNode("node", "node"); using (ISession s = OpenSession()) { s.BeginTransaction(); s.Persist(node); s.Transaction.Commit(); } ClearCounts(); using (var s = OpenSession()) { s.BeginTransaction(); node = s.Get<VersionedNode>(node.Id); node.Name = "node-name"; s.SetReadOnly(node, false); s.Transaction.Commit(); } AssertUpdateCount(1); AssertInsertCount(0); ClearCounts(); using (var s = OpenSession()) { s.BeginTransaction(); node = s.Get<VersionedNode>(node.Id); Assert.That(node.Name, Is.EqualTo("node-name")); Assert.That(node.Version, Is.EqualTo(2)); //s.SetReadOnly(node, true); s.Delete(node); s.Transaction.Commit(); } AssertUpdateCount(0); AssertDeleteCount(1); }
public void SetReadOnlyTrueAndFalse() { ISession s = OpenSession(); s.BeginTransaction(); VersionedNode node = new VersionedNode("node", "node"); s.Persist(node); s.Transaction.Commit(); s.Close(); ClearCounts(); s = OpenSession(); s.BeginTransaction(); node = s.Get<VersionedNode>(node.Id); s.SetReadOnly(node, true); node.Name = "node-name"; s.Transaction.Commit(); AssertUpdateCount(0); AssertInsertCount(0); // the changed name is still in node Assert.That(node.Name, Is.EqualTo("node-name")); s.BeginTransaction(); node = s.Get<VersionedNode>(node.Id); // the changed name is still in the session Assert.That(node.Name, Is.EqualTo("node-name")); s.Refresh(node); // after refresh, the name reverts to the original value Assert.That(node.Name, Is.EqualTo("node")); node = s.Get<VersionedNode>(node.Id); Assert.That(node.Name, Is.EqualTo("node")); s.Transaction.Commit(); s.Close(); AssertUpdateCount(0); AssertInsertCount(0); s = OpenSession(); s.BeginTransaction(); node = s.Get<VersionedNode>(node.Id); Assert.That(node.Name, Is.EqualTo("node")); s.SetReadOnly(node, true); node.Name = "diff-node-name"; s.Flush(); Assert.That(node.Name, Is.EqualTo("diff-node-name")); s.Refresh(node); Assert.That(node.Name, Is.EqualTo("node")); s.SetReadOnly(node, false); node.Name = "diff-node-name"; s.Transaction.Commit(); s.Close(); AssertUpdateCount(1); AssertInsertCount(0); ClearCounts(); s = OpenSession(); s.BeginTransaction(); node = s.Get<VersionedNode>(node.Id); Assert.That(node.Name, Is.EqualTo("diff-node-name")); Assert.That(node.Version, Is.EqualTo(2)); s.SetReadOnly(node, true); s.Delete(node); s.Transaction.Commit(); s.Close(); AssertUpdateCount(0); AssertDeleteCount(1); }
public void GetParentMakeReadOnlyThenMergeDetachedParentWithNewChildC() { ISession s = OpenSession(); s.BeginTransaction(); VersionedNode parent = new VersionedNode("parent", "parent"); s.Persist(parent); s.Transaction.Commit(); s.Close(); ClearCounts(); parent.Name = "new parent name"; VersionedNode child = new VersionedNode("child", "child"); parent.AddChild(child); s = OpenSession(); s.BeginTransaction(); VersionedNode parentManaged = s.Get<VersionedNode>(parent.Id); s.SetReadOnly(parentManaged, true); VersionedNode parentMerged = (VersionedNode) s.Merge(parent); Assert.That(parentManaged, Is.SameAs(parentMerged)); s.Transaction.Commit(); s.Close(); AssertUpdateCount(1); AssertInsertCount(1); ClearCounts(); s = OpenSession(); s.BeginTransaction(); parent = s.Get<VersionedNode>(parent.Id); child = s.Get<VersionedNode>(child.Id); Assert.That(parent.Name, Is.EqualTo("parent")); Assert.That(parent.Children.Count, Is.EqualTo(1)); Assert.That(parent.Version, Is.EqualTo(2)); Assert.That(child.Parent, Is.SameAs(parent)); Assert.That(parent.Children.First(), Is.SameAs(child)); Assert.That(child.Version, Is.EqualTo(1)); s.Delete(parent); s.Delete(child); s.Transaction.Commit(); s.Close(); AssertUpdateCount(0); AssertDeleteCount(2); }
public void AddNewChildToReadOnlyParent() { ISession s = OpenSession(); s.CacheMode = CacheMode.Ignore; s.BeginTransaction(); VersionedNode parent = new VersionedNode("parent", "parent"); s.Persist(parent); s.Transaction.Commit(); s.Close(); ClearCounts(); s = OpenSession(); s.CacheMode = CacheMode.Ignore; s.BeginTransaction(); VersionedNode parentManaged = s.Get<VersionedNode>(parent.Id); s.SetReadOnly(parentManaged, true); parentManaged.Name = "new parent name"; VersionedNode child = new VersionedNode("child", "child"); parentManaged.AddChild(child); s.Save(parentManaged); s.Transaction.Commit(); s.Close(); AssertUpdateCount(1); AssertInsertCount(1); s = OpenSession(); s.CacheMode = CacheMode.Ignore; s.BeginTransaction(); parent = s.Get<VersionedNode>(parent.Id); Assert.That(parent.Name, Is.EqualTo("parent")); Assert.That(parent.Children.Count, Is.EqualTo(1)); Assert.That(parent.Version, Is.EqualTo(2)); child = s.Get<VersionedNode>(child.Id); Assert.That(child, Is.Not.Null); s.Delete(parent); s.Transaction.Commit(); s.Close(); }
public void SetReadOnlyUpdateSetModifiableFailureExpected() { ISession s = OpenSession(); s.BeginTransaction(); VersionedNode node = new VersionedNode("node", "node"); s.Persist(node); s.Transaction.Commit(); s.Close(); ClearCounts(); s = OpenSession(); s.BeginTransaction(); node = s.Get<VersionedNode>(node.Id); s.SetReadOnly(node, true); node.Name = "node-name"; s.SetReadOnly(node, false); s.Transaction.Commit(); s.Close(); AssertUpdateCount(1); AssertInsertCount(0); s = OpenSession(); s.BeginTransaction(); node = s.Get<VersionedNode>(node.Id); Assert.That(node.Name, Is.EqualTo("node-name")); Assert.That(node.Version, Is.EqualTo(2)); s.Delete(node); s.Transaction.Commit(); s.Close(); }
public void MergeUnchangedDetachedParentChildren() { ISession s = OpenSession(); s.BeginTransaction(); VersionedNode parent = new VersionedNode("parent", "parent"); VersionedNode child = new VersionedNode("child", "child"); parent.AddChild(child); s.Persist(parent); s.Transaction.Commit(); s.Close(); ClearCounts(); s = OpenSession(); s.BeginTransaction(); parent = (VersionedNode)s.Merge(parent); s.Transaction.Commit(); s.Close(); AssertUpdateCount(0); AssertInsertCount(0); ClearCounts(); s = OpenSession(); s.BeginTransaction(); VersionedNode parentGet = s.Get <VersionedNode>(parent.Id); s.Merge(parent); s.Transaction.Commit(); s.Close(); AssertUpdateCount(0); AssertInsertCount(0); ClearCounts(); s = OpenSession(); s.BeginTransaction(); VersionedNode parentLoad = s.Load <VersionedNode>(parent.Id); s.Merge(parent); s.Transaction.Commit(); s.Close(); AssertUpdateCount(0); AssertInsertCount(0); ClearCounts(); s = OpenSession(); s.BeginTransaction(); parent = s.Get <VersionedNode>(parent.Id); child = s.Get <VersionedNode>(child.Id); Assert.That(parent.Name, Is.EqualTo("parent")); Assert.That(parent.Children.Count, Is.EqualTo(1)); Assert.That(parent.Version, Is.EqualTo(1)); Assert.That(child.Parent, Is.SameAs(parent)); Assert.That(parent.Children.First(), Is.SameAs(child)); Assert.That(child.Version, Is.EqualTo(1)); s.Delete(parent); s.Delete(child); s.Transaction.Commit(); s.Close(); AssertUpdateCount(0); AssertDeleteCount(2); }
public void UpdateChildWithNewParentCommitWithReadOnlyChild() { ISession s = OpenSession(); s.BeginTransaction(); VersionedNode child = new VersionedNode("child", "child"); s.Persist(child); s.Transaction.Commit(); s.Close(); ClearCounts(); child.Name = "new child name"; VersionedNode parent = new VersionedNode("parent", "parent"); parent.AddChild(child); s = OpenSession(); s.BeginTransaction(); s.Update(child); s.SetReadOnly(child, true); s.Transaction.Commit(); s.Close(); AssertUpdateCount(0); AssertInsertCount(1); ClearCounts(); s = OpenSession(); s.BeginTransaction(); parent = s.Get<VersionedNode>(parent.Id); child = s.Get<VersionedNode>(child.Id); Assert.That(child.Name, Is.EqualTo("child")); Assert.That(child.Parent, Is.Null); Assert.That(child.Version, Is.EqualTo(1)); Assert.That(parent, Is.Not.Null); Assert.That(parent.Children.Count, Is.EqualTo(0)); Assert.That(parent.Version, Is.EqualTo(1)); s.SetReadOnly(parent, true); s.SetReadOnly(child, true); s.Delete(parent); s.Delete(child); s.Transaction.Commit(); s.Close(); AssertUpdateCount(0); AssertDeleteCount(2); }
public async Task MergeUnchangedDetachedParentChildrenAsync() { VersionedNode parent = new VersionedNode("parent", "parent"); VersionedNode child = new VersionedNode("child", "child"); using (var s = OpenSession()) using (var t = s.BeginTransaction()) { parent.AddChild(child); await(s.PersistAsync(parent)); await(t.CommitAsync()); } ClearCounts(); using (var s = OpenSession()) using (var t = s.BeginTransaction()) { parent = (VersionedNode)await(s.MergeAsync(parent)); await(t.CommitAsync()); } AssertUpdateCount(0); AssertInsertCount(0); ClearCounts(); using (var s = OpenSession()) using (var t = s.BeginTransaction()) { VersionedNode parentGet = await(s.GetAsync <VersionedNode>(parent.Id)); await(s.MergeAsync(parent)); await(t.CommitAsync()); } AssertUpdateCount(0); AssertInsertCount(0); ClearCounts(); using (var s = OpenSession()) using (var t = s.BeginTransaction()) { VersionedNode parentLoad = await(s.LoadAsync <VersionedNode>(parent.Id)); await(s.MergeAsync(parent)); await(t.CommitAsync()); } AssertUpdateCount(0); AssertInsertCount(0); ClearCounts(); using (var s = OpenSession()) using (var t = s.BeginTransaction()) { parent = await(s.GetAsync <VersionedNode>(parent.Id)); child = await(s.GetAsync <VersionedNode>(child.Id)); Assert.That(parent.Name, Is.EqualTo("parent")); Assert.That(parent.Children.Count, Is.EqualTo(1)); Assert.That(parent.Version, Is.EqualTo(1)); Assert.That(child.Parent, Is.SameAs(parent)); Assert.That(parent.Children.First(), Is.SameAs(child)); Assert.That(child.Version, Is.EqualTo(1)); await(s.DeleteAsync(parent)); await(s.DeleteAsync(child)); await(t.CommitAsync()); } AssertUpdateCount(0); AssertDeleteCount(2); }
public async Task SetReadOnlyTrueAndFalseAsync() { VersionedNode node = new VersionedNode("node", "node"); using (var s = OpenSession()) using (var t = s.BeginTransaction()) { await(s.PersistAsync(node)); await(t.CommitAsync()); } ClearCounts(); using (var s = OpenSession()) { using (var t = s.BeginTransaction()) { node = await(s.GetAsync <VersionedNode>(node.Id)); s.SetReadOnly(node, true); node.Name = "node-name"; await(t.CommitAsync()); } AssertUpdateCount(0); AssertInsertCount(0); // the changed name is still in node Assert.That(node.Name, Is.EqualTo("node-name")); using (var t = s.BeginTransaction()) { node = await(s.GetAsync <VersionedNode>(node.Id)); // the changed name is still in the session Assert.That(node.Name, Is.EqualTo("node-name")); await(s.RefreshAsync(node)); // after refresh, the name reverts to the original value Assert.That(node.Name, Is.EqualTo("node")); node = await(s.GetAsync <VersionedNode>(node.Id)); Assert.That(node.Name, Is.EqualTo("node")); await(t.CommitAsync()); } } AssertUpdateCount(0); AssertInsertCount(0); using (var s = OpenSession()) using (var t = s.BeginTransaction()) { node = await(s.GetAsync <VersionedNode>(node.Id)); Assert.That(node.Name, Is.EqualTo("node")); s.SetReadOnly(node, true); node.Name = "diff-node-name"; await(s.FlushAsync()); Assert.That(node.Name, Is.EqualTo("diff-node-name")); await(s.RefreshAsync(node)); Assert.That(node.Name, Is.EqualTo("node")); s.SetReadOnly(node, false); node.Name = "diff-node-name"; await(t.CommitAsync()); } AssertUpdateCount(1); AssertInsertCount(0); ClearCounts(); using (var s = OpenSession()) using (var t = s.BeginTransaction()) { node = await(s.GetAsync <VersionedNode>(node.Id)); Assert.That(node.Name, Is.EqualTo("diff-node-name")); Assert.That(node.Version, Is.EqualTo(2)); s.SetReadOnly(node, true); await(s.DeleteAsync(node)); await(t.CommitAsync()); } AssertUpdateCount(0); AssertDeleteCount(1); }