private static void UseMyData() { using (var d = new MyData(new MemoryPersistentSource())) { using (d.BeginTransaction()) { d.Documents.Put(new RavenJObject { {"key", "items/1"}, {"id", "items/1"}, {"etag", Guid.NewGuid().ToByteArray()}, }, new byte[0]); d.Commit(); } using (d.BeginTransaction()) { d.Documents.Put(new RavenJObject { {"key", "items/1"}, {"id", "items/1"}, {"etag", Guid.NewGuid().ToByteArray()}, {"txId", "1234"} }, new byte[0]); d.Transactions.Put(new RavenJObject { {"id", "1234"}, }, new byte[0]); d.Commit(); } ThreadPool.QueueUserWorkItem(state => { d.BeginTransaction(); Table.ReadResult readResult = d.Documents.Read(new RavenJObject {{"key", "items/1"}}); var txId = readResult.Key.Value<string>("txId"); Table.ReadResult txResult = d.Transactions.Read(new RavenJObject {{"id", txId}}); if (txResult == null) { Environment.Exit(1); return; } d.Transactions.Remove(txResult.Key); var x = ((RavenJObject) readResult.Key.CloneToken()); x.Remove("txId"); d.Documents.UpdateKey(x); d.CommitCurrentTransaction(); }); while (true) { using (d.BeginTransaction()) { Table.ReadResult readResult = d.Documents.Read(new RavenJObject {{"key", "items/1"}}); var txId = readResult.Key.Value<string>("txId"); if (txId == null) { return; } Table.ReadResult txResult = d.Transactions.Read(new RavenJObject {{"id", txId}}); if (txResult == null) { Environment.Exit(1); return; } d.Commit(); } } } }
private static void UseMyData() { using (var d = new MyData(new MemoryPersistentSource())) { using (d.BeginTransaction()) { d.Documents.Put(new RavenJObject { { "key", "items/1" }, { "id", "items/1" }, { "etag", Guid.NewGuid().ToByteArray() }, }, new byte[0]); d.Commit(); } using (d.BeginTransaction()) { d.Documents.Put(new RavenJObject { { "key", "items/1" }, { "id", "items/1" }, { "etag", Guid.NewGuid().ToByteArray() }, { "txId", "1234" } }, new byte[0]); d.Transactions.Put(new RavenJObject { { "id", "1234" }, }, new byte[0]); d.Commit(); } ThreadPool.QueueUserWorkItem(state => { d.BeginTransaction(); Table.ReadResult readResult = d.Documents.Read(new RavenJObject { { "key", "items/1" } }); var txId = readResult.Key.Value <string>("txId"); Table.ReadResult txResult = d.Transactions.Read(new RavenJObject { { "id", txId } }); if (txResult == null) { Environment.Exit(1); return; } d.Transactions.Remove(txResult.Key); var x = ((RavenJObject)readResult.Key.CloneToken()); x.Remove("txId"); d.Documents.UpdateKey(x); d.CommitCurrentTransaction(); }); while (true) { using (d.BeginTransaction()) { Table.ReadResult readResult = d.Documents.Read(new RavenJObject { { "key", "items/1" } }); var txId = readResult.Key.Value <string>("txId"); if (txId == null) { return; } Table.ReadResult txResult = d.Transactions.Read(new RavenJObject { { "id", txId } }); if (txResult == null) { Environment.Exit(1); return; } d.Commit(); } } } }