package org.seamframework.sql;

import java.util.Iterator;

public class Insert<X> extends AbstractStatement<X> {
	
	public Insert(Table<X> table) {
		super(table);
	}

	@Override
	public String toSql() {
		StringBuilder sql = new StringBuilder();
		sql.append("insert into ");
		sql.append( table.getQualifiedName() );
		sql.append(" (");
		for (Iterator<Column<X, ?>> i =  columns.iterator(); i.hasNext(); ) {
			sql.append( i.next().getName() ); 
			if ( i.hasNext() ) sql.append(", ");
		}
		sql.append(") values (");
		for (int i=0; i<columns.size()-1; i++) {
			sql.append("?, ");
		}
		sql.append("?)");
		return sql.toString();
	}
}
