public void InsertRows( PersistentCollection collection, object id, ISessionImplementor session )
		{
			if( !isInverse )
			{
				if( log.IsDebugEnabled )
				{
					log.Debug( "Inserting rows of collection: " + role + "#" + id );
				}

				collection.PreInsert( this );
				int i = 0;
				int count = 0;

				try
				{
					// insert all the new entries
					ICollection entries = collection.Entries();
					try
					{
						// Moved the IDbCommand outside the loop, because ADO.NET doesn't do batch commands,
						// so it's more efficient. But it
						foreach( object entry in entries )
						{
							if( collection.NeedsInserting( entry, i, elementType ) )
							{
								IDbCommand st = 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 );
								collection.AfterRowInsert( this, entry, i );
								count++;
							}
							i++;
						}

						if( log.IsDebugEnabled )
						{
							log.Debug( string.Format( "done inserting rows: {0} inserted", count ) );
						}
					}
					catch( Exception e )
					{
						session.Batcher.AbortBatch( e );
						throw;
					}
				}
				catch( HibernateException )
				{
					// Do not call Convert on HibernateExceptions
					throw;
				}
				catch( Exception sqle )
				{
					throw Convert( sqle, "could not insert collection rows: " + MessageHelper.InfoString( this, id ) );
				}

			}
		}
示例#2
0
        public void InsertRows(PersistentCollection collection, object id, ISessionImplementor session)
        {
            if (!isInverse)
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("Inserting rows of collection: " + role + "#" + id);
                }

                collection.PreInsert(this);
                int i     = 0;
                int count = 0;

                try
                {
                    // insert all the new entries
                    ICollection entries = collection.Entries();
                    try
                    {
                        // Moved the IDbCommand outside the loop, because ADO.NET doesn't do batch commands,
                        // so it's more efficient. But it
                        foreach (object entry in entries)
                        {
                            if (collection.NeedsInserting(entry, i, elementType))
                            {
                                IDbCommand st = 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);
                                collection.AfterRowInsert(this, entry, i);
                                count++;
                            }
                            i++;
                        }

                        if (log.IsDebugEnabled)
                        {
                            log.Debug(string.Format("done inserting rows: {0} inserted", count));
                        }
                    }
                    catch (Exception e)
                    {
                        session.Batcher.AbortBatch(e);
                        throw;
                    }
                }
                catch (HibernateException)
                {
                    // Do not call Convert on HibernateExceptions
                    throw;
                }
                catch (Exception sqle)
                {
                    throw Convert(sqle, "could not insert collection rows: " + MessageHelper.InfoString(this, id));
                }
            }
        }