FileDocCategorySizeDatePackage
Insert.javaAPI DocHibernate 3.2.52540Fri Mar 24 11:10:04 GMT 2006org.hibernate.sql

Insert

public class Insert extends Object
An SQL INSERT statement
author
Gavin King

Fields Summary
private org.hibernate.dialect.Dialect
dialect
private String
tableName
private String
comment
private Map
columns
Constructors Summary
public Insert(org.hibernate.dialect.Dialect dialect)


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

		return addColumn(columnName, "?");
	
public org.hibernate.sql.InsertaddColumn(java.lang.String columnName, java.lang.String value)

		columns.put(columnName, value);
		return this;
	
public org.hibernate.sql.InsertaddColumn(java.lang.String columnName, java.lang.Object value, org.hibernate.type.LiteralType type)

		return addColumn( columnName, type.objectToSQLString(value, dialect) );
	
public org.hibernate.sql.InsertaddColumns(java.lang.String[] columnNames)

		for ( int i=0; i<columnNames.length; i++ ) {
			addColumn( columnNames[i] );
		}
		return this;
	
public org.hibernate.sql.InsertaddColumns(java.lang.String[] columnNames, boolean[] insertable)

		for ( int i=0; i<columnNames.length; i++ ) {
			if ( insertable[i] ) {
				addColumn( columnNames[i] );
			}
		}
		return this;
	
public org.hibernate.sql.InsertaddIdentityColumn(java.lang.String columnName)

		String value = dialect.getIdentityInsertString();
		if ( value != null ) {
			addColumn( columnName, value );
		}
		return this;
	
protected org.hibernate.dialect.DialectgetDialect()

		return dialect;
	
public org.hibernate.sql.InsertsetComment(java.lang.String comment)

		this.comment = comment;
		return this;
	
public org.hibernate.sql.InsertsetTableName(java.lang.String tableName)

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

		StringBuffer buf = new StringBuffer( columns.size()*15 + tableName.length() + 10 );
		if ( comment != null ) {
			buf.append( "/* " ).append( comment ).append( " */ " );
		}
		buf.append("insert into ")
			.append(tableName);
		if ( columns.size()==0 ) {
			buf.append(' ").append( dialect.getNoColumnsInsertString() );
		}
		else {
			buf.append(" (");
			Iterator iter = columns.keySet().iterator();
			while ( iter.hasNext() ) {
				buf.append( iter.next() );
				if ( iter.hasNext() ) {
					buf.append( ", " );
				}
			}
			buf.append(") values (");
			iter = columns.values().iterator();
			while ( iter.hasNext() ) {
				buf.append( iter.next() );
				if ( iter.hasNext() ) {
					buf.append( ", " );
				}
			}
			buf.append(')");
		}
		return buf.toString();