public IEnumerable<DocumentMigrationCommand> ApplicableCommands(DocumentDesign design, int currentDocumentVersion) { return configuration.Migrations .Where(x => x.Version > currentDocumentVersion) .SelectMany(x => x.MigrateDocument()) .Where(x => x.ForType(design.DocumentType)); }
public DocumentDesign CreateDesignFor(Type type, string tablename = null) { var discriminator = TypeMapper.ToDiscriminator(type); var parent = TryGetDesignFor(type); if (parent != null && tablename == null) { var design = new DocumentDesign(this, parent, type, discriminator); var afterParent = DocumentDesigns.IndexOf(parent) + 1; DocumentDesigns.Insert(afterParent, design); return(design); } else { tablename = tablename ?? GetTableNameByConventionFor(type); if (initialized) { throw new InvalidOperationException($"You can not register the table '{tablename}' after store has been initialized."); } var existingDesign = DocumentDesigns.FirstOrDefault(existing => type.IsAssignableFrom(existing.DocumentType)); if (existingDesign != null) { throw new InvalidOperationException($"Document {type.Name} must be configured before its subtype {existingDesign.DocumentType}."); } var design = new DocumentDesign(this, AddTable(tablename), type, discriminator); DocumentDesigns.Add(design); return(design); } }
public BackupCommand(DatabaseCommand command, IBackupWriter writer, DocumentDesign design, string key, int version, byte[] document) { this.command = command; this.writer = writer; this.design = design; this.key = key; this.version = version; this.document = document; }
public DocumentDesign(Configuration configuration, DocumentDesign parent, Type documentType, string discriminator) : this(configuration, parent.Table, documentType, discriminator) { Parent = parent; Projections = parent.Projections.ToDictionary(); Projections[Table.DiscriminatorColumn] = Projection.From <string>(managedEntity => Discriminator); Parent.AddChild(this); }
public DocumentDesign(Configuration configuration, DocumentDesign parent, Type documentType, string discriminator) : this(configuration, parent.Table, documentType, discriminator) { Base = parent.Base; Parent = parent; Projections = parent.Projections.ToDictionary(); Projections[Table.DiscriminatorColumn] = Projection.From<string>(_ => Discriminator); Parent.AddChild(this); }
void AddChild(DocumentDesign design) { Parent?.AddChild(design); if (decendentsAndSelf.ContainsKey(design.Discriminator)) { throw new InvalidOperationException($"Discriminator '{design.Discriminator}' is already in use."); } decendentsAndSelf.Add(design.Discriminator, design); }
public DocumentDesign GetOrCreateConcreteDesign(DocumentDesign @base, string discriminator, string key) { DocumentDesign concreteDesign; if (@base.DecendentsAndSelf.TryGetValue(discriminator, out concreteDesign)) { return(concreteDesign); } var type = TypeMapper.ToType(discriminator); if (type == null) { throw new InvalidOperationException($"Document with id '{key}' exists, but no concrete type was found for discriminator '{discriminator}'."); } if ([email protected](type)) { throw new InvalidOperationException($"Document with id '{key}' exists, but is not assignable to the given type '{@base.DocumentType.Name}'."); } return(CreateDesignFor(type)); }
public object DeserializeAndMigrate(IDocumentSession session, DocumentDesign design, string id, byte[] document, int currentDocumentVersion) { var configuredVersion = configuration.ConfiguredVersion; if (configuredVersion == currentDocumentVersion) { return configuration.Serializer.Deserialize(document, design.DocumentType); } if (configuredVersion < currentDocumentVersion) { throw new InvalidOperationException(string.Format( "Document {0}/{1} version is ahead of configuration. Document is version {2}, but configuration is version {3}.", design.DocumentType.FullName, id, currentDocumentVersion, configuredVersion)); } logger.Information("Migrating document {0}/{1} from version {2} to {3}.", design.DocumentType.FullName, id, currentDocumentVersion, configuration.ConfiguredVersion); document = ApplicableCommands(design, currentDocumentVersion) .Aggregate(document, (currentDocument, command) => command.Execute(session, configuration.Serializer, currentDocument)); return configuration.Serializer.Deserialize(document, design.DocumentType); }
public DocumentDesigner(DocumentDesign design) { this.design = design; }
public IndexDesigner(DocumentDesign design) { designer = new DocumentDesigner <TEntity>(design); }
public IndexDesigner(DocumentDesign design, Func <Expression, string> columnNameConvention) { this.columnNameConvention = columnNameConvention; designer = new DocumentDesigner <TEntity>(design, columnNameConvention); }
public DocumentDesigner(DocumentDesign design, Func <Expression, string> columnNameConvention) { this.design = design; this.columnNameConvention = columnNameConvention; }