예제 #1
0
        public async Task InsertRowsAsync(IPersistentCollection collection, object id, ISessionImplementor session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            if (!isInverse && RowInsertEnabled)
            {
                if (log.IsDebugEnabled())
                {
                    log.Debug("Inserting rows of collection: {0}", MessageHelper.CollectionInfoString(this, collection, id, session));
                }

                try
                {
                    // insert all the new entries
                    await(collection.PreInsertAsync(this, cancellationToken)).ConfigureAwait(false);
                    IExpectation expectation = Expectations.AppropriateExpectation(insertCheckStyle);
                    //bool callable = InsertCallable;
                    bool useBatch = expectation.CanBeBatched;
                    int  i        = 0;
                    int  count    = 0;

                    IEnumerable entries = collection.Entries(this);
                    foreach (object entry in entries)
                    {
                        if (await(collection.NeedsInsertingAsync(entry, i, elementType, cancellationToken)).ConfigureAwait(false))
                        {
                            object entryId;
                            if (!IsIdentifierAssignedByInsert)
                            {
                                // NH Different implementation: write once
                                entryId = await(PerformInsertAsync(id, collection, expectation, entry, i, useBatch, false, session, cancellationToken)).ConfigureAwait(false);
                            }
                            else
                            {
                                entryId = await(PerformInsertAsync(id, collection, entry, i, session, cancellationToken)).ConfigureAwait(false);
                            }
                            collection.AfterRowInsert(this, entry, i, entryId);
                            count++;
                        }
                        i++;
                    }

                    if (log.IsDebugEnabled())
                    {
                        log.Debug("done inserting rows: {0} inserted", count);
                    }
                }
                catch (DbException sqle)
                {
                    throw ADOExceptionHelper.Convert(sqlExceptionConverter, sqle,
                                                     "could not insert collection rows: " + MessageHelper.CollectionInfoString(this, collection, id, session));
                }
            }
        }
예제 #2
0
        public async Task RecreateAsync(IPersistentCollection collection, object id, ISessionImplementor session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            if (!isInverse && RowInsertEnabled)
            {
                if (log.IsDebugEnabled())
                {
                    log.Debug("Inserting collection: {0}", MessageHelper.CollectionInfoString(this, collection, id, session));
                }

                try
                {
                    IExpectation expectation = null;
                    bool         useBatch    = false;
                    int          i           = 0;
                    int          count       = 0;

                    // create all the new entries
                    foreach (var entry in collection.Entries(this))
                    {
                        // Init, if we're on the first element.
                        if (count == 0)
                        {
                            expectation = Expectations.AppropriateExpectation(insertCheckStyle);
                            await(collection.PreInsertAsync(this, cancellationToken)).ConfigureAwait(false);
                            //bool callable = InsertCallable;
                            useBatch = expectation.CanBeBatched;
                        }

                        if (collection.EntryExists(entry, i))
                        {
                            object entryId;
                            if (!IsIdentifierAssignedByInsert)
                            {
                                // NH Different implementation: write once
                                entryId = await(PerformInsertAsync(id, collection, expectation, entry, i, useBatch, false, session, cancellationToken)).ConfigureAwait(false);
                            }
                            else
                            {
                                entryId = await(PerformInsertAsync(id, collection, entry, i, session, cancellationToken)).ConfigureAwait(false);
                            }
                            collection.AfterRowInsert(this, entry, i, entryId);
                            count++;
                        }
                        i++;
                    }

                    if (log.IsDebugEnabled())
                    {
                        if (count > 0)
                        {
                            log.Debug("done inserting collection: {0} rows inserted", count);
                        }
                        else
                        {
                            log.Debug("collection was empty");
                        }
                    }
                }
                catch (DbException sqle)
                {
                    throw ADOExceptionHelper.Convert(sqlExceptionConverter, sqle,
                                                     "could not insert collection: " + MessageHelper.CollectionInfoString(this, collection, id, session));
                }
            }
        }