Example usage for org.hibernate.mapping PrimaryKey getColumns

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

Introduction

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

Prototype

public List<Column> getColumns() 

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 w w w  .j a va  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();
}

From source file:com.krawler.esp.hibernate.impl.HibernateUtil.java

License:Open Source License

public static String getPrimaryColName(Table table) throws ServiceException {
    String colName = "";
    try {//from   w  w w  . ja va  2s. c  om
        PrimaryKey pk = table.getPrimaryKey();
        List lst = pk.getColumns();
        Column col = (Column) lst.get(0);
        colName = col.getName();
    } catch (Exception e) {
        throw ServiceException.FAILURE("HibernateUtil.getPrimaryColName", e);
    }
    return colName;
}