Example usage for org.hibernate.mapping PrimaryKey getColumnIterator

List of usage examples for org.hibernate.mapping PrimaryKey getColumnIterator

Introduction

In this page you can find the example usage for org.hibernate.mapping PrimaryKey getColumnIterator.

Prototype

public Iterator<Column> getColumnIterator() 

Source Link

Usage

From source file:com.xpn.xwiki.store.migration.hibernate.R40000XWIKI6990DataMigration.java

License:Open Source License

/**
 * Append a add primary key constraint command for the given table.
 *
 * @param sb append the result into this string builder
 * @param table the table name/*from  w ww. j  a v a2s .c  o  m*/
 */
private void appendAddPrimaryKey(StringBuilder sb, Table table) {
    PrimaryKey pk = table.getPrimaryKey();
    String pkName = pk.getName();

    sb.append("    <addPrimaryKey tableName=\"").append(table.getName()).append("\"  columnNames=\"");

    @SuppressWarnings("unchecked")
    Iterator<Column> columns = pk.getColumnIterator();
    while (columns.hasNext()) {
        Column column = columns.next();
        sb.append(column.getName());
        if (columns.hasNext()) {
            sb.append(",");
        }
    }

    if (pkName != null) {
        sb.append("\"  constraintName=\"").append(pkName);
    }

    sb.append("\"/>\n");
}

From source file:org.teiid.spring.views.ViewBuilder.java

License:Apache License

private void addPrimaryKey(org.hibernate.mapping.Table ormTable, Table view, MetadataFactory mf) {
    PrimaryKey pk = ormTable.getPrimaryKey();
    List<String> pkColumns = new ArrayList<>();
    if (pk != null) {
        Iterator<org.hibernate.mapping.Column> it = pk.getColumnIterator();
        while (it.hasNext()) {
            org.hibernate.mapping.Column c = it.next();
            Column col = view.getColumnByName(c.getName());
            if (pk.isGenerated(dialect)) {
                col.setAutoIncremented(true);
            }/* w  w w. j ava2  s . c  om*/
            pkColumns.add(c.getName());
        }
        mf.addPrimaryKey("PK", pkColumns, view);
    }

}