Ejemplo n.º 1
0
        public void BulkInsert <T>(string tenantId, IReadOnlyCollection <T> documents,
                                   BulkInsertMode mode = BulkInsertMode.InsertsOnly,
                                   int batchSize       = 1000)
        {
            var bulkInsertion = new BulkInsertion(Tenancy[tenantId], Options);

            bulkInsertion.BulkInsert(documents, mode, batchSize);
        }
Ejemplo n.º 2
0
        public Task BulkInsertAsync <T>(string tenantId, IReadOnlyCollection <T> documents,
                                        BulkInsertMode mode            = BulkInsertMode.InsertsOnly, int batchSize = 1000,
                                        CancellationToken cancellation = default)
        {
            var bulkInsertion = new BulkInsertion(Tenancy[tenantId], Options);

            return(bulkInsertion.BulkInsertAsync(documents, mode, batchSize, cancellation));
        }
Ejemplo n.º 3
0
        public Task BulkInsertDocumentsAsync(string tenantId, IEnumerable <object> documents,
                                             BulkInsertMode mode = BulkInsertMode.InsertsOnly,
                                             int batchSize       = 1000, CancellationToken cancellation = default)
        {
            var bulkInsertion = new BulkInsertion(Tenancy[tenantId], Options);

            return(bulkInsertion.BulkInsertDocumentsAsync(documents, mode, batchSize, cancellation));
        }
Ejemplo n.º 4
0
        public void BulkInsertDocuments(string tenantId, IEnumerable <object> documents,
                                        BulkInsertMode mode = BulkInsertMode.InsertsOnly,
                                        int batchSize       = 1000)
        {
            var bulkInsertion = new BulkInsertion(Tenancy[tenantId], Options);

            bulkInsertion.BulkInsertDocuments(documents, mode, batchSize);
        }
Ejemplo n.º 5
0
        private void bulkInsertDocuments <T>(IReadOnlyCollection <T> documents, int batchSize, NpgsqlConnection conn,
                                             BulkInsertMode mode)
        {
            var provider = _tenant.Database.Providers.StorageFor <T>();
            var loader   = provider.BulkLoader;

            if (mode != BulkInsertMode.InsertsOnly)
            {
                var sql = loader.CreateTempTableForCopying();
                conn.CreateCommand(sql).ExecuteNonQuery();
            }

            if (documents.Count <= batchSize)
            {
                loadDocuments(documents, loader, mode, conn);
            }
            else
            {
                var batch = new List <T>(batchSize);

                foreach (var document in documents)
                {
                    batch.Add(document);

                    if (batch.Count < batchSize)
                    {
                        continue;
                    }

                    loadDocuments(batch, loader, mode, conn);
                    batch.Clear();
                }

                loadDocuments(batch, loader, mode, conn);
            }

            if (mode == BulkInsertMode.IgnoreDuplicates)
            {
                var copy = loader.CopyNewDocumentsFromTempTable();

                conn.CreateCommand(copy).ExecuteNonQuery();
            }
            else if (mode == BulkInsertMode.OverwriteExisting)
            {
                var overwrite = loader.OverwriteDuplicatesFromTempTable();
                var copy      = loader.CopyNewDocumentsFromTempTable();

                conn.CreateCommand(overwrite + ";" + copy).ExecuteNonQuery();
            }
        }
Ejemplo n.º 6
0
 public void BulkInsertDocuments(IEnumerable <object> documents, BulkInsertMode mode = BulkInsertMode.InsertsOnly, int batchSize = 1000)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 7
0
 public void BulkInsert <T>(T[] documents, BulkInsertMode mode = BulkInsertMode.InsertsOnly, int batchSize = 1000)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 8
0
 void IDocumentStore.BulkInsert <T>(string tenantId, IReadOnlyCollection <T> documents, BulkInsertMode mode = BulkInsertMode.InsertsOnly, int batchSize = 1000)
 {
     _documentStore.BulkInsert(tenantId, documents, mode, batchSize);
 }
Ejemplo n.º 9
0
 private void loadDocuments <T>(IEnumerable <T> documents, IBulkLoader <T> loader, BulkInsertMode mode,
                                NpgsqlConnection conn)
 {
     if (mode == BulkInsertMode.InsertsOnly)
     {
         loader.Load(_tenant, Serializer, conn, documents);
     }
     else
     {
         loader.LoadIntoTempTable(_tenant, Serializer, conn, documents);
     }
 }
Ejemplo n.º 10
0
        public void BulkInsertDocuments(IEnumerable <object> documents, BulkInsertMode mode = BulkInsertMode.InsertsOnly, int batchSize = 1000)
        {
            var bulkInsertion = new BulkInsertion(Tenancy.Default, Options, _writerPool);

            bulkInsertion.BulkInsertDocuments(documents, mode, batchSize);
        }
Ejemplo n.º 11
0
            public async Task BulkInsertAsync(int batchSize, NpgsqlConnection conn, BulkInsertion parent, BulkInsertMode mode,
                                              CancellationToken cancellation)
            {
                await parent._tenant.Database.EnsureStorageExistsAsync(typeof(T), cancellation).ConfigureAwait(true);

                await parent.bulkInsertDocumentsAsync(_documents, batchSize, conn, mode, cancellation).ConfigureAwait(false);
            }
Ejemplo n.º 12
0
 void IDocumentStore.BulkInsertDocuments(string tenantId, IEnumerable <object> documents, BulkInsertMode mode,
                                         int batchSize)
 {
     _documentStore.BulkInsertDocuments(tenantId, documents, mode, batchSize);
 }
Ejemplo n.º 13
0
 void IDocumentStore.BulkInsertDocuments(IEnumerable <object> documents, BulkInsertMode mode, int batchSize)
 {
     _documentStore.BulkInsertDocuments(documents, mode, batchSize);
 }
Ejemplo n.º 14
0
 private async Task loadDocumentsAsync <T>(IReadOnlyCollection <T> documents, IBulkLoader <T> loader, BulkInsertMode mode, NpgsqlConnection conn, CancellationToken cancellation)
 {
     if (mode == BulkInsertMode.InsertsOnly)
     {
         await loader.LoadAsync(_tenant, Serializer, conn, documents, cancellation).ConfigureAwait(false);
     }
     else
     {
         await loader.LoadIntoTempTableAsync(_tenant, Serializer, conn, documents, cancellation).ConfigureAwait(false);
     }
 }
Ejemplo n.º 15
0
        private void bulkInsertDocuments <T>(IReadOnlyCollection <T> documents, int batchSize, NpgsqlConnection conn, BulkInsertMode mode)
        {
            var loader = _tenant.BulkLoaderFor <T>();

            if (mode != BulkInsertMode.InsertsOnly)
            {
                var sql = loader.CreateTempTableForCopying();
                conn.RunSql(sql);
            }

            var writer = _writerPool.Lease();

            try
            {
                if (documents.Count <= batchSize)
                {
                    loadDocuments(documents, loader, mode, conn, writer);
                }
                else
                {
                    var batch = new List <T>(batchSize);

                    foreach (var document in documents)
                    {
                        batch.Add(document);

                        if (batch.Count < batchSize)
                        {
                            continue;
                        }

                        loadDocuments(batch, loader, mode, conn, writer);
                        batch.Clear();
                    }

                    loadDocuments(batch, loader, mode, conn, writer);
                }
            }
            finally
            {
                if (writer != null)
                {
                    _writerPool.Release(writer);
                }
            }

            if (mode == BulkInsertMode.IgnoreDuplicates)
            {
                var copy = loader.CopyNewDocumentsFromTempTable();

                conn.RunSql(copy);
            }
            else if (mode == BulkInsertMode.OverwriteExisting)
            {
                var overwrite = loader.OverwriteDuplicatesFromTempTable();
                var copy      = loader.CopyNewDocumentsFromTempTable();

                conn.RunSql(overwrite, copy);
            }
        }
Ejemplo n.º 16
0
 public void BulkInsert(int batchSize, NpgsqlConnection connection, BulkInsertion parent,
                        BulkInsertMode mode)
 {
     parent._tenant.Database.EnsureStorageExists(typeof(T));
     parent.bulkInsertDocuments(_documents, batchSize, connection, mode);
 }
Ejemplo n.º 17
0
 public void BulkInsert <T>(string tenantId,
                            IReadOnlyCollection <T> documents,
                            BulkInsertMode mode = BulkInsertMode.InsertsOnly,
                            int batchSize       = 1000) =>
 throw new NotImplementedException();
Ejemplo n.º 18
0
        public void BulkInsert <T>(IReadOnlyCollection <T> documents, BulkInsertMode mode = BulkInsertMode.InsertsOnly, int batchSize = 1000)
        {
            var bulkInsertion = new BulkInsertion(Tenancy.Default, Options, _writerPool);

            bulkInsertion.BulkInsert(documents, mode, batchSize);
        }
Ejemplo n.º 19
0
        private async Task bulkInsertDocumentsAsync <T>(IReadOnlyCollection <T> documents, int batchSize, NpgsqlConnection conn, BulkInsertMode mode, CancellationToken cancellation)
        {
            var provider = _tenant.Providers.StorageFor <T>();
            var loader   = provider.BulkLoader;

            if (mode != BulkInsertMode.InsertsOnly)
            {
                var sql = loader.CreateTempTableForCopying();
                await conn.CreateCommand(sql).ExecuteNonQueryAsync(cancellation).ConfigureAwait(false);
            }

            if (documents.Count <= batchSize)
            {
                await loadDocumentsAsync(documents, loader, mode, conn, cancellation).ConfigureAwait(false);
            }
            else
            {
                var batch = new List <T>(batchSize);

                foreach (var document in documents)
                {
                    batch.Add(document);

                    if (batch.Count < batchSize)
                    {
                        continue;
                    }

                    await loadDocumentsAsync(batch, loader, mode, conn, cancellation).ConfigureAwait(false);

                    batch.Clear();
                }

                await loadDocumentsAsync(batch, loader, mode, conn, cancellation).ConfigureAwait(false);
            }

            if (mode == BulkInsertMode.IgnoreDuplicates)
            {
                var copy = loader.CopyNewDocumentsFromTempTable();

                await conn.CreateCommand(copy).ExecuteNonQueryAsync(cancellation).ConfigureAwait(false);
            }
            else if (mode == BulkInsertMode.OverwriteExisting)
            {
                var overwrite = loader.OverwriteDuplicatesFromTempTable();
                var copy      = loader.CopyNewDocumentsFromTempTable();

                await conn.CreateCommand(overwrite + ";" + copy)
                .ExecuteNonQueryAsync(cancellation).ConfigureAwait(false);
            }
        }
Ejemplo n.º 20
0
        private void bulkInsertDocuments <T>(T[] documents, int batchSize, NpgsqlConnection conn, BulkInsertMode mode)
        {
            var loader = Schema.BulkLoaderFor <T>();

            if (mode != BulkInsertMode.InsertsOnly)
            {
                var sql = loader.CreateTempTableForCopying();
                conn.RunSql(sql);
            }

            if (documents.Length <= batchSize)
            {
                if (mode == BulkInsertMode.InsertsOnly)
                {
                    loader.Load(_serializer, conn, documents);
                }
                else
                {
                    loader.LoadIntoTempTable(_serializer, conn, documents);
                }
            }
            else
            {
                var total = 0;
                var page  = 0;

                while (total < documents.Length)
                {
                    var batch = documents.Skip(page * batchSize).Take(batchSize).ToArray();

                    if (mode == BulkInsertMode.InsertsOnly)
                    {
                        loader.Load(_serializer, conn, batch);
                    }
                    else
                    {
                        loader.LoadIntoTempTable(_serializer, conn, batch);
                    }


                    page++;
                    total += batch.Length;
                }
            }

            if (mode == BulkInsertMode.IgnoreDuplicates)
            {
                var copy = loader.CopyNewDocumentsFromTempTable();

                conn.RunSql(copy);
            }
            else if (mode == BulkInsertMode.OverwriteExisting)
            {
                var overwrite = loader.OverwriteDuplicatesFromTempTable();
                var copy      = loader.CopyNewDocumentsFromTempTable();

                conn.RunSql(overwrite, copy);
            }
        }
Ejemplo n.º 21
0
 public Task BulkInsertAsync(int batchSize, NpgsqlConnection conn, BulkInsertion parent, BulkInsertMode mode,
                             CancellationToken cancellation)
 {
     return(parent.bulkInsertDocumentsAsync(_documents, batchSize, conn, mode, cancellation));
 }
Ejemplo n.º 22
0
 public void BulkInsert(int batchSize, NpgsqlConnection connection, BulkInsertion parent, BulkInsertMode mode)
 {
     parent.bulkInsertDocuments(_documents, batchSize, connection, mode);
 }
 void IDocumentStore.BulkInsert <T>(IReadOnlyCollection <T> documents, BulkInsertMode mode, int batchSize)
 => _documentStore.BulkInsert(documents, mode, batchSize);