FileDocCategorySizeDatePackage
InsertSelect.javaAPI DocHibernate 3.2.51944Tue Jun 07 15:06:10 BST 2005org.hibernate.sql

InsertSelect

public class InsertSelect extends Object
Implementation of InsertSelect.
author
Steve Ebersole

Fields Summary
private org.hibernate.dialect.Dialect
dialect
private String
tableName
private String
comment
private List
columnNames
private Select
select
Constructors Summary
public InsertSelect(org.hibernate.dialect.Dialect dialect)


	   
		this.dialect = dialect;
	
Methods Summary
public org.hibernate.sql.InsertSelectaddColumn(java.lang.String columnName)

		columnNames.add( columnName );
		return this;
	
public org.hibernate.sql.InsertSelectaddColumns(java.lang.String[] columnNames)

		for ( int i = 0; i < columnNames.length; i++ ) {
			this.columnNames.add( columnNames[i] );
		}
		return this;
	
public org.hibernate.sql.InsertSelectsetComment(java.lang.String comment)

		this.comment = comment;
		return this;
	
public org.hibernate.sql.InsertSelectsetSelect(Select select)

		this.select = select;
		return this;
	
public org.hibernate.sql.InsertSelectsetTableName(java.lang.String tableName)

		this.tableName = tableName;
		return this;
	
public java.lang.StringtoStatementString()

		if ( tableName == null ) throw new HibernateException( "no table name defined for insert-select" );
		if ( select == null ) throw new HibernateException( "no select defined for insert-select" );

		StringBuffer buf = new StringBuffer( (columnNames.size() * 15) + tableName.length() + 10 );
		if ( comment!=null ) {
			buf.append( "/* " ).append( comment ).append( " */ " );
		}
		buf.append( "insert into " ).append( tableName );
		if ( !columnNames.isEmpty() ) {
			buf.append( " (" );
			Iterator itr = columnNames.iterator();
			while ( itr.hasNext() ) {
				buf.append( itr.next() );
				if ( itr.hasNext() ) {
					buf.append( ", " );
				}
			}
			buf.append( ")" );
		}
		buf.append( ' " ).append( select.toStatementString() );
		return buf.toString();