@Override
	public <T> void prepareMerge(SQLStatement stat, String schemaName, String tableName,
			TableDefinition<T> def, Object obj) {
		StatementBuilder buff = new StatementBuilder("INSERT INTO ");
		buff.append(prepareTableName(schemaName, tableName));
		buff.append(" (");
		buff.resetCount();
		for (FieldDefinition field : def.fields) {
			buff.appendExceptFirst(", ");
			buff.append(prepareColumnName(field.columnName));
		}
		buff.append(") (SELECT ");
		buff.resetCount();
		for (FieldDefinition field : def.fields) {
			buff.appendExceptFirst(", ");
			buff.append('?');
			Object value = def.getValue(obj, field);
			stat.addParameter(value);
		}
		buff.append(" FROM ");
		buff.append(prepareTableName(schemaName, tableName));
		buff.append(" WHERE ");
		buff.resetCount();
		for (FieldDefinition field : def.fields) {
			if (field.isPrimaryKey) {
				buff.appendExceptFirst(" AND ");
				buff.append(MessageFormat.format("{0} = ?", prepareColumnName(field.columnName)));
				Object value = def.getValue(obj, field);
				stat.addParameter(value);
			}
		}
		buff.append(" HAVING count(*)=0)");
		stat.setSQL(buff.toString());
	}