Example usage for org.hibernate.mapping PrimaryKey getColumnSpan

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

Introduction

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

Prototype

public int getColumnSpan() 

Source Link

Usage

From source file:com.github.gekoh.yagen.ddl.CreateDDL.java

License:Apache License

private boolean hasIndex(Table table, String tableNameLC, org.hibernate.mapping.Column column) {
    String columnName = column.getName().toLowerCase();
    if (tblColNameHasSingleColIndex.contains(tableNameLC + "." + columnName)) {
        return true;
    }//from www. j  a v  a  2s . c  om

    TableConfig tableConfig = tblNameToConfig.get(tableNameLC);
    List<String> pkCols = tableConfig != null ? tableConfig.getPkColnames() : null;

    if (pkCols != null && pkCols.size() == 1 && pkCols.contains(columnName)) {
        return true;
    }

    PrimaryKey pk = table.getPrimaryKey();

    if (pk != null && pk.getColumnSpan() == 1 && pk.getColumns().get(0).equals(column)) {
        return true;
    }

    Iterator<UniqueKey> uniqueKeyIterator = table.getUniqueKeyIterator();
    while (uniqueKeyIterator.hasNext()) {
        UniqueKey uk = uniqueKeyIterator.next();
        if (uk.getColumnSpan() == 1 && uk.containsColumn(column)) {
            return true;
        }
    }

    return column.isUnique();
}