public DocumentDesign(Configuration configuration, DocumentTable table, Type documentType, string discriminator) { Base = this; DocumentType = documentType; Table = table; Discriminator = discriminator; if (Table.DiscriminatorColumn.Length > -1 && discriminator.Length > Table.DiscriminatorColumn.Length) { throw new InvalidOperationException($"Discriminator '{discriminator}' is too long for column. Maximum length is {Table.DiscriminatorColumn.Length}."); } decendentsAndSelf = new Dictionary<string, DocumentDesign>(); decendentsAndSelf.Add(Discriminator, this); GetKey = configuration.DefaultKeyResolver; Projections = new Dictionary<string, Projection> { [Table.DiscriminatorColumn] = Projection.From<string>(_ => Discriminator), [Table.DocumentColumn] = Projection.From<byte[]>(document => configuration.Serializer.Serialize(document)), [Table.MetadataColumn] = Projection.From<byte[]>((document, metadata) => metadata != null ? configuration.Serializer.Serialize(metadata) : null), [Table.VersionColumn] = Projection.From<int>(_ => configuration.ConfiguredVersion), [Table.AwaitsReprojectionColumn] = Projection.From<bool>(_ => false) }; }
public DeleteCommand(DocumentTable table, string key, Guid etag, bool lastWriteWins) { this.table = table; this.key = key; currentEtag = etag; this.lastWriteWins = lastWriteWins; }
public UpdateCommand(DocumentTable table, string key, Guid etag, object projections, bool lastWriteWins) { this.table = table; this.key = key; currentEtag = etag; this.projections = projections; this.lastWriteWins = lastWriteWins; }
public Document(DocumentTable table, string document, IDictionary<string, object> projections) { Table = table; DocumentAsString = document; idColumn = projections.Single(x => x.Key == table.IdColumn.Name); documentColumn = projections.Single(x => x.Key == table.DocumentColumn.Name); etagColumn = projections.Single(x => x.Key == table.EtagColumn.Name); this.projections = projections.Where(x => !(x.Key is SystemColumn)) .Select(x => new Projection(x.Key, x.Value)) .ToList(); }
public void AcceptsConcurrentWrites() { UseRealTables(); Document<Entity>().With(x => x.Number); store.Initialize(); var id = NewId(); var table = new DocumentTable("Entities"); var etag = store.Insert(table, id, new { Discriminator = typeof(Entity).AssemblyQualifiedName, Version = 0, Document = configuration.Serializer.Serialize(new Entity()) }); var gate1 = new ManualResetEvent(false); var gate2 = new ManualResetEvent(false); UseMigrations(new InlineMigration(1, new ChangeDocument<Entity>((serializer, bytes) => { gate1.Set(); Thread.Sleep(1000); return bytes; }))); bool? failed = null; new DocumentMigrationRunner() .Run(store) .ContinueWith(x => { failed = x.IsFaulted; gate2.Set(); }); gate1.WaitOne(); store.Update(table, id, etag, new {}); gate2.WaitOne(); failed.ShouldBe(false); }
public void ReprojectsWhenAwaitingReprojection(bool awaitsReprojection, int result) { Document<Entity>().With(x => x.Number); var id = NewId(); var table = new DocumentTable("Entities"); store.Insert(table, id, new { AwaitsReprojection = awaitsReprojection, Discriminator = "Entity", Version = 0, Document = configuration.Serializer.Serialize(new Entity { Number = 42 }) }); new DocumentMigrationRunner(store).RunSynchronously(); var row = store.Get(table, id); row["Number"].ShouldBe(result); row["AwaitsReprojection"].ShouldBe(false); row[table.VersionColumn].ShouldBe(0); }
public void CanExecuteOnMultipleThreads() { UseTempDb(); Document<Entity>().With(x => x.Property); InitializeStore(); Parallel.For(0, 10, x => { var table = new DocumentTable("Entities"); store.Insert(table, NewId(), new { Property = "Asger", Version = 1 }); }); }
public void UtilityColsAreRemovedFromQueryResults() { Document<Entity>(); var table = new DocumentTable("Entities"); store.Insert(table, NewId(), new { Version = 1 }); QueryStats stats; var result1 = store.Query(table, out stats, skip: 0, take: 2).Single(); result1.ContainsKey(new Column("RowNumber", typeof(int))).ShouldBe(false); result1.ContainsKey(new Column("TotalResults", typeof(int))).ShouldBe(false); var result2 = store.Query<object>(table, out stats, skip: 0, take: 2).Single(); ((IDictionary<string, object>)result2).ContainsKey("RowNumber").ShouldBe(false); ((IDictionary<string, object>)result2).ContainsKey("TotalResults").ShouldBe(false); }
public InsertCommand(DocumentTable table, string key, object projections) { this.table = table; this.key = key; this.projections = projections; }
public static Guid Update(this IDocumentStore store, DocumentTable table, string key, Guid etag, object projections, bool lastWriteWins = false) { return Execute(store, new UpdateCommand(table, key, etag, projections, lastWriteWins)); }
public static IEnumerable<IDictionary<string, object>> Query( this IDocumentStore store, DocumentTable table, out QueryStats stats, string select = null, string where = "", int skip = 0, int take = 0, string orderby = "", object parameters = null) { return store.Query<object>(table, out stats, @select, @where, skip, take, @orderby, parameters).Select(x => (IDictionary<string, object>) x.Data); }
public static Guid Insert(this IDocumentStore store, DocumentTable table, string key, object projections) { return Execute(store, new InsertCommand(table, key, projections)); }
public static void Delete(this IDocumentStore store, DocumentTable table, string key, Guid etag, bool lastWriteWins = false) { Execute(store, new DeleteCommand(table, key, etag, lastWriteWins)); }