use of org.hibernate.tool.schema.extract.spi.IndexInformation in project hibernate-orm by hibernate.
the class TableInformationImpl method indexes.
protected Map<Identifier, IndexInformation> indexes() {
if (indexes == null) {
final Map<Identifier, IndexInformation> indexMap = new HashMap<>();
final Iterable<IndexInformation> indexes = extractor.getIndexes(this);
for (IndexInformation index : indexes) {
indexMap.put(index.getIndexIdentifier(), index);
}
this.indexes = indexMap;
}
return indexes;
}
use of org.hibernate.tool.schema.extract.spi.IndexInformation in project hibernate-orm by hibernate.
the class AbstractSchemaMigrator method applyIndexes.
protected void applyIndexes(Table table, TableInformation tableInformation, Dialect dialect, Metadata metadata, Formatter formatter, ExecutionOptions options, GenerationTarget... targets) {
final Exporter<Index> exporter = dialect.getIndexExporter();
final Iterator<Index> indexItr = table.getIndexIterator();
while (indexItr.hasNext()) {
final Index index = indexItr.next();
if (!StringHelper.isEmpty(index.getName())) {
IndexInformation existingIndex = null;
if (tableInformation != null) {
existingIndex = findMatchingIndex(index, tableInformation);
}
if (existingIndex == null) {
applySqlStrings(false, exporter.getSqlCreateStrings(index, metadata), formatter, options, targets);
}
}
}
}
use of org.hibernate.tool.schema.extract.spi.IndexInformation in project hibernate-orm by hibernate.
the class AbstractSchemaMigrator method applyUniqueKeys.
protected void applyUniqueKeys(Table table, TableInformation tableInfo, Dialect dialect, Metadata metadata, Formatter formatter, ExecutionOptions options, GenerationTarget... targets) {
if (uniqueConstraintStrategy == null) {
uniqueConstraintStrategy = determineUniqueConstraintSchemaUpdateStrategy(metadata);
}
if (uniqueConstraintStrategy != UniqueConstraintSchemaUpdateStrategy.SKIP) {
final Exporter<Constraint> exporter = dialect.getUniqueKeyExporter();
final Iterator ukItr = table.getUniqueKeyIterator();
while (ukItr.hasNext()) {
final UniqueKey uniqueKey = (UniqueKey) ukItr.next();
// Skip if index already exists. Most of the time, this
// won't work since most Dialects use Constraints. However,
// keep it for the few that do use Indexes.
IndexInformation indexInfo = null;
if (tableInfo != null && StringHelper.isNotEmpty(uniqueKey.getName())) {
indexInfo = tableInfo.getIndex(Identifier.toIdentifier(uniqueKey.getName()));
}
if (indexInfo == null) {
if (uniqueConstraintStrategy == UniqueConstraintSchemaUpdateStrategy.DROP_RECREATE_QUIETLY) {
applySqlStrings(true, exporter.getSqlDropStrings(uniqueKey, metadata), formatter, options, targets);
}
applySqlStrings(true, exporter.getSqlCreateStrings(uniqueKey, metadata), formatter, options, targets);
}
}
}
}
use of org.hibernate.tool.schema.extract.spi.IndexInformation in project hibernate-orm by hibernate.
the class InformationExtractorJdbcDatabaseMetaDataImpl method getIndexes.
@Override
public Iterable<IndexInformation> getIndexes(TableInformation tableInformation) {
final Map<Identifier, IndexInformationImpl.Builder> builders = new HashMap<>();
final QualifiedTableName tableName = tableInformation.getName();
final Identifier catalog = tableName.getCatalogName();
final Identifier schema = tableName.getSchemaName();
final String catalogFilter;
final String schemaFilter;
if (catalog == null) {
catalogFilter = "";
} else {
catalogFilter = catalog.getText();
}
if (schema == null) {
schemaFilter = "";
} else {
schemaFilter = schema.getText();
}
try {
ResultSet resultSet = extractionContext.getJdbcDatabaseMetaData().getIndexInfo(catalogFilter, schemaFilter, tableName.getTableName().getText(), // DO NOT limit to just unique
false, // DO require up-to-date results
true);
try {
while (resultSet.next()) {
if (resultSet.getShort("TYPE") == DatabaseMetaData.tableIndexStatistic) {
continue;
}
final Identifier indexIdentifier = DatabaseIdentifier.toIdentifier(resultSet.getString("INDEX_NAME"));
IndexInformationImpl.Builder builder = builders.get(indexIdentifier);
if (builder == null) {
builder = IndexInformationImpl.builder(indexIdentifier);
builders.put(indexIdentifier, builder);
}
final Identifier columnIdentifier = DatabaseIdentifier.toIdentifier(resultSet.getString("COLUMN_NAME"));
final ColumnInformation columnInformation = tableInformation.getColumn(columnIdentifier);
if (columnInformation == null) {
// See HHH-10191: this may happen when dealing with Oracle/PostgreSQL function indexes
log.logCannotLocateIndexColumnInformation(columnIdentifier.getText(), indexIdentifier.getText());
}
builder.addColumn(columnInformation);
}
} finally {
resultSet.close();
}
} catch (SQLException e) {
throw convertSQLException(e, "Error accessing index information: " + tableInformation.getName().toString());
}
final List<IndexInformation> indexes = new ArrayList<IndexInformation>();
for (IndexInformationImpl.Builder builder : builders.values()) {
IndexInformationImpl index = builder.build();
indexes.add(index);
}
return indexes;
}
Aggregations