public object PerformInsert(SqlCommandInfo insertSQL, ISessionImplementor session, IBinder binder)
        {
            try
            {
                // prepare and execute the insert
                IDbCommand insert = session.Batcher.PrepareCommand(insertSQL.CommandType, insertSQL.Text, insertSQL.ParameterTypes);
                try
                {
                    binder.BindValues(insert);
                    session.Batcher.ExecuteNonQuery(insert);
                }
                finally
                {
                    session.Batcher.CloseCommand(insert, null);
                }
            }
            catch (DbException sqle)
            {
                throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, sqle,
                                                 "could not insert: " + persister.GetInfoString(), insertSQL.Text);
            }

            SqlString selectSQL = SelectSQL;

            using (new SessionIdLoggingContext(session.SessionId))
                try
                {
                    //fetch the generated id in a separate query
                    IDbCommand idSelect = session.Batcher.PrepareCommand(CommandType.Text, selectSQL, ParametersTypes);
                    try
                    {
                        BindParameters(session, idSelect, binder.Entity);
                        IDataReader rs = session.Batcher.ExecuteReader(idSelect);
                        try
                        {
                            return(GetResult(session, rs, binder.Entity));
                        }
                        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);
                }
        }
		public object PerformInsert(SqlCommandInfo insertSQL, ISessionImplementor session, IBinder binder)
		{
			try
			{
				// prepare and execute the insert
				IDbCommand insert = session.Batcher.PrepareCommand(insertSQL.CommandType, insertSQL.Text, insertSQL.ParameterTypes);
				try
				{
					binder.BindValues(insert);
					session.Batcher.ExecuteNonQuery(insert);
				}
				finally
				{
					session.Batcher.CloseCommand(insert, null);
				}
			}
			catch (DbException sqle)
			{
				throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, sqle,
				                                 "could not insert: " + persister.GetInfoString(), insertSQL.Text);
			}

			SqlString selectSQL = SelectSQL;
			using (new SessionIdLoggingContext(session.SessionId)) 
			try
			{
				//fetch the generated id in a separate query
				IDbCommand idSelect = session.Batcher.PrepareCommand(CommandType.Text, selectSQL, ParametersTypes);
				try
				{
					BindParameters(session, idSelect, binder.Entity);
					IDataReader rs = session.Batcher.ExecuteReader(idSelect);
					try
					{
						return GetResult(session, rs, binder.Entity);
					}
					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);
			}
		}
Ejemplo n.º 3
0
            protected internal override void BindParameters(ISessionImplementor session, DbCommand ps, IBinder binder)
            {
                // 6.0 TODO: remove the "if" block and do the other TODO of this method
                if (persister is IEntityPersister)
                {
#pragma warning disable 618
                    BindParameters(session, ps, binder.Entity);
#pragma warning restore 618
                    return;
                }

                if (persister is ICompositeKeyPostInsertIdentityPersister compositeKeyPersister)
                {
                    compositeKeyPersister.BindSelectByUniqueKey(session, ps, binder, uniqueKeySuppliedPropertyNames);
                    return;
                }

                // 6.0 TODO: remove by merging ICompositeKeyPostInsertIdentityPersister in IPostInsertIdentityPersister
                binder.BindValues(ps);
            }
Ejemplo n.º 4
0
 public object PerformInsert(SqlCommandInfo insertSQL, ISessionImplementor session, IBinder binder)
 {
     try
     {
         // prepare and execute the insert
         IDbCommand insert = Prepare(insertSQL, session);
         try
         {
             binder.BindValues(insert);
             return ExecuteAndExtract(insert, session);
         }
         finally
         {
             ReleaseStatement(insert, session);
         }
     }
     catch (DbException sqle)
     {
         throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, sqle,
                                          "could not insert: " + MessageHelper.InfoString(persister), insertSQL.Text);
     }
 }
Ejemplo n.º 5
0
 public object PerformInsert(SqlCommandInfo insertSQL, ISessionImplementor session, IBinder binder)
 {
     try
     {
         // prepare and execute the insert
         IDbCommand insert = Prepare(insertSQL, session);
         try
         {
             binder.BindValues(insert);
             return(ExecuteAndExtract(insert, session));
         }
         finally
         {
             ReleaseStatement(insert, session);
         }
     }
     catch (DbException sqle)
     {
         throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, sqle,
                                          "could not insert: " + persister.GetInfoString(), insertSQL.Text);
     }
 }
        public object PerformInsert(SqlCommandInfo insertSql, ISessionImplementor session, IBinder binder)
        {
            // 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 = session.Batcher.PrepareCommand(insertSql.CommandType, insertSql.Text, insertSql.ParameterTypes);
                    try
                    {
                        binder.BindValues(insert);
                        session.Batcher.ExecuteNonQuery(insert);
                    }
                    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 (session.BeginProcess())
                {
                    try
                    {
                        //fetch the generated id in a separate query
                        var idSelect = session.Batcher.PrepareCommand(CommandType.Text, selectSql, ParametersTypes);
                        try
                        {
                            BindParameters(session, idSelect, binder);
                            var rs = session.Batcher.ExecuteReader(idSelect);
                            try
                            {
                                return(GetResult(session, rs, binder.Entity));
                            }
                            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();
            }
        }