Ejemplo n.º 1
0
        private List <RowIdentifier> ParseClonedRows(Dictionary <Int16, ExecutionPlan> exucutionPlanByServer)
        {
            var clonedRows = new List <RowIdentifier>();

            foreach (var server in exucutionPlanByServer)
            {
                foreach (var row in server.Value.InsertSteps.Where(s => s.Depth == 0))
                {
                    var pkTemp = row.TableSchema.BuildPkFromDataRow(row.Datarow);

                    //Clone for new reference
                    var clonedPk = new ColumnsWithValue();
                    foreach (var col in pkTemp)
                    {
                        var sqlVar = col.Value as SqlVariable;
                        clonedPk.Add(col.Key, sqlVar != null ? sqlVar.Value : col.Value);
                    }

                    var riReturn = new RowIdentifier
                    {
                        ServerId = row.DestinationTable.ServerId,
                        Database = row.DestinationTable.Database,
                        Schema   = row.DestinationTable.Schema,
                        Table    = row.DestinationTable.Table,
                        Columns  = clonedPk
                    };

                    //Construit la pk de retour
                    clonedRows.Add(riReturn);
                }
            }

            return(clonedRows);
        }
Ejemplo n.º 2
0
 public new static RowIdentifier Deserialize(BinaryReader input)
 {
     return(new RowIdentifier
     {
         ServerId = input.ReadInt16(),
         Database = input.ReadString(),
         Schema = input.ReadString(),
         Table = input.ReadString(),
         Columns = ColumnsWithValue.Deserialize(input)
     });
 }
Ejemplo n.º 3
0
        public static ColumnsWithValue Deserialize(BinaryReader input)
        {
            var cols = new ColumnsWithValue();

            var nbCols = input.ReadInt32();

            for (int i = 0; i < nbCols; i++)
            {
                var key   = input.ReadString();
                var value = SerializationHelper.Deserialize <Object>(input.BaseStream);
                cols.Add(key, value);
            }
            return(cols);
        }
Ejemplo n.º 4
0
 public RowIdentifier()
 {
     Columns = new ColumnsWithValue();
 }
Ejemplo n.º 5
0
        private void BuildCircularReferencesPlan()
        {
            foreach (var job in _circularKeyJobs)
            {
                var baseTable           = MetadataContainer.Metadatas.GetTable(job.SourceBaseRowStartPoint);
                var fkTable             = MetadataContainer.Metadatas.GetTable(job.SourceFkRowStartPoint);
                var pkDestinationRow    = _keyRelationships.GetKey(job.SourceBaseRowStartPoint);
                var keyDestinationFkRow = _keyRelationships.GetKey(job.SourceFkRowStartPoint);

                var serverDstBaseTable = MetadataContainer.ServerMap[new ServerIdentifier
                                                                     {
                                                                         ServerId = job.SourceBaseRowStartPoint.ServerId,
                                                                         Database = job.SourceBaseRowStartPoint.Database,
                                                                         Schema = job.SourceBaseRowStartPoint.Schema
                                                                     }];

                var serverDstFkTable = MetadataContainer.ServerMap[new ServerIdentifier
                                                                   {
                                                                       ServerId = job.SourceFkRowStartPoint.ServerId,
                                                                       Database = job.SourceFkRowStartPoint.Database,
                                                                       Schema = job.SourceFkRowStartPoint.Schema
                                                                   }];

                if (job.ForeignKey.Columns.Count != keyDestinationFkRow.Length)
                {
                    throw new Exception("The foreign key defenition is not matching with the values.");
                }

                var fk = new ColumnsWithValue();
                for (var i = 0; i < job.ForeignKey.Columns.Count; i++)
                {
                    var colName = job.ForeignKey.Columns[i].NameTo;
                    var value   = keyDestinationFkRow[i];

                    fk.Add(colName, value);
                }

                var riBaseDestination = new RowIdentifier
                {
                    ServerId = serverDstBaseTable.ServerId,
                    Database = serverDstBaseTable.Database,
                    Schema   = serverDstBaseTable.Schema,
                    Table    = job.SourceBaseRowStartPoint.Table,
                    Columns  = baseTable.BuildPkFromRawKey(pkDestinationRow)
                };

                var riFkDestination = new RowIdentifier
                {
                    ServerId = serverDstFkTable.ServerId,
                    Database = serverDstFkTable.Database,
                    Schema   = serverDstFkTable.Schema,
                    Table    = job.SourceFkRowStartPoint.Table,
                    Columns  = fk
                };

                var fkDestinationDataRow = GetDataRow(riFkDestination);
                var modifiedFk           = fkTable.BuildKeyFromFkDataRow(job.ForeignKey, fkDestinationDataRow);

                var step = new UpdateStep()
                {
                    StepId           = _nextStepId++,
                    DestinationRow   = riBaseDestination,
                    ForeignKey       = modifiedFk,
                    DestinationTable = riFkDestination
                };

                AddUpdateStep(step);
            }
            _circularKeyJobs.Clear();
        }