protected override int DoUpdateRows(object id, PersistentCollection collection, ISessionImplementor session)
 {
     try
     {
         IDbCommand  st      = null;
         ICollection entries = collection.Entries();
         try
         {
             int i     = 0;
             int count = 0;
             foreach (object entry in entries)
             {
                 if (collection.NeedsUpdating(entry, i, ElementType))
                 {
                     if (st == null)
                     {
                         st = session.Batcher.PrepareBatchCommand(SqlUpdateRowString);
                     }
                     if (!hasIdentifier)
                     {
                         WriteKey(st, id, true, session);
                     }
                     collection.WriteTo(st, this, entry, i, true);
                     session.Batcher.AddToBatch(1);
                     count++;
                 }
                 i++;
             }
             return(count);
         }
         catch (Exception e)
         {
             //TODO: change to SqlException
             // NB This calls cmd.Dispose
             session.Batcher.AbortBatch(e);
             throw;
         }
     }
     catch (HibernateException)
     {
         // Do not call Convert on HibernateExceptions
         throw;
     }
     catch (Exception sqle)
     {
         throw Convert(sqle, "could not update collection rows: " + MessageHelper.InfoString(this, id));
     }
 }
예제 #2
0
        protected override int DoUpdateRows(object id, PersistentCollection collection, ISessionImplementor session)
        {
            // we finish all the "removes" first to take care of possible unique
            // constraints and so that we can take better advantage of batching

            IDbCommand  st;
            ICollection entries;
            int         i;
            int         count;

            try
            {
                // update removed rows fks to null
                count = 0;
                try
                {
                    st      = null;
                    i       = 0;
                    entries = collection.Entries();
                    foreach (object entry in entries)
                    {
                        if (collection.NeedsUpdating(entry, i, ElementType))                            // will still be issued when it used to be null
                        {
                            if (st == null)
                            {
                                st = session.Batcher.PrepareBatchCommand(SqlDeleteRowString);
                            }
                            WriteKey(st, id, false, session);
                            WriteIndex(st, collection.GetIndex(entry, i), false, session);
                            session.Batcher.AddToBatch(-1);
                            count++;
                        }
                        i++;
                    }
                }
                catch (Exception e)
                {
                    session.Batcher.AbortBatch(e);
                    throw;
                }

                // now update all changed or added rows fks
                count = 0;
                try
                {
                    st      = null;
                    i       = 0;
                    entries = collection.Entries();
                    foreach (object entry in entries)
                    {
                        if (collection.NeedsUpdating(entry, i, ElementType))                            // will still be issued when it used to be null
                        {
                            if (st == null)
                            {
                                st = session.Batcher.PrepareBatchCommand(SqlInsertRowString);
                            }
                            WriteKey(st, id, false, session);
                            collection.WriteTo(st, this, entry, i, false);
                            session.Batcher.AddToBatch(1);
                            count++;
                        }
                        i++;
                    }
                }
                catch (Exception e)
                {
                    //TODO: change to SqlException
                    session.Batcher.AbortBatch(e);
                    throw;
                }
                return(count);
            }
            catch (HibernateException)
            {
                // Do not call Convert on HibernateExceptions
                throw;
            }
            catch (Exception sqle)
            {
                throw Convert(sqle, "could not update collection rows: " + MessageHelper.InfoString(this, id));
            }
        }
		protected override int DoUpdateRows( object id, PersistentCollection collection, ISessionImplementor session )
		{
			// we finish all the "removes" first to take care of possible unique 
			// constraints and so that we can take better advantage of batching

			IDbCommand st;
			ICollection entries;
			int i;
			int count;

			try
			{
				// update removed rows fks to null
				count = 0;
				try
				{
					st = null;
					i = 0;
					entries = collection.Entries();
					foreach( object entry in entries )
					{
						if( collection.NeedsUpdating( entry, i, ElementType ) ) // will still be issued when it used to be null
						{
							if( st == null )
							{
								st = session.Batcher.PrepareBatchCommand( SqlDeleteRowString );
							}
							WriteKey( st, id, false, session );
							WriteIndex( st, collection.GetIndex( entry, i ), false, session );
							session.Batcher.AddToBatch( -1 );
							count++;
						}
						i++;
					}
				}
				catch( Exception e )
				{
					session.Batcher.AbortBatch( e );
					throw;
				}

				// now update all changed or added rows fks
				count = 0;
				try
				{
					st = null;
					i = 0;
					entries = collection.Entries();
					foreach( object entry in entries )
					{
						if( collection.NeedsUpdating( entry, i, ElementType ) ) // will still be issued when it used to be null
						{
							if( st == null )
							{
								st = session.Batcher.PrepareBatchCommand( SqlInsertRowString );
							}
							WriteKey( st, id, false, session );
							collection.WriteTo( st, this, entry, i, false );
							session.Batcher.AddToBatch( 1 );
							count++;
						}
						i++;
					}
				}
				catch( Exception e )
				{
					//TODO: change to SqlException
					session.Batcher.AbortBatch( e );
					throw;
				}
				return count;
			}
			catch( HibernateException )
			{
				// Do not call Convert on HibernateExceptions
				throw;
			}
			catch( Exception sqle )
			{
				throw Convert( sqle, "could not update collection rows: " + MessageHelper.InfoString( this, id ) );
			}
		}
		protected override int DoUpdateRows( object id, PersistentCollection collection, ISessionImplementor session )
		{
			try
			{
				IDbCommand st = null;
				ICollection entries = collection.Entries();
				try
				{
					int i = 0;
					int count = 0;
					foreach( object entry in entries )
					{
						if( collection.NeedsUpdating( entry, i, ElementType ) )
						{
							if( st == null )
							{
								st = session.Batcher.PrepareBatchCommand( SqlUpdateRowString );
							}
							if( !hasIdentifier )
							{
								WriteKey( st, id, true, session );
							}
							collection.WriteTo( st, this, entry, i, true );
							session.Batcher.AddToBatch( 1 );
							count++;
						}
						i++;
					}
					return count;
				}
				catch( Exception e )
				{
					//TODO: change to SqlException
					// NB This calls cmd.Dispose
					session.Batcher.AbortBatch( e );
					throw;
				}
			}
			catch( HibernateException )
			{
				// Do not call Convert on HibernateExceptions
				throw;
			}
			catch( Exception sqle )
			{
				throw Convert( sqle, "could not update collection rows: " + MessageHelper.InfoString( this, id ) );
			}
		}