Example usage for org.hibernate.mapping Table hasPrimaryKey

List of usage examples for org.hibernate.mapping Table hasPrimaryKey

Introduction

In this page you can find the example usage for org.hibernate.mapping Table hasPrimaryKey.

Prototype

public boolean hasPrimaryKey() 

Source Link

Usage

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

License:Open Source License

/**
 * Create liquibase change log to modify the column type to BIGINT.
 * If the database is MSSQL, drop PK constraints and indexes during operation.
 * /*ww  w  .  ja v  a2  s  . c  o m*/
 * @param sb append the result into this string builder
 * @param table the table name
 * @param column the column name
 */
private void appendDataTypeChangeLog(StringBuilder sb, Table table, String column) {
    String tableName = table.getName();

    sb.append("  <changeSet id=\"R").append(this.getVersion().getVersion()).append('-')
            .append(Util.getHash(String.format("modifyDataType-%s-%s", table, column)))
            .append("\" author=\"xwiki\">\n").append("    <comment>Upgrade identifier [").append(column)
            .append("] from table [").append(tableName).append("] to BIGINT type</comment >\n");

    // MS-SQL require that primary key constraints and all indexes related to the changed column be dropped before
    // changing the column type.
    if (this.isMSSQL) {
        if (table.hasPrimaryKey()) {
            appendDropPrimaryKey(sb, table);
        }

        // We drop all index related to the table, this is overkill, but does not hurt
        for (@SuppressWarnings("unchecked")
        Iterator<Index> it = table.getIndexIterator(); it.hasNext();) {
            Index index = it.next();
            appendDropIndex(sb, index);
        }
    }

    appendModifyColumn(sb, tableName, column);

    // Add back dropped PK constraints and indexes for MS-SQL
    if (this.isMSSQL) {
        if (table.hasPrimaryKey()) {
            appendAddPrimaryKey(sb, table);
        }

        for (@SuppressWarnings("unchecked")
        Iterator<Index> it = table.getIndexIterator(); it.hasNext();) {
            Index index = it.next();
            appendAddIndex(sb, index);
        }
    }

    sb.append("  </changeSet>\n");
    this.logCount++;
}