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 ) );
				}

			}
		}
Example #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));
                }
            }
        }
		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 ) );
				}
			}
		}
Example #4
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));
                }
            }
        }