Beispiel #1
0
        public override void OnBeforeStage()
        {
            base.OnBeforeStage();
            var metadataMapping = new MetadataMapping(UpgradeContext.Services.StorageDriver, UpgradeContext.Services.NameBuilder);
            var metadataTasks   = UpgradeContext.Services.MappingResolver.GetMetadataTasks();
            var executor        = new Providers.SqlExecutor(UpgradeContext.Services.StorageDriver, UpgradeContext.Services.Connection);
            var metadataSet     = new MetadataSet();
            var isRecreate      = UpgradeContext.NodeConfiguration.UpgradeMode == DomainUpgradeMode.Recreate;
            var extractor       = new MetadataExtractor(metadataMapping, executor);

            foreach (var sqlExtractionTask in metadataTasks)
            {
                if (!isRecreate)
                {
                    extractor.ExtractAssemblies(metadataSet, sqlExtractionTask);
                    extractor.ExtractTypes(metadataSet, sqlExtractionTask);
                    extractor.ExtractExtensions(metadataSet, sqlExtractionTask);
                }
            }

            ValidateMetadataTables(metadataSet, internalStage, isRecreate);
            ValidateUserTables(metadataSet, internalStage, isRecreate);

            if (UpgradeContext.Stage == UpgradeStage.Upgrading)
            {
                internalStage = Stage.AfterUpgrading;
            }
            else
            {
                internalStage = Stage.Final;
            }
        }
        private static bool LookupHasAllValuesInMap(XElement lookupXElement, MetadataMapping map)
        {
            var ns = lookupXElement.Name.Namespace;

            return(map.Properties
                   .Select(propertyMapping => lookupXElement.Element(ns + propertyMapping.SourceName))
                   .All(xElement => xElement != null && !xElement.IsEmpty));
        }
Beispiel #3
0
        private void PrepareMetadata(Schema schema)
        {
            var mapping = new MetadataMapping(accessor.StorageDriver, accessor.NameBuilder);

            DropExistingMetadataTables(schema, mapping);
            PrepareAssemblyTable(schema, mapping);
            PrepareExtensionTable(schema, mapping);
            PreapareTypeTable(schema, mapping);
        }
        private void CreateMetadataMappings(MetadataMapping mapping)
        {
            var xmlSourceModels = new List <ModelMetadata>();

            MetadataMappingFactoryBase.PopulateModelMetadata(_xmlMetadata, xmlSourceModels, mapping.SourceName);

            var xmlTargetModels = new List <ModelMetadata>();

            MetadataMappingFactoryBase.PopulateModelMetadata(_xmlMetadata, xmlTargetModels, mapping.TargetName);

            _metadataMapper.CreateMetadataMappings(mapping, xmlSourceModels, xmlTargetModels);
        }
        private void PerformElementMapping(MetadataMapping map, XElement element, string path, XElement jsonXElement)
        {
            var propertyMappings = map.Properties.Where(p => p.SourceName == path);

            foreach (var mapping in propertyMappings)
            {
                mapping.MappingStrategy.MapElement(element, mapping.TargetName, jsonXElement);
            }

            foreach (var ele in element.Elements())
            {
                PerformElementMapping(map, ele, $"{path}/{ele.Name.LocalName}", jsonXElement);
            }
        }
        private void CreateMetadataMappings(MetadataMapping mapping)
        {
            var xmlModels = new List <ModelMetadata>();

            PopulateModelMetadata(FilteredXmlMetadata, xmlModels, mapping.SourceName);

            var jsonModels = new List <ModelMetadata>();

            PopulateModelMetadata(FilteredJsonMetadata, jsonModels, mapping.TargetName);

            foreach (var strategy in MappingStrategies)
            {
                strategy.CreateMetadataMappings(mapping, xmlModels, jsonModels);
            }
        }
Beispiel #7
0
        private void PrepareExtensionTable(Schema schema, MetadataMapping mapping)
        {
            var columnsTypeMap = GetColumnsTypeMap(typeof(Xtensive.Orm.Metadata.Extension));

            var table  = schema.CreateTable(mapping.Extension);
            var create = SqlDdl.Create(table);

            table.CreateColumn(mapping.ExtensionName, columnsTypeMap[mapping.ExtensionName]);
            table.CreateColumn(mapping.ExtensionText, columnsTypeMap[mapping.ExtensionText]);
            Execute(create);

            var tableRef = SqlDml.TableRef(table);
            var insert   = SqlDml.Insert(tableRef);

            insert.Values.Add(tableRef[mapping.ExtensionName], "name");
            insert.Values.Add(tableRef[mapping.ExtensionText], "text");
            Execute(insert);
        }
Beispiel #8
0
        private void PrepareAssemblyTable(Schema schema, MetadataMapping mapping)
        {
            var columnsTypeMap = GetColumnsTypeMap(typeof(Xtensive.Orm.Metadata.Assembly));

            var table  = schema.CreateTable(mapping.Assembly);
            var create = SqlDdl.Create(table);

            table.CreateColumn(mapping.AssemblyName, columnsTypeMap[mapping.AssemblyName]);
            table.CreateColumn(mapping.AssemblyVersion, columnsTypeMap[mapping.AssemblyVersion]);
            Execute(create);

            var tableRef = SqlDml.TableRef(table);
            var insert   = SqlDml.Insert(tableRef);

            insert.Values.Add(tableRef[mapping.AssemblyName], "name");
            insert.Values.Add(tableRef[mapping.AssemblyVersion], "version");
            Execute(insert);
        }
        private void PreapareTypeTable(Schema schema, MetadataMapping mapping)
        {
            var columnsTypeMap = GetColumnsTypeMap(typeof(Xtensive.Orm.Metadata.Type));

            var table  = schema.CreateTable(mapping.Type);
            var create = SqlDdl.Create(table);

            _ = table.CreateColumn(mapping.TypeId, columnsTypeMap[mapping.TypeId]);
            _ = table.CreateColumn(mapping.TypeName, columnsTypeMap[mapping.TypeName]);
            Execute(create);

            var tableRef = SqlDml.TableRef(table);
            var insert   = SqlDml.Insert(tableRef);

            insert.Values.Add(tableRef[mapping.TypeId], 1);
            insert.Values.Add(tableRef[mapping.TypeName], "name");
            Execute(insert);
        }
Beispiel #10
0
        private void DropExistingMetadataTables(Schema schema, MetadataMapping mapping)
        {
            var assemblyTable  = schema.Tables[mapping.Assembly];
            var extensionTable = schema.Tables[mapping.Extension];
            var typeTable      = schema.Tables[mapping.Type];

            if (assemblyTable != null)
            {
                Execute(SqlDdl.Drop(assemblyTable));
                schema.Tables.Remove(assemblyTable);
            }
            if (extensionTable != null)
            {
                Execute(SqlDdl.Drop(extensionTable));
                schema.Tables.Remove(extensionTable);
            }
            if (typeTable != null)
            {
                Execute(SqlDdl.Drop(typeTable));
                schema.Tables.Remove(typeTable);
            }
        }
Beispiel #11
0
		/// <summary>
		/// Walks a workspace utilizing the IModelAdapter when appropriate
		/// </summary>
		/// <param name="connectionData"></param>
		/// <returns></returns>
		private MetadataWorkspace AdaptWorkspace(EntityConnectionStringBuilder connectionData)
		{
			MetadataWorkspace workspace;

			// If our metadata dictionary already contains the workspace, use it; otherwise walk
			if (!MetadataMapping.TryGetValue(connectionData.Metadata, out workspace))
			{
				// Load our workspace (utilizing the resourceAssembly, when appropriate)
				var metaDataSource = new MetadataArtifacts(connectionData.Metadata, ResourceAssembly);

				// Create our workspace after splitting into conceptual (CSDL), storage (SSDL), and mapping (MSL) subtrees
				workspace = CreateWorkspace(
					metaDataSource.ConceptualXml.CreateNavigator().ReadSubtree(),
					AdaptStorageMetadata(metaDataSource.StorageXml.CreateNavigator().ReadSubtree()),
					AdaptMappingMetadata(metaDataSource.MappingXml.CreateNavigator().ReadSubtree()));

				// Cache our walked workspace for future performance gains
				MetadataMapping[connectionData.Metadata] = workspace;
			}

			return workspace;
		}
Beispiel #12
0
        public override void OnStage()
        {
            base.OnStage();
            // here, for every custom handler or not system upgrade handler, we have updated metadata
            // also here we have a session and selected storage node for it
            // so we can finally validate that the metadata of the building node is saved into right database/scheme pair
            var metadataMapping = new MetadataMapping(UpgradeContext.Services.StorageDriver, UpgradeContext.Services.NameBuilder);
            var metadataTasks   = UpgradeContext.Services.MappingResolver.GetMetadataTasks();
            var executor        = new Providers.SqlExecutor(UpgradeContext.Services.StorageDriver, UpgradeContext.Services.Connection);
            var metadataSet     = new MetadataSet();
            var isRecreate      = UpgradeContext.NodeConfiguration.UpgradeMode == DomainUpgradeMode.Recreate;
            var extractor       = new MetadataExtractor(metadataMapping, executor);

            foreach (var sqlExtractionTask in metadataTasks)
            {
                extractor.ExtractAssemblies(metadataSet, sqlExtractionTask);
                extractor.ExtractTypes(metadataSet, sqlExtractionTask);
                extractor.ExtractExtensions(metadataSet, sqlExtractionTask);
            }

            ValidateMetadataTables(metadataSet, internalStage, isRecreate);
            ValidateUserTables(metadataSet, internalStage, isRecreate);
        }