コード例 #1
0
ファイル: FilterJoinSqlModel.cs プロジェクト: dbshell/dbshell
        private FilterJoinSqlModel(SourceEntitySqlModel rootModel, SourceGraphSqlModel sourceGraphModel, IDatabaseFactory factory)
        {
            _sourceGraph = sourceGraphModel;
            _rootEntity = rootModel;
            _factory = factory;

            FillEntitiesOnTheSameServer();

            BuildLinkedEntities();

            bool hasFilter = _linkedEntities.Any(x => x.Dbsh.Columns.Any(y => y.Filter != null));

            if (!hasFilter)
            {
                _isValid = false;
                return;
            }

            _filteredEntities.AddRange(_linkedEntities);
            DetectUnusedEntities();
        }
コード例 #2
0
ファイル: SourceJoinSqlModel.cs プロジェクト: dbshell/dbshell
        public SourceJoinSqlModel(TargetEntitySqlModel targetEntitySqlModel, SourceGraphSqlModel sourceGraph)
        {
            _targetEntitySqlModel = targetEntitySqlModel;
            _sourceGraph = sourceGraph;

            SourceToRefsJoin = new DmlfFromItem();


            //foreach (var column in _targetEntitySqlModel.RequiredSourceColumns)
            //{
            //    if (Columns.ContainsKey(column.Alias)) continue;

            //    Columns[column.Alias] = new SourceColumnSqlModel
            //    {
            //        Alias = column.Alias,
            //    };

            //    bool addedEntity = false;
            //    foreach (var ent in column.Entities)
            //    {
            //        if (ent.SingleKeyColumn == column.Alias)
            //        {
            //            AddEntity(ent);
            //            addedEntity = true;
            //            break;
            //        }
            //    }
            //    if (addedEntity) continue;

            //    AddEntity(column.Entities.First());
            //}

            if (_sourceGraph == null)
            {
                // flat variant
                PrimarySource = _targetEntitySqlModel.DataSync.FlatSources.FirstOrDefault(x => x.Match(_targetEntitySqlModel.Dbsh.PrimarySource));
                if (PrimarySource == null)
                {
                    throw new IncorrectRdsDefinitionException($"DBSH-00000 Source not found for entity {_targetEntitySqlModel.LogName}");
                }
                SourceToRefsJoin.Source = PrimarySource.QuerySource;
                foreach (var col in PrimarySource.Columns)
                {
                    Columns[col.Alias] = col;
                }
            }
            else
            {
                _entityQueue.AddRange(_sourceGraph.Entities);

                DetectPrimarySource();

                DetectUnusedEntities();

                RebuildEntityList();
                //queue.Add(_targetEntitySqlModel.KeySourceColumns.First().Entities.First());
                //foreach (var ent in _targetEntitySqlModel.RequiredSourceColumns.SelectMany(x => x.Entities))
                //{
                //    if (queue.Contains(ent)) continue;
                //    queue.Add(ent);
                //}

                if (!_entityQueue.Any() && targetEntitySqlModel.Dbsh.Columns.Any(x => x.IsKey))
                {
                    throw new IncorrectRdsDefinitionException($"LGM-00000 None of source entities is used in {_targetEntitySqlModel.LogName} (try to set source column)");
                }

                if (_entityQueue.Any())
                {
                    CreateSourceJoin();
                    AddRefsToJoin();
                }

                foreach (var col in Columns.Values) col.CompileFilter();
            }
        }
コード例 #3
0
ファイル: FilterJoinSqlModel.cs プロジェクト: dbshell/dbshell
 public static FilterJoinSqlModel Create(SourceEntitySqlModel rootTable, SourceGraphSqlModel sourceGraphModel, IDatabaseFactory factory)
 {
     var res = new FilterJoinSqlModel(rootTable, sourceGraphModel, factory);
     if (res._isValid) return res;
     return null;
 }
コード例 #4
0
ファイル: DataSyncSqlModel.cs プロジェクト: dbshell/dbshell
        public DataSyncSqlModel(SyncModel model, IShellContext context, bool allowExternalSources, string providerString)
        {
            _model = model;
            _allowExternalSources = allowExternalSources;

            foreach(var param in model.Parameters)
            {
                Parameters.Add(new ParameterModel
                {
                    DataType = context.Replace(param.DataType),
                    DefaultValue = context.Replace(param.DefaultValue),
                    Name = context.Replace(param.Name),
                });
            }

            ProviderString = providerString;
            TargetStructure = context.GetDatabaseStructure(providerString);

            if (_model.IsFlatSync)
            {
                foreach (var src in _model.Sources)
                {
                    var entity = new SourceEntitySqlModel(src, this);
                    entity.LoadFlatColumns();
                    FlatSources.Add(entity);
                    entity.SqlAlias = src.Alias ?? "src_" + FlatSources.Count;
                    entity.InitializeQuerySource(src.DataSource, context, src.SourceTableVariable, src.SourceQueryVariable);
                    entity.MaterializeIfNeeded();
                }
            }
            else
            {
                SourceGraphModel = new SourceGraphSqlModel(model, context, this);
                foreach(var col in SourceGraphModel.Columns.Values)
                {
                    col.CompileFilter();
                }
            }
            foreach (var entity in model.Targets)
            {
                Entities.Add(new TargetEntitySqlModel(this, entity, context));
            }
            foreach (var fk in model.TargetReferences)
            {
                var sourceReplaced = context.Replace(fk.Source);
                var sourceEntity = FindTarget(sourceReplaced);
                string targetReplaced = context.Replace(fk.Target);
                var targetEntity = FindTarget(targetReplaced);
                if (sourceEntity == null) throw new Exception($"DBSH-00000 Source entity {sourceReplaced} not found");
                if (targetEntity == null) throw new Exception($"DBSH-00219 Target entity {targetReplaced} not found");

                sourceEntity.AddReference(fk, targetEntity);
            }

            PartialSortEntitiesByRefs();

            foreach (var entity in Entities)
            {
                entity.CreateJoinModel();
            }

            foreach (var entity in Entities)
            {
                entity.TestCorrectness();
            }
        }