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

项目:Equella    文件:HibernateMigrationHelper.java   
@SuppressWarnings({"unchecked"})
private void addIndexSQL(List<String> sqlStrings, Table table, Set<Column> colSet)
{
    Iterator<Index> indexIterator = table.getIndexIterator();
    while( indexIterator.hasNext() )
    {
        Index index = indexIterator.next();
        Iterator<Column> colIter = index.getColumnIterator();
        boolean found = false;
        while( colIter.hasNext() )
        {
            Column col = colIter.next();
            if( colSet.contains(col) )
            {
                found = true;
                break;
            }
        }
        if( found && (!extDialect.supportsAutoIndexForUniqueColumn() || !hasUniqueIndex(index, table)) )
        {
            sqlStrings.add(index.sqlCreateString(dialect, mapping, defaultCatalog, defaultSchema));
        }
    }
}
项目: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;
}
项目:Equella    文件:HibernateMigrationHelper.java   
@SuppressWarnings("unchecked")
public Collection<? extends String> getAddIndexesIfRequired(Session session, String tableName, String... indexes)
{
    final Table table = findTable(tableName);

    List<String> sqlStrings = new ArrayList<String>();
    Map<Set<String>, String> revIndexMap = getExistingIndexes(table, session);
    Set<String> indexSet = new HashSet<String>(Arrays.asList(indexes));
    Iterator<Index> indexIterator = table.getIndexIterator();
    while( indexIterator.hasNext() )
    {
        Index index = indexIterator.next();
        if( !indexSet.remove(index.getName()) )
        {
            continue;
        }
        processIndex(table, index, revIndexMap, sqlStrings);
    }
    if( !indexSet.isEmpty() )
    {
        throw new RuntimeException("Failed to find indexes:" + indexSet + " on table: " + tableName);
    }
    return sqlStrings;
}
项目:Equella    文件:HibernateMigrationHelper.java   
public Collection<? extends String> getAddIndexesRawIfRequired(Session session, String tableName,
    String[]... indexes)
{
    List<String> sqlStrings = new ArrayList<String>();
    final Table table = findTable(tableName);
    Map<Set<String>, String> revIndexMap = getExistingIndexes(table, session);
    for( String[] index : indexes )
    {
        Index indexObj = new Index();
        indexObj.setTable(table);
        indexObj.setName(index[0]);
        for( int i = 1; i < index.length; i++ )
        {
            Column col = new Column(index[i]);
            indexObj.addColumn(col);
        }
        processIndex(table, indexObj, revIndexMap, sqlStrings);
    }
    return sqlStrings;
}
项目:Equella    文件:HibernateMigrationHelper.java   
public Collection<? extends String> getAddIndexesRaw(String tableName, String[]... indexes)
{
    List<String> sqlStrings = new ArrayList<String>();
    final Table table = findTable(tableName);
    for( String[] index : indexes )
    {
        Index indexObj = new Index();
        indexObj.setTable(table);
        indexObj.setName(index[0]);
        for( int i = 1; i < index.length; i++ )
        {
            Column col = new Column(index[i]);
            indexObj.addColumn(col);
        }
        sqlStrings.add(indexObj.sqlCreateString(dialect, mapping, defaultCatalog, defaultSchema));
    }
    return sqlStrings;
}
项目:Equella    文件:HibernateMigrationHelper.java   
@SuppressWarnings("unchecked")
private void processIndex(Table table, Index index, Map<Set<String>, String> revIndexMap, List<String> sqlStrings)
{
    Iterator<Column> colIter = index.getColumnIterator();
    Set<String> indexCols = new HashSet<String>();
    while( colIter.hasNext() )
    {
        Column col = colIter.next();
        indexCols.add(col.getName().toLowerCase());
    }
    String existingIndex = revIndexMap.get(indexCols);
    if( existingIndex != null )
    {
        if( existingIndex.equalsIgnoreCase(index.getName()) )
        {
            return;
        }
        else
        {
            sqlStrings.add(extDialect.getDropIndexSql(table.getName(), '`' + existingIndex + '`'));
        }
    }
    sqlStrings.add(index.sqlCreateString(dialect, mapping, defaultCatalog, defaultSchema));
}
项目:Equella    文件:HibernateMigrationHelper.java   
public String getAddNamedIndex(String tableName, String indexName, String... columnNames)
{
    Index index = new Index();
    index.setName(indexName);
    index.setTable(findTable(tableName));
    for( String columnName : columnNames )
    {
        index.addColumn(new Column(columnName));
    }
    return index.sqlCreateString(dialect, mapping, defaultCatalog, defaultSchema);
}
项目:hibernate-conventions    文件:MappingConventions.java   
@SuppressWarnings("rawtypes")
private void normalizeIndexs(Table table, String entityName) {
    Iterator iterator = table.getIndexIterator();
    while (iterator.hasNext()) {
        Index idx = (Index) iterator.next();
        String name = strategy.indexName(entityName, table.getName());
        idx.setName(name);
    }
}
项目:hibernate-conventions    文件:MappingConventions.java   
@SuppressWarnings("rawtypes")
private void validateIndexs(Table table) {
    Iterator iterator = table.getIndexIterator();
    while (iterator.hasNext()) {
        Index index = (Index) iterator.next();
        validateMaxLength(index.getName());
    }
}
项目:Equella    文件:TablesOnlyFilter.java   
@Override
public boolean includeIndex(Table table, Index index)
{
    return includeTable(table);
}
项目:Equella    文件:AllDataHibernateMigrationFilter.java   
@Override
public boolean includeIndex(Table table, Index index)
{
    return true;
}
项目:Equella    文件:HibernateCreationFilter.java   
boolean includeIndex(Table table, Index index);