Ejemplo n.º 1
0
        public virtual void BulkInsertStructures(IStructureSchema structureSchema, IStructure[] structures)
        {
            if (!structures.Any())
            {
                return;
            }

            if (HasPipe)
            {
                foreach (var structure in structures)
                {
                    structure.Data = Pipe.Writing(structureSchema, structure.Data);
                }
            }

            using (var structuresReader = new StructuresReader(new StructureStorageSchema(structureSchema, structureSchema.GetStructureTableName()), structures))
            {
                using (var bulkInserter = GetBulkCopy())
                {
                    bulkInserter.DestinationTableName = structuresReader.StorageSchema.Name;
                    bulkInserter.BatchSize            = structures.Length;

                    var fields = structuresReader.StorageSchema.GetFieldsOrderedByIndex().Where(f => !f.Equals(StructureStorageSchema.Fields.RowId)).ToArray();
                    foreach (var field in fields)
                    {
                        bulkInserter.AddColumnMapping(field.Name, field.Name);
                    }

                    bulkInserter.Write(structuresReader);
                }
            }
        }
        private void InsertStructures(StructuresReader structures)
        {
            using (var bulkInserter = _dbClient.GetBulkCopy())
            {
                bulkInserter.BatchSize = structures.RecordsAffected;
                bulkInserter.DestinationTableName = structures.StorageSchema.Name;
                bulkInserter.NotifyAfter = 0;

                foreach (var field in structures.StorageSchema.FieldsByIndex.Values)
                    bulkInserter.ColumnMappings.Add(field.Name, field.Name);

                bulkInserter.WriteToServer(structures);
                bulkInserter.Close();
            }
        }
        internal void Insert(IStructureSchema structureSchema, IEnumerable<IStructure> structures)
        {
            var structureStorageSchema = new StructureStorageSchema(structureSchema);
            var indexesStorageSchema = new IndexStorageSchema(structureSchema);
            var uniquesStorageSchema = new UniqueStorageSchema(structureSchema);

            foreach (var batch in _elementsBatcher.Batch(structures))
            {
                using (var structuresReader = new StructuresReader(structureStorageSchema, batch))
                {
                    var indexRows = batch.Select(s => new IndexRow(s.Id, s.Indexes.ToArray()));
                    using (var indexesReader = new IndexesReader(indexesStorageSchema, indexRows))
                    {
                        using (var uniquesReader = new UniquesReader(uniquesStorageSchema, batch.SelectMany(s => s.Uniques).ToList()))
                        {
                            InsertStructures(structuresReader);
                            InsertIndexes(indexesReader);
                            InsertUniques(uniquesReader);
                        }
                    }
                }
            }
        }
        protected virtual void BulkInsertStructures(IStructureSchema structureSchema, IStructure[] structures)
        {
            if (!structures.Any())
                return;

            var structureStorageSchema = new StructureStorageSchema(structureSchema, structureSchema.GetStructureTableName());

            using (var structuresReader = new StructuresReader(structureStorageSchema, structures))
            {
                using (var bulkInserter = MainDbClient.GetBulkCopy())
                {
                    bulkInserter.DestinationTableName = structuresReader.StorageSchema.Name;
                    bulkInserter.BatchSize = structures.Length;

                    var fields = structuresReader.StorageSchema.GetFieldsOrderedByIndex().Where(f => !f.Equals(StructureStorageSchema.Fields.RowId)).ToArray();
                    foreach (var field in fields)
                        bulkInserter.AddColumnMapping(field.Name, field.Name);

                    bulkInserter.Write(structuresReader);
                }
            }
        }