Example usage for org.hibernate.mapping UniqueKey containsColumn

List of usage examples for org.hibernate.mapping UniqueKey containsColumn

Introduction

In this page you can find the example usage for org.hibernate.mapping UniqueKey containsColumn.

Prototype

public boolean containsColumn(Column column) 

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;
    }//  www  . ja va 2  s.  c  o  m

    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:org.web4thejob.orm.PropertyMetadataImpl.java

License:Open Source License

@Override
public boolean isUniqueKeyWith(String propertyName) {

    if (getName().equals(propertyName)) {
        return false;
    }//  w  ww.  j  av a  2  s  .c om

    PersistentClass pc = entityMetadata.getPersistentClass();
    while (pc != null) {
        Table table = pc.getTable();
        for (Iterator<?> iterUK = table.getUniqueKeyIterator(); iterUK.hasNext();) {
            UniqueKey uniqueKey = (UniqueKey) iterUK.next();

            if (!(uniqueKey.getColumnSpan() > 1)) {
                continue;
            }

            int totcols = 0;
            boolean keyMembers = true;

            for (PropertyMetadataImpl propertyMetadata : Arrays.asList(this,
                    (PropertyMetadataImpl) entityMetadata.getPropertyMetadata(propertyName))) {
                if (!propertyMetadata.hasColumns()) {
                    return false;
                }

                for (final Iterator<?> iterCol = propertyMetadata.property.getColumnIterator(); iterCol
                        .hasNext();) {
                    Column column = (Column) iterCol.next();
                    keyMembers &= column != null && uniqueKey.containsColumn(column);
                }
                totcols += propertyMetadata.property.getColumnSpan();
            }

            if (keyMembers && totcols == uniqueKey.getColumnSpan()) {
                return true;
            }

        }

        pc = pc.getSuperclass();

    }

    return false;
}

From source file:org.web4thejob.orm.PropertyMetadataImpl.java

License:Open Source License

@Override
public boolean isMemberOfUniqueKey() {
    if (!hasColumns()) {
        return false;
    }//from  w  ww . jav a 2 s .  c  om

    PersistentClass pc = entityMetadata.getPersistentClass();
    while (pc != null) {
        Table table = pc.getTable();
        for (Iterator<?> iterUK = table.getUniqueKeyIterator(); iterUK.hasNext();) {
            UniqueKey uniqueKey = (UniqueKey) iterUK.next();
            boolean member = true;
            for (final Iterator<?> iterCol = property.getColumnIterator(); iterCol.hasNext();) {
                Column column = (Column) iterCol.next();
                member &= column != null && uniqueKey.containsColumn(column);
            }

            if (member) {
                return true;
            }
        }
        pc = pc.getSuperclass();
    }

    return false;
}