Пример #1
0
        private void EnumerateDataSourceViews(Database db, int dbID, out Dictionary <DataSourceView, DsvRepositoryInformation> dsvToObjectIDMap)
        {
            dsvToObjectIDMap = new Dictionary <DataSourceView, DsvRepositoryInformation>();

            foreach (DataSourceView dsv in db.DataSourceViews)
            {
                // get the connection ID
                int connectionID = -1;

                if (dsv.DataSource != null)
                {
                    connectionID = repository.GetConnection(dsv.DataSource.ConnectionString);

                    if (connectionID == -1)
                    {
                        connectionID = CreateConnection(dsv.DataSource);
                    }
                }

                // a DSV might exist without a data source. So, we have to use the database as the parent.
                int dsvID = repository.AddObject(dsv.Name, dsv.Description, ObjectTypes.DataSourceView, dbID);

                DsvRepositoryInformation dsvRepositoryInformation = new DsvRepositoryInformation();
                dsvRepositoryInformation.dsvID = dsvID;

                EnumerateDsvTables(dsv, connectionID, dsvID, out dsvRepositoryInformation.dsvTableNameToIDMap);

                dsvToObjectIDMap.Add(dsv, dsvRepositoryInformation);
            }
        }
Пример #2
0
        private void EnumerateDimensions(Database db, int dbID, Dictionary <DataSourceView, DsvRepositoryInformation> dsvToObjectIDMap, Dictionary <DataSource, int> dsToIDMap, out Dictionary <Dimension, int> dimensionToIdMap)
        {
            dimensionToIdMap = new Dictionary <Dimension, int>(db.Dimensions.Count);

            foreach (Dimension dim in db.Dimensions)
            {
                // get the connection ID
                int connectionID = -1;

                if ((dim.DataSource != null) && (dsToIDMap.ContainsKey(dim.DataSource)))
                {
                    connectionID = dsToIDMap[dim.DataSource];
                }

                DsvRepositoryInformation dsvRepositoryInformation = dsvToObjectIDMap[dim.DataSourceView];
                Dictionary <string, int> dsvTableNameToIdMap      = dsvRepositoryInformation.dsvTableNameToIDMap;

                int dimID = repository.AddObject(dim.Name, dim.Description, ObjectTypes.DatabaseDimension, dbID);
                dimensionToIdMap.Add(dim, dimID);

                Dictionary <int, bool> sourceTableIDs = new Dictionary <int, bool>();

                foreach (DimensionAttribute attr in dim.Attributes)
                {
                    if (connectionID > -1)
                    {
                        string query;
                        int    sourceTableID = GetSourceIDForBinding(connectionID, dsvTableNameToIdMap, attr.NameColumn.Source, out query);

                        if (sourceTableID > 0)
                        {
                            // since we track only table level dependencies and not at the column level,
                            // we have to create a distinct list of these source tables
                            sourceTableIDs[sourceTableID] = true;
                        }
                        else
                        {
                            // if we don't have a table ID but have a query, store that as an attribute
                            // so that users can at least take a look at the query itself.
                            if (query != null)
                            {
                                repository.AddAttribute(dimID, Repository.Attributes.QueryDefinition, query);
                            }
                        }
                    }
                }

                // now create the lineage map from the distinct list of source tables to the dimension
                foreach (int sourceTableID in sourceTableIDs.Keys)
                {
                    repository.AddMapping(sourceTableID, dimID);
                }
            }
        }