public void Recreate( PersistentCollection collection, object id, ISessionImplementor session )
		{
			if( !isInverse )
			{
				if( log.IsDebugEnabled )
				{
					log.Debug( "Inserting collection: " + MessageHelper.InfoString( this, id ) );
				}

				try
				{
					// create all the new entries
					ICollection entries = collection.Entries();
					if( entries.Count > 0 )
					{
						int i = 0;
						int count = 0;
						try
						{
							collection.PreInsert( this );

							foreach( object entry in entries )
							{
								if( collection.EntryExists( entry, i ) )
								{
									IDbCommand 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++;
							}
						} 
							//TODO: change to SqlException
						catch( Exception e )
						{
							session.Batcher.AbortBatch( e );
							throw;
						}
						if( log.IsDebugEnabled )
						{
							log.Debug( string.Format( "done inserting collection: {0} rows inserted", count ) );
						}
					}
					else
					{
						if( log.IsDebugEnabled )
						{
							log.Debug( "collection was empty" );
						}
					}
				}
				catch( HibernateException )
				{
					// Do not call Convert on HibernateExceptions
					throw;
				}
				catch( Exception sqle )
				{
					throw Convert( sqle, "could not insert collection: " + MessageHelper.InfoString( this, id ) );
				}
			}
		}
Пример #2
0
        public void Recreate(PersistentCollection collection, object id, ISessionImplementor session)
        {
            if (!isInverse)
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("Inserting collection: " + MessageHelper.InfoString(this, id));
                }

                try
                {
                    // create all the new entries
                    ICollection entries = collection.Entries();
                    if (entries.Count > 0)
                    {
                        int i     = 0;
                        int count = 0;
                        try
                        {
                            collection.PreInsert(this);

                            foreach (object entry in entries)
                            {
                                if (collection.EntryExists(entry, i))
                                {
                                    IDbCommand 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++;
                            }
                        }
                        //TODO: change to SqlException
                        catch (Exception e)
                        {
                            session.Batcher.AbortBatch(e);
                            throw;
                        }
                        if (log.IsDebugEnabled)
                        {
                            log.Debug(string.Format("done inserting collection: {0} rows inserted", count));
                        }
                    }
                    else
                    {
                        if (log.IsDebugEnabled)
                        {
                            log.Debug("collection was empty");
                        }
                    }
                }
                catch (HibernateException)
                {
                    // Do not call Convert on HibernateExceptions
                    throw;
                }
                catch (Exception sqle)
                {
                    throw Convert(sqle, "could not insert collection: " + MessageHelper.InfoString(this, id));
                }
            }
        }