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 QueryProvider(DocumentSession session, DocumentDesign design) { this.session = session; this.design = design; store = session.Advanced.DocumentStore; lastQueryStats = new QueryStats(); }
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 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 override bool Matches(int version, Configuration configuration, DocumentDesign design, IDictionary <string, object> row) { var rowId = row.Get(DocumentTable.IdColumn); if (row.Get(DocumentTable.DiscriminatorColumn) != design.Discriminator) { throw new ArgumentException(_(@$ " Provided design must be the concrete design for the row. The given design has discriminator {design.Discriminator},
public object Load(DocumentDesign design, string key) { ManagedEntity managedEntity; if (entities.TryGetValue(new EntityKey(design.Table, key), out managedEntity)) { return(managedEntity.State != EntityState.Deleted ? managedEntity.Entity : null); } var row = store.Get(design.Table, key); if (row == null) { return(null); } return(ConvertToEntityAndPutUnderManagement(design, row)); }
internal object ConvertToEntityAndPutUnderManagement(DocumentDesign design, IDictionary <string, object> row) { var table = design.Table; var key = (string)row[table.IdColumn]; var discriminator = ((string)row[table.DiscriminatorColumn]).Trim(); var concreteDesign = store.Configuration.GetOrCreateConcreteDesign(design, discriminator, key); ManagedEntity managedEntity; if (entities.TryGetValue(new EntityKey(design.Table, key), out managedEntity)) { return(managedEntity.State != EntityState.Deleted ? managedEntity.Entity : null); } var document = (byte[])row[table.DocumentColumn]; var currentDocumentVersion = (int)row[table.VersionColumn]; var entity = migrator.DeserializeAndMigrate(this, concreteDesign, key, document, currentDocumentVersion); var metadataDocument = (byte[])row[table.MetadataColumn]; var metadata = metadataDocument != null ? (Dictionary <string, List <string> >)store.Configuration.Serializer.Deserialize(metadataDocument, typeof(Dictionary <string, List <string> >)) : null; managedEntity = new ManagedEntity { Key = key, Entity = entity, Document = document, Metadata = metadata, MetadataDocument = metadataDocument, Etag = (Guid)row[table.EtagColumn], Version = currentDocumentVersion, State = EntityState.Loaded, Table = table }; entities.Add(new EntityKey(design.Table, key), managedEntity); return(entity); }
public override bool Matches(int version, Configuration configuration, DocumentDesign design, IDictionary <string, object> row) => true;
public abstract bool Matches(int version, Configuration configuration, DocumentDesign design, IDictionary <string, object> row);