use of org.hibernate.tool.schema.extract.spi.TableInformation in project hibernate-orm by hibernate.
the class GroupedSchemaMigratorImpl method performTablesMigration.
@Override
protected NameSpaceTablesInformation performTablesMigration(Metadata metadata, DatabaseInformation existingDatabase, ExecutionOptions options, Dialect dialect, Formatter formatter, Set<String> exportIdentifiers, boolean tryToCreateCatalogs, boolean tryToCreateSchemas, Set<Identifier> exportedCatalogs, Namespace namespace, GenerationTarget[] targets) {
final NameSpaceTablesInformation tablesInformation = new NameSpaceTablesInformation(metadata.getDatabase().getJdbcEnvironment().getIdentifierHelper());
if (schemaFilter.includeNamespace(namespace)) {
createSchemaAndCatalog(existingDatabase, options, dialect, formatter, tryToCreateCatalogs, tryToCreateSchemas, exportedCatalogs, namespace, targets);
final NameSpaceTablesInformation tables = existingDatabase.getTablesInformation(namespace);
for (Table table : namespace.getTables()) {
if (schemaFilter.includeTable(table) && table.isPhysicalTable()) {
checkExportIdentifier(table, exportIdentifiers);
final TableInformation tableInformation = tables.getTableInformation(table);
if (tableInformation == null) {
createTable(table, dialect, metadata, formatter, options, targets);
} else if (tableInformation != null && tableInformation.isPhysicalTable()) {
tablesInformation.addTableInformation(tableInformation);
migrateTable(table, tableInformation, dialect, metadata, formatter, options, targets);
}
}
}
for (Table table : namespace.getTables()) {
if (schemaFilter.includeTable(table) && table.isPhysicalTable()) {
final TableInformation tableInformation = tablesInformation.getTableInformation(table);
if (tableInformation == null || (tableInformation != null && tableInformation.isPhysicalTable())) {
applyIndexes(table, tableInformation, dialect, metadata, formatter, options, targets);
applyUniqueKeys(table, tableInformation, dialect, metadata, formatter, options, targets);
}
}
}
}
return tablesInformation;
}
use of org.hibernate.tool.schema.extract.spi.TableInformation in project hibernate-orm by hibernate.
the class InformationExtractorJdbcDatabaseMetaDataImpl method getTable.
@Override
public TableInformation getTable(Identifier catalog, Identifier schema, Identifier tableName) {
if (catalog != null || schema != null) {
return locateTableInNamespace(catalog, schema, tableName);
} else {
// The table did not define an explicit namespace:
// 1) look in current namespace
// 2) look in default namespace
// 3) look in all namespaces - multiple hits is considered an error
TableInformation tableInfo = null;
// 1) look in current namespace
if (extractionContext.getJdbcEnvironment().getCurrentCatalog() != null || extractionContext.getJdbcEnvironment().getCurrentSchema() != null) {
tableInfo = locateTableInNamespace(extractionContext.getJdbcEnvironment().getCurrentCatalog(), extractionContext.getJdbcEnvironment().getCurrentSchema(), tableName);
if (tableInfo != null) {
return tableInfo;
}
}
// 2) look in default namespace
if (extractionContext.getDefaultCatalog() != null || extractionContext.getDefaultSchema() != null) {
tableInfo = locateTableInNamespace(extractionContext.getDefaultCatalog(), extractionContext.getDefaultSchema(), tableName);
if (tableInfo != null) {
return tableInfo;
}
}
// 3) look in all namespaces
try {
final String tableNameFilter = toMetaDataObjectName(tableName);
final ResultSet resultSet = extractionContext.getJdbcDatabaseMetaData().getTables(null, null, tableNameFilter, tableTypes);
try {
return processTableResults(null, null, tableName, resultSet);
} finally {
try {
resultSet.close();
} catch (SQLException ignore) {
}
}
} catch (SQLException sqlException) {
throw convertSQLException(sqlException, "Error accessing table metadata");
}
}
}
use of org.hibernate.tool.schema.extract.spi.TableInformation in project hibernate-orm by hibernate.
the class InformationExtractorJdbcDatabaseMetaDataImpl method processTableResults.
private NameSpaceTablesInformation processTableResults(ResultSet resultSet) throws SQLException {
try {
NameSpaceTablesInformation tables = new NameSpaceTablesInformation(identifierHelper());
while (resultSet.next()) {
final TableInformation tableInformation = extractTableInformation(resultSet);
tables.addTableInformation(tableInformation);
}
return tables;
} finally {
try {
resultSet.close();
} catch (SQLException ignore) {
}
}
}
use of org.hibernate.tool.schema.extract.spi.TableInformation in project hibernate-orm by hibernate.
the class IndividuallySchemaMigratorImpl method performTablesMigration.
@Override
protected NameSpaceTablesInformation performTablesMigration(Metadata metadata, DatabaseInformation existingDatabase, ExecutionOptions options, Dialect dialect, Formatter formatter, Set<String> exportIdentifiers, boolean tryToCreateCatalogs, boolean tryToCreateSchemas, Set<Identifier> exportedCatalogs, Namespace namespace, GenerationTarget[] targets) {
final NameSpaceTablesInformation tablesInformation = new NameSpaceTablesInformation(metadata.getDatabase().getJdbcEnvironment().getIdentifierHelper());
if (schemaFilter.includeNamespace(namespace)) {
createSchemaAndCatalog(existingDatabase, options, dialect, formatter, tryToCreateCatalogs, tryToCreateSchemas, exportedCatalogs, namespace, targets);
for (Table table : namespace.getTables()) {
if (schemaFilter.includeTable(table) && table.isPhysicalTable()) {
checkExportIdentifier(table, exportIdentifiers);
final TableInformation tableInformation = existingDatabase.getTableInformation(table.getQualifiedTableName());
if (tableInformation == null) {
createTable(table, dialect, metadata, formatter, options, targets);
} else if (tableInformation != null && tableInformation.isPhysicalTable()) {
tablesInformation.addTableInformation(tableInformation);
migrateTable(table, tableInformation, dialect, metadata, formatter, options, targets);
}
}
}
for (Table table : namespace.getTables()) {
if (schemaFilter.includeTable(table) && table.isPhysicalTable()) {
final TableInformation tableInformation = tablesInformation.getTableInformation(table);
if (tableInformation == null || (tableInformation != null && tableInformation.isPhysicalTable())) {
applyIndexes(table, tableInformation, dialect, metadata, formatter, options, targets);
applyUniqueKeys(table, tableInformation, dialect, metadata, formatter, options, targets);
}
}
}
}
return tablesInformation;
}
Aggregations