Exemplo n.º 1
0
        public TargetEntitySqlModel(DataSyncSqlModel dataSyncSqlModel, Target dbsh, IShellContext context)
        {
            this._dataSyncSqlModel = dataSyncSqlModel;
            this._dbsh = dbsh;
            TargetTable = new NameWithSchema(context.Replace(dbsh.TableSchema), context.Replace(dbsh.TableName));
            string findSchema = dbsh.TableSchema;
            if (findSchema != null && findSchema.StartsWith(NameWithSchema.NoQuotePrefix)) findSchema = null;
            Structure = dataSyncSqlModel.TargetStructure.FindTableLike(findSchema, TargetTable.Name);
            SqlAlias = _dbsh.Alias ?? "dst_" + _dataSyncSqlModel.Entities.Count;

            foreach (var col in dbsh.Columns)
            {
                var targetCol = new TargetNoRefColumnSqlModel(col, FindColumnInfo(col.Name));
                TargetColumns.Add(targetCol);

                foreach (string alias in ExtractColumnSources(col))
                {
                    SourceColumnSqlModel source = null;
                    if (dataSyncSqlModel.SourceGraphModel == null)
                    {
                        // flat sync
                        if (!String.IsNullOrEmpty(dbsh.PrimarySource))
                        {
                            var tableSource = DataSync.FlatSources.FirstOrDefault(x => x.Match(Dbsh.PrimarySource));
                            if (tableSource != null)
                            {
                                source = tableSource.Columns.FirstOrDefault(x => x.Alias == alias);
                            }
                        }
                    }
                    else
                    {
                        source = dataSyncSqlModel.SourceGraphModel[alias];
                        //targetCol.Sources.Add(source);
                    }
                    RequiredSourceColumns.Add(source);
                    if (col.IsKey) KeySourceColumns.Add(source);
                }
            }

            if (!String.IsNullOrEmpty(_dbsh.Connection))
            {
                var ctxConn = new NormalizedDatabaseConnectionInfo(new DatabaseConnectionInfoHolder { ProviderString = context.GetDefaultConnection() });
                var tableConn = new NormalizedDatabaseConnectionInfo(new DatabaseConnectionInfoHolder { ProviderString = context.Replace(_dbsh.Connection), LinkedInfo = _dbsh.LinkedInfo });

                if (ctxConn != tableConn)
                {
                    if (ctxConn.ServerConnectionString == tableConn.ServerConnectionString)
                    {
                        TargetLinkedInfo = tableConn.GetLinkedInfo();
                    }
                    else
                    {
                        throw new IncorrectRdsDefinitionException($"DBSH-00000 RDS target must be reachable by database or linked server: ({TargetTable})");
                    }
                }
            }
        }
Exemplo n.º 2
0
        protected override void DoRun(IShellContext context)
        {
            var model = GetModel(context);
            var sqlModel = new DataSyncSqlModel(model, context, false, context.Replace(GetProviderString(context)));

            var connection = GetConnectionProvider(context);
            using (var conn = connection.Connect())
            {
                sqlModel.CreateProcedure(conn, connection.Factory, new NameWithSchema(context.Replace(ProcSchema), context.Replace(ProcName)), context, UseTransaction, OverwriteExisting, sqlModel.Parameters);
            }
        }
Exemplo n.º 3
0
        public SqlScriptCompiler(IDatabaseFactory factory, DataSyncSqlModel datasync, IShellContext context, string procName)
        {
            _context = context;
            _procName = procName;
            _datasync = datasync;
            _factory = factory;

            _sw = new StringWriter();
            var so = new SqlOutputStream(factory.CreateDialect(), _sw, new SqlFormatProperties());
            so.OverrideCommandDelimiter(";");
            _dmp = factory.CreateDumper(so, new SqlFormatProperties());
        }
Exemplo n.º 4
0
        public SourceGraphSqlModel(SyncModel model, IShellContext context, DataSyncSqlModel dataSync)
        {
            _model = model;

            if (!model.Sources.Any())
            {
                throw new IncorrectRdsDefinitionException("LGM-00000 There are no available sources entities. Try to add source.");
            }

            foreach (var item in model.Sources)
            {
                var src = new SourceEntitySqlModel(item, dataSync);
                Entities.Add(src);
                src.SqlAlias = item.Alias ?? "src_" + Entities.Count;
                src.InitializeQuerySource(item.DataSource, context, context.Replace(item.SourceTableVariable), context.Replace(item.SourceQueryVariable));
                src.MaterializeIfNeeded();

                foreach (var colItem in item.Columns)
                {
                    string alias = colItem.AliasOrName;
                    if (!Columns.ContainsKey(alias))
                    {
                        Columns[alias] = new SourceColumnSqlModel
                        {
                            Alias = alias,
                        };
                    }
                    Columns[alias].DbshColumns.Add(colItem);
                    Columns[alias].Entities.Add(src);
                    src.Columns.Add(Columns[alias]);
                    if (!String.IsNullOrEmpty(colItem.Filter))
                    {
                        Columns[alias].Filters.Add(colItem.Filter);
                        if (colItem.FilterType != Driver.Common.FilterParser.FilterParser.ExpressionType.None)
                        {
                            Columns[alias].FilterType = colItem.FilterType;
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        protected override void DoRun(IShellContext context)
        {
            var model = GetModel(context);
            var sqlModel = new DataSyncSqlModel(model, context, true, context.Replace(GetProviderString(context)));

            var connection = GetConnectionProvider(context);
            using (var conn = connection.Connect())
            {
                var sqlconn = conn as SqlConnection;
                if (sqlconn != null)
                {
                    sqlconn.InfoMessage += (s, e) =>
                    {
                        foreach (SqlError error in e.Errors)
                        {
                            context.OutputMessage(error.Message);
                        }
                    };
                }
                sqlModel.Run(conn, connection.Factory, context, UseTransaction, sqlModel.Parameters, GetParameterValues(context));
            }
        }
Exemplo n.º 6
0
 public override string GenerateSql(IDatabaseFactory factory, IShellContext context)
 {
     var model = GetModel(context);
     var sqlModel = new DataSyncSqlModel(model, context, true, context.Replace(GetProviderString(context)));
     return sqlModel.GenerateScript(factory, context, UseTransaction, sqlModel.Parameters, GetParameterValues(context)) + SqlEditorInfoTool.FormatEditorInfo(EditorInfo);
 }
Exemplo n.º 7
0
 public SourceEntitySqlModel(Source dbsh, DataSyncSqlModel dataSync)
 {
     _dbsh = dbsh;
     _dataSync = dataSync;
 }
Exemplo n.º 8
0
 public override string GenerateSql(IDatabaseFactory factory, IShellContext context)
 {
     var model = GetModel(context);
     var sqlModel = new DataSyncSqlModel(model, context, false, context.Replace(GetProviderString(context)));
     return sqlModel.GenerateCreateProcedure(factory, new NameWithSchema(context.Replace(ProcSchema), context.Replace(ProcName)), context, UseTransaction, OverwriteExisting, sqlModel.Parameters, EditorInfo);
 }