public Task BindSelectByUniqueKeyAsync(
     ISessionImplementor session,
     DbCommand selectCommand,
     IBinder binder,
     string[] suppliedPropertyNames, CancellationToken cancellationToken)
 {
     if (cancellationToken.IsCancellationRequested)
     {
         return(Task.FromCanceled <object>(cancellationToken));
     }
     return(binder.BindValuesAsync(selectCommand, cancellationToken));
 }
Ejemplo n.º 2
0
            protected internal override async Task BindParametersAsync(ISessionImplementor session, DbCommand ps, IBinder binder, CancellationToken cancellationToken)
            {
                cancellationToken.ThrowIfCancellationRequested();
                // 6.0 TODO: remove the "if" block and do the other TODO of this method
                if (persister is IEntityPersister)
                {
#pragma warning disable 618
                    await(BindParametersAsync(session, ps, binder.Entity, cancellationToken)).ConfigureAwait(false);
#pragma warning restore 618
                    return;
                }

                if (persister is ICompositeKeyPostInsertIdentityPersister compositeKeyPersister)
                {
                    await(compositeKeyPersister.BindSelectByUniqueKeyAsync(session, ps, binder, uniqueKeySuppliedPropertyNames, cancellationToken)).ConfigureAwait(false);
                    return;
                }

                // 6.0 TODO: remove by merging ICompositeKeyPostInsertIdentityPersister in IPostInsertIdentityPersister
                await(binder.BindValuesAsync(ps, cancellationToken)).ConfigureAwait(false);
            }
Ejemplo n.º 3
0
 public async Task <object> PerformInsertAsync(SqlCommandInfo insertSQL, ISessionImplementor session, IBinder binder, CancellationToken cancellationToken)
 {
     cancellationToken.ThrowIfCancellationRequested();
     try
     {
         // prepare and execute the insert
         var insert = await(PrepareAsync(insertSQL, session, cancellationToken)).ConfigureAwait(false);
         try
         {
             await(binder.BindValuesAsync(insert, cancellationToken)).ConfigureAwait(false);
             return(await(ExecuteAndExtractAsync(insert, session, cancellationToken)).ConfigureAwait(false));
         }
         finally
         {
             ReleaseStatement(insert, session);
         }
     }
     catch (DbException sqle)
     {
         throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, sqle,
                                          "could not insert: " + persister.GetInfoString(), insertSQL.Text);
     }
 }
        public async Task <object> PerformInsertAsync(SqlCommandInfo insertSql, ISessionImplementor session, IBinder binder, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            // NH-2145: Prevent connection releases between insert and select when we cannot perform
            // them as a single statement. Retrieving id most of the time relies on using the same connection.
            session.ConnectionManager.FlushBeginning();
            try
            {
                try
                {
                    // prepare and execute the insert
                    var insert = await(session.Batcher.PrepareCommandAsync(insertSql.CommandType, insertSql.Text, insertSql.ParameterTypes, cancellationToken)).ConfigureAwait(false);
                    try
                    {
                        await(binder.BindValuesAsync(insert, cancellationToken)).ConfigureAwait(false);
                        await(session.Batcher.ExecuteNonQueryAsync(insert, cancellationToken)).ConfigureAwait(false);
                    }
                    finally
                    {
                        session.Batcher.CloseCommand(insert, null);
                    }
                }
                catch (DbException sqle)
                {
                    throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, sqle,
                                                     "could not insert: " + persister.GetInfoString(), insertSql.Text);
                }

                var selectSql = SelectSQL;
                using (new SessionIdLoggingContext(session.SessionId))
                {
                    try
                    {
                        //fetch the generated id in a separate query
                        var idSelect = await(session.Batcher.PrepareCommandAsync(CommandType.Text, selectSql, ParametersTypes, cancellationToken)).ConfigureAwait(false);
                        try
                        {
                            await(BindParametersAsync(session, idSelect, binder.Entity, cancellationToken)).ConfigureAwait(false);
                            var rs = await(session.Batcher.ExecuteReaderAsync(idSelect, cancellationToken)).ConfigureAwait(false);
                            try
                            {
                                return(await(GetResultAsync(session, rs, binder.Entity, cancellationToken)).ConfigureAwait(false));
                            }
                            finally
                            {
                                session.Batcher.CloseReader(rs);
                            }
                        }
                        finally
                        {
                            session.Batcher.CloseCommand(idSelect, null);
                        }
                    }
                    catch (DbException sqle)
                    {
                        throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, sqle,
                                                         "could not retrieve generated id after insert: " + persister.GetInfoString(),
                                                         insertSql.Text);
                    }
                }
            }
            finally
            {
                session.ConnectionManager.FlushEnding();
            }
        }