package lx.easydb.mapping;

import java.util.Iterator;

import lx.easydb.StringHelper;
import lx.easydb.dialect.Dialect;

public class PrimaryKey extends Constraint {

	public String toSqlConstraintString(Dialect dialect) {
        StringBuffer sb = StringHelper.createBuilder().append("primary key (");
        return appendColumns(sb, dialect).append(")").toString();
    }
	
	protected String doToSqlConstraint(Dialect dialect, String constraintName) {
		StringBuffer sb = StringHelper.createBuilder()
            .append(dialect.getAddPrimaryKeyConstraintString(constraintName))
            .append("(");
        return appendColumns(sb, dialect).append(")").toString();
    }
	
	private StringBuffer appendColumns(StringBuffer sb, Dialect dialect) {
		boolean append = false;
		Iterator it = getColumns().iterator();
		while (it.hasNext()) {
			if (append)
				sb.append(", ");
			else
				append = true;
			Column column = (Column) it.next();
			sb.append(column.getQuotedName(dialect));
		}
        return sb;
    }
}

@@ -159,16 +159,228 @@
 traint %7B
+%0A%09%0A%09public PrimaryKey() %7B%0A%09%09%0A%09%7D%0A%09%0A%09public PrimaryKey(Column column) %7B%0A%09%09addColumn(column);%0A%09%7D%0A%09%0A%09public PrimaryKey(Column%5B%5D columns) %7B%0A%09%09for (int i = 0; i %3C columns.length; i++) %7B%0A%09%09%09addColumn(columns%5Bi%5D);%0A%09%09%7D%0A%09%7D
 %0A%0A%09publi

add constructs to PrimaryKey