Java 类org.hibernate.mapping.UniqueKey 实例源码

项目:spanner-hibernate    文件:CloudSpannerUniqueDelegate.java   
public UniqueIndex getIndex(UniqueKey uniqueKey)
{
    for (UniqueIndex idx : map.values())
    {
        if (idx.table.equalsIgnoreCase(uniqueKey.getTable().getName()))
        {
            List<String> cols = uniqueKey.getColumns().stream().map(x -> x.getName().toUpperCase())
                    .collect(Collectors.toList());
            if (idx.columns.containsAll(cols) && cols.containsAll(idx.columns))
            {
                return idx;
            }
        }
    }
    return null;
}
项目:spanner-hibernate    文件:CloudSpannerUniqueDelegate.java   
@Override
public String getAlterTableToDropUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata)
{
    // First check that this unique key actually is present, as this is a
    // lot faster than trying to drop it and then fail.
    initIndices();
    UniqueIndex idx = indices.getIndex(uniqueKey);
    if (idx == null)
    {
        return null;
    }
    // Remove from cache
    indices.removeIndex(uniqueKey);
    final StringBuilder buf = new StringBuilder("DROP INDEX ");
    buf.append(dialect.quote(uniqueKey.getName()));

    return buf.toString();
}
项目:Equella    文件:HibernateMigrationHelper.java   
@SuppressWarnings("unchecked")
private boolean hasUniqueIndex(Index index, Table table)
{
    HashSet<Column> indexCols = new HashSet<Column>();
    Iterator<Column> icolIter = index.getColumnIterator();
    while( icolIter.hasNext() )
    {
        Column col = icolIter.next();
        indexCols.add(col);
        if( index.getColumnSpan() == 1 && table.getColumn(col).isUnique() )
        {
            return true;
        }
    }
    Iterator<UniqueKey> iter = table.getUniqueKeyIterator();
    while( iter.hasNext() )
    {
        UniqueKey uk = iter.next();
        if( uk.getColumnSpan() == indexCols.size() && indexCols.containsAll(uk.getColumns()) )
        {
            return true;
        }
    }
    return false;
}
项目:spanner-hibernate    文件:CloudSpannerUniqueDelegate.java   
@Override
public String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata)
{
    ConfigurationService config = metadata.getDatabase().getBuildingOptions().getServiceRegistry()
            .getService(ConfigurationService.class);
    if (config != null)
    {
        String value = config.getSetting("hibernate.hbm2ddl.auto", StandardConverters.STRING);
        if (!value.equalsIgnoreCase("update"))
        {
            // We should only check whether it is already present in an
            // update scenario, in all other scenarios, just return the
            // actual create statement.
            return org.hibernate.mapping.Index.buildSqlCreateIndexString(dialect, uniqueKey.getName(),
                    uniqueKey.getTable(), uniqueKey.columnIterator(), uniqueKey.getColumnOrderMap(), true,
                    metadata);
        }
    }
    // First check that this unique key is not already present, as this is a
    // lot faster than trying to create it and then fail.
    initIndices();
    UniqueIndex idx = indices.getIndex(uniqueKey);
    if (idx != null)
    {
        return null;
    }
    return org.hibernate.mapping.Index.buildSqlCreateIndexString(dialect, uniqueKey.getName(), uniqueKey.getTable(),
            uniqueKey.columnIterator(), uniqueKey.getColumnOrderMap(), true, metadata);
}
项目:hibernate-conventions    文件:MappingConventions.java   
@SuppressWarnings("rawtypes")
private void normalizeUniqueKeys(Table table, String entityName) {
    Iterator iterator = table.getUniqueKeyIterator();
    while (iterator.hasNext()) {
        UniqueKey uk = (UniqueKey) iterator.next();
        String name = strategy.uniqueKeyName(entityName, table.getName());
        uk.setName(name);
    }
}
项目:hibernate-conventions    文件:MappingConventions.java   
@SuppressWarnings("rawtypes")
private void validateUniqueKeys(Table table) {
    Iterator iterator = table.getUniqueKeyIterator();
    while (iterator.hasNext()) {
        UniqueKey uk = (UniqueKey) iterator.next();
        validateMaxLength(uk.getName());
    }
}
项目:spanner-hibernate    文件:CloudSpannerUniqueDelegate.java   
public void removeIndex(UniqueKey uniqueKey)
{
    String key = uniqueKey.getTable().getName() + "." + uniqueKey.getName();
    map.remove(key);
}
项目:Equella    文件:HibernateMigrationHelper.java   
@SuppressWarnings({"unchecked"})
public List<String> getAddIndexesAndConstraintsForColumns(String tableName, boolean includeForeignKeyConstraints,
    String... columnNames)
{
    Set<Column> colSet = new HashSet<Column>();
    for( String columnName : columnNames )
    {
        colSet.add(new Column(columnName));
    }
    List<String> sqlStrings = new ArrayList<String>();

    Table table = findTable(tableName);
    if( !extDialect.supportsModifyWithConstraints() )
    {
        for( Column col : colSet )
        {
            Column realCol = table.getColumn(col);
            if( realCol.isUnique() )
            {
                table.createUniqueKey(Collections.singletonList(realCol));
            }
        }
    }
    Iterator<UniqueKey> keyIter = table.getUniqueKeyIterator();
    if( dialect.supportsUniqueConstraintInCreateAlterTable() )
    {
        while( keyIter.hasNext() )
        {
            UniqueKey uk = keyIter.next();
            if( !Collections.disjoint(uk.getColumns(), colSet) )
            {
                StringBuilder buf = new StringBuilder("alter table ");
                buf.append(table.getQualifiedName(dialect, defaultCatalog, defaultSchema));
                buf.append(" add constraint ");
                buf.append(extDialect.getRandomIdentifier());
                buf.append(' ');
                String constraint = uk.sqlConstraintString(dialect);
                if( constraint != null )
                {
                    buf.append(constraint);
                    sqlStrings.add(buf.toString());
                }
            }
        }
    }
    else
    {
        while( keyIter.hasNext() )
        {
            UniqueKey ukey = keyIter.next();
            if( !Collections.disjoint(ukey.getColumns(), colSet) )
            {
                sqlStrings.add(ukey.sqlCreateString(dialect, mapping, defaultCatalog, defaultSchema));
            }
        }
    }

    addIndexSQL(sqlStrings, table, colSet);

    // Caller may opt to skip foreign key constraints
    if( includeForeignKeyConstraints )
    {
        Iterator<ForeignKey> fkeyIter = table.getForeignKeyIterator();
        while( fkeyIter.hasNext() )
        {
            ForeignKey fkey = fkeyIter.next();
            if( !Collections.disjoint(fkey.getColumns(), colSet) )
            {
                sqlStrings.add(fkey.sqlCreateString(dialect, mapping, defaultCatalog, defaultSchema));
            }
        }
    }

    return sqlStrings;
}
项目:Equella    文件:TablesOnlyFilter.java   
@Override
public boolean includeUniqueKey(Table table, UniqueKey uk)
{
    return includeTable(table);
}
项目:Equella    文件:AllDataHibernateMigrationFilter.java   
@Override
public boolean includeUniqueKey(Table table, UniqueKey uk)
{
    return true;
}
项目:Equella    文件:HibernateCreationFilter.java   
boolean includeUniqueKey(Table table, UniqueKey uk);