@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)); } } }
@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; }
@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; }
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; }
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; }
@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)); }
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); }
@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); } }
@SuppressWarnings("rawtypes") private void validateIndexs(Table table) { Iterator iterator = table.getIndexIterator(); while (iterator.hasNext()) { Index index = (Index) iterator.next(); validateMaxLength(index.getName()); } }
@Override public boolean includeIndex(Table table, Index index) { return includeTable(table); }
@Override public boolean includeIndex(Table table, Index index) { return true; }
boolean includeIndex(Table table, Index index);