class ConstraintUnique extends Constraint {

    private Index index;
    private boolean indexOwner;
    private IndexColumn[] columns;
    private final boolean primaryKey;

    public ConstraintUnique(Schema schema, int id, String name, Table table, boolean primaryKey) {
        super(schema, id, name, table);
        this.primaryKey = primaryKey;
    }

    @Override
    public String getConstraintType() {
        return primaryKey ? Constraint.PRIMARY_KEY : Constraint.UNIQUE;
    }

    private String getCreateSQLForCopy(Table forTable, String quotedName, boolean internalIndex) {
        StatementBuilder buff = new StatementBuilder("ALTER TABLE ");
        buff.append(forTable.getSQL()).append(" ADD CONSTRAINT ");
        if (forTable.isHidden()) {
            buff.append("IF NOT EXISTS ");
        }
        buff.append(quotedName);
        if (comment != null) {
            buff.append(" COMMENT ").append(StringUtils.quoteStringSQL(comment));
        }
        buff.append(' ').append(getTypeName()).append('(');
        for (IndexColumn c : columns) {
            buff.appendExceptFirst(", ");
            buff.append(forTable.getDatabase().quoteIdentifier(c.column.getName()));
        }
        buff.append(')');
        if (internalIndex && indexOwner && forTable == this.table) {
            buff.append(" INDEX ").append(index.getSQL());
        }
        return buff.toString();
    }

    private String getTypeName() {
        if (primaryKey) {
            return "PRIMARY KEY";
        }
        return "UNIQUE";
    }

    @Override
    public String getCreateSQLWithoutIndexes() {
        return getCreateSQLForCopy(table, getSQL(), false);
    }

    @Override
    public String getCreateSQL() {
        return getCreateSQLForCopy(table, getSQL(), true);
    }

    public void setColumns(IndexColumn[] columns) {
        this.columns = columns;
    }

    public IndexColumn[] getColumns() {
        return columns;
    }

    /**
     * Set the index to use for this unique constraint.
     *
     * @param index the index
     * @param isOwner true if the index is generated by the system and belongs
     *            to this constraint
     */
    public void setIndex(Index index, boolean isOwner) {
        this.index = index;
        this.indexOwner = isOwner;
    }

    @Override
    public void removeChildrenAndResources(ServerSession session, DbObjectLock lock) {
        table.removeConstraint(this);
        if (indexOwner) {
            table.removeIndexOrTransferOwnership(session, index, lock);
        }
    }

    @Override
    public void invalidate() {
        index = null;
        columns = null;
        table = null;
        super.invalidate();
    }

    @Override
    public void checkRow(ServerSession session, Table t, Row oldRow, Row newRow) {
        // unique index check is enough
    }

    @Override
    public boolean usesIndex(Index idx) {
        return idx == index;
    }

    @Override
    public void setIndexOwner(Index index) {
        indexOwner = true;
    }

    @Override
    public HashSet<Column> getReferencedColumns(Table table) {<FILL_FUNCTION_BODY>}

    @Override
    public boolean isBefore() {
        return true;
    }

    @Override
    public void checkExistingData(ServerSession session) {
        // no need to check: when creating the unique index any problems are
        // found
    }

    @Override
    public Index getUniqueIndex() {
        return index;
    }

    @Override
    public void rebuild() {
        // nothing to do
    }
}

        HashSet<Column> result = new HashSet<>(columns.length);
        for (IndexColumn c : columns) {
            result.add(c.column);
        }
        return result;
    
<methods>public abstract void checkExistingData(com.lealone.db.session.ServerSession) ,public abstract void checkRow(com.lealone.db.session.ServerSession, com.lealone.db.table.Table, com.lealone.db.result.Row, com.lealone.db.result.Row) ,public int compareTo(com.lealone.db.constraint.Constraint) ,public abstract java.lang.String getConstraintType() ,public abstract java.lang.String getCreateSQLWithoutIndexes() ,public void getDependencies(Set<com.lealone.db.DbObject>) ,public com.lealone.db.table.Table getRefTable() ,public abstract HashSet<com.lealone.db.table.Column> getReferencedColumns(com.lealone.db.table.Table) ,public com.lealone.db.table.Table getTable() ,public com.lealone.db.DbObjectType getType() ,public abstract com.lealone.db.index.Index getUniqueIndex() ,public abstract boolean isBefore() ,public boolean isHidden() ,public abstract void rebuild() ,public abstract void setIndexOwner(com.lealone.db.index.Index) ,public abstract boolean usesIndex(com.lealone.db.index.Index) <variables>public static final java.lang.String CHECK,public static final java.lang.String PRIMARY_KEY,public static final java.lang.String REFERENTIAL,public static final java.lang.String UNIQUE,protected com.lealone.db.table.Table table