HHH-9716 - Previously working schema creation fails on 5.0
This commit is contained in:
parent
3e5a8b6603
commit
3c85127f82
|
@ -38,7 +38,7 @@ import org.hibernate.tool.schema.extract.spi.TableInformation;
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class DatabaseInformationImpl implements DatabaseInformation, ExtractionContext.RegisteredObjectAccess {
|
public class DatabaseInformationImpl implements DatabaseInformation, ExtractionContext.DatabaseObjectAccess {
|
||||||
private final Map<QualifiedTableName,TableInformation> tableInformationMap = new HashMap<QualifiedTableName, TableInformation>();
|
private final Map<QualifiedTableName,TableInformation> tableInformationMap = new HashMap<QualifiedTableName, TableInformation>();
|
||||||
private final Map<QualifiedSequenceName,SequenceInformation> sequenceInformationMap = new HashMap<QualifiedSequenceName, SequenceInformation>();
|
private final Map<QualifiedSequenceName,SequenceInformation> sequenceInformationMap = new HashMap<QualifiedSequenceName, SequenceInformation>();
|
||||||
|
|
||||||
|
@ -55,32 +55,32 @@ public class DatabaseInformationImpl implements DatabaseInformation, ExtractionC
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TableInformation getTableInformation(Identifier catalogName, Identifier schemaName, Identifier tableName) {
|
public TableInformation getTableInformation(Identifier catalogName, Identifier schemaName, Identifier tableName) {
|
||||||
return locateRegisteredTableInformation( new QualifiedTableName( catalogName, schemaName, tableName ) );
|
return locateTableInformation( new QualifiedTableName( catalogName, schemaName, tableName ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TableInformation getTableInformation(Schema.Name schemaName, Identifier tableName) {
|
public TableInformation getTableInformation(Schema.Name schemaName, Identifier tableName) {
|
||||||
return locateRegisteredTableInformation( new QualifiedTableName( schemaName, tableName ) );
|
return locateTableInformation( new QualifiedTableName( schemaName, tableName ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TableInformation getTableInformation(QualifiedTableName tableName) {
|
public TableInformation getTableInformation(QualifiedTableName tableName) {
|
||||||
return locateRegisteredTableInformation( tableName );
|
return locateTableInformation( tableName );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SequenceInformation getSequenceInformation(Identifier catalogName, Identifier schemaName, Identifier sequenceName) {
|
public SequenceInformation getSequenceInformation(Identifier catalogName, Identifier schemaName, Identifier sequenceName) {
|
||||||
return locateRegisteredSequenceInformation( new QualifiedSequenceName( catalogName, schemaName, sequenceName ) );
|
return locateSequenceInformation( new QualifiedSequenceName( catalogName, schemaName, sequenceName ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SequenceInformation getSequenceInformation(Schema.Name schemaName, Identifier sequenceName) {
|
public SequenceInformation getSequenceInformation(Schema.Name schemaName, Identifier sequenceName) {
|
||||||
return locateRegisteredSequenceInformation( new QualifiedSequenceName( schemaName, sequenceName ) );
|
return locateSequenceInformation( new QualifiedSequenceName( schemaName, sequenceName ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SequenceInformation getSequenceInformation(QualifiedSequenceName sequenceName) {
|
public SequenceInformation getSequenceInformation(QualifiedSequenceName sequenceName) {
|
||||||
return locateRegisteredSequenceInformation( sequenceName );
|
return locateSequenceInformation( sequenceName );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -95,12 +95,12 @@ public class DatabaseInformationImpl implements DatabaseInformation, ExtractionC
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TableInformation locateRegisteredTableInformation(QualifiedTableName tableName) {
|
public TableInformation locateTableInformation(QualifiedTableName tableName) {
|
||||||
return tableInformationMap.get( tableName );
|
return tableInformationMap.get( tableName );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SequenceInformation locateRegisteredSequenceInformation(QualifiedSequenceName sequenceName) {
|
public SequenceInformation locateSequenceInformation(QualifiedSequenceName sequenceName) {
|
||||||
return sequenceInformationMap.get( sequenceName );
|
return sequenceInformationMap.get( sequenceName );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ public class ExtractionContextImpl implements ExtractionContext {
|
||||||
private final ServiceRegistry serviceRegistry;
|
private final ServiceRegistry serviceRegistry;
|
||||||
private final JdbcEnvironment jdbcEnvironment;
|
private final JdbcEnvironment jdbcEnvironment;
|
||||||
private final JdbcConnectionAccess jdbcConnectionAccess;
|
private final JdbcConnectionAccess jdbcConnectionAccess;
|
||||||
private final RegisteredObjectAccess registeredTableAccess;
|
private final DatabaseObjectAccess registeredTableAccess;
|
||||||
private final Identifier defaultCatalogName;
|
private final Identifier defaultCatalogName;
|
||||||
private final Identifier defaultSchemaName;
|
private final Identifier defaultSchemaName;
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ public class ExtractionContextImpl implements ExtractionContext {
|
||||||
ServiceRegistry serviceRegistry,
|
ServiceRegistry serviceRegistry,
|
||||||
JdbcEnvironment jdbcEnvironment,
|
JdbcEnvironment jdbcEnvironment,
|
||||||
JdbcConnectionAccess jdbcConnectionAccess,
|
JdbcConnectionAccess jdbcConnectionAccess,
|
||||||
RegisteredObjectAccess registeredTableAccess,
|
DatabaseObjectAccess registeredTableAccess,
|
||||||
Identifier defaultCatalogName,
|
Identifier defaultCatalogName,
|
||||||
Identifier defaultSchemaName) {
|
Identifier defaultSchemaName) {
|
||||||
this.serviceRegistry = serviceRegistry;
|
this.serviceRegistry = serviceRegistry;
|
||||||
|
@ -109,7 +109,7 @@ public class ExtractionContextImpl implements ExtractionContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RegisteredObjectAccess getRegisteredObjectAccess() {
|
public DatabaseObjectAccess getDatabaseObjectAccess() {
|
||||||
return registeredTableAccess;
|
return registeredTableAccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,6 @@ import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
|
@ -444,8 +443,8 @@ public class InformationExtractorJdbcDatabaseMetaDataImpl implements Information
|
||||||
|
|
||||||
final QualifiedTableName incomingPkTableName = extractKeyTableName( resultSet, "PK" );
|
final QualifiedTableName incomingPkTableName = extractKeyTableName( resultSet, "PK" );
|
||||||
|
|
||||||
final TableInformation pkTableInformation = extractionContext.getRegisteredObjectAccess()
|
final TableInformation pkTableInformation = extractionContext.getDatabaseObjectAccess()
|
||||||
.locateRegisteredTableInformation( incomingPkTableName );
|
.locateTableInformation( incomingPkTableName );
|
||||||
|
|
||||||
if ( pkTableInformation == null ) {
|
if ( pkTableInformation == null ) {
|
||||||
// the assumption here is that we have not seen this table already based on fully-qualified name
|
// the assumption here is that we have not seen this table already based on fully-qualified name
|
||||||
|
@ -520,8 +519,8 @@ public class InformationExtractorJdbcDatabaseMetaDataImpl implements Information
|
||||||
}
|
}
|
||||||
|
|
||||||
private QualifiedTableName extractKeyTableName(ResultSet resultSet, String prefix) throws SQLException {
|
private QualifiedTableName extractKeyTableName(ResultSet resultSet, String prefix) throws SQLException {
|
||||||
final String incomingCatalogName = resultSet.getString( prefix + "TABLE_SCHEM" );
|
final String incomingCatalogName = resultSet.getString( prefix + "TABLE_CAT" );
|
||||||
final String incomingSchemaName = resultSet.getString( prefix + "TABLE_CAT" );
|
final String incomingSchemaName = resultSet.getString( prefix + "TABLE_SCHEM" );
|
||||||
final String incomingTableName = resultSet.getString( prefix + "TABLE_NAME" );
|
final String incomingTableName = resultSet.getString( prefix + "TABLE_NAME" );
|
||||||
|
|
||||||
return new QualifiedTableName(
|
return new QualifiedTableName(
|
||||||
|
|
|
@ -36,13 +36,9 @@ import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
||||||
import org.hibernate.service.ServiceRegistry;
|
import org.hibernate.service.ServiceRegistry;
|
||||||
import org.hibernate.tool.schema.extract.internal.ExtractionContextImpl;
|
import org.hibernate.tool.schema.extract.internal.ExtractionContextImpl;
|
||||||
import org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl;
|
import org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl;
|
||||||
import org.hibernate.tool.schema.extract.spi.ColumnInformation;
|
|
||||||
import org.hibernate.tool.schema.extract.spi.DatabaseInformation;
|
import org.hibernate.tool.schema.extract.spi.DatabaseInformation;
|
||||||
import org.hibernate.tool.schema.extract.spi.ExtractionContext;
|
import org.hibernate.tool.schema.extract.spi.ExtractionContext;
|
||||||
import org.hibernate.tool.schema.extract.spi.ForeignKeyInformation;
|
|
||||||
import org.hibernate.tool.schema.extract.spi.IndexInformation;
|
|
||||||
import org.hibernate.tool.schema.extract.spi.InformationExtractor;
|
import org.hibernate.tool.schema.extract.spi.InformationExtractor;
|
||||||
import org.hibernate.tool.schema.extract.spi.PrimaryKeyInformation;
|
|
||||||
import org.hibernate.tool.schema.extract.spi.SequenceInformation;
|
import org.hibernate.tool.schema.extract.spi.SequenceInformation;
|
||||||
import org.hibernate.tool.schema.extract.spi.TableInformation;
|
import org.hibernate.tool.schema.extract.spi.TableInformation;
|
||||||
|
|
||||||
|
@ -57,16 +53,12 @@ import org.hibernate.tool.schema.extract.spi.TableInformation;
|
||||||
* class will be removed once that work has been finished.
|
* class will be removed once that work has been finished.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class DatabaseInformationImpl implements DatabaseInformation, ExtractionContext.RegisteredObjectAccess {
|
public class DatabaseInformationImpl implements DatabaseInformation, ExtractionContext.DatabaseObjectAccess {
|
||||||
private final InformationExtractor extractor;
|
private final InformationExtractor extractor;
|
||||||
private final ExtractionContext extractionContext;
|
private final ExtractionContext extractionContext;
|
||||||
|
|
||||||
private final JdbcEnvironment jdbcEnvironment;
|
private final JdbcEnvironment jdbcEnvironment;
|
||||||
|
|
||||||
private final Identifier defaultCatalogName;
|
|
||||||
private final Identifier defaultSchemaName;
|
|
||||||
|
|
||||||
private final Map<QualifiedTableName,TableInformation> tableInformationMap = new HashMap<QualifiedTableName, TableInformation>();
|
|
||||||
private final Map<QualifiedSequenceName,SequenceInformation> sequenceInformationMap = new HashMap<QualifiedSequenceName, SequenceInformation>();
|
private final Map<QualifiedSequenceName,SequenceInformation> sequenceInformationMap = new HashMap<QualifiedSequenceName, SequenceInformation>();
|
||||||
|
|
||||||
public DatabaseInformationImpl(
|
public DatabaseInformationImpl(
|
||||||
|
@ -76,8 +68,6 @@ public class DatabaseInformationImpl implements DatabaseInformation, ExtractionC
|
||||||
Identifier defaultCatalogName,
|
Identifier defaultCatalogName,
|
||||||
Identifier defaultSchemaName) throws SQLException {
|
Identifier defaultSchemaName) throws SQLException {
|
||||||
this.jdbcEnvironment = jdbcEnvironment;
|
this.jdbcEnvironment = jdbcEnvironment;
|
||||||
this.defaultCatalogName = defaultCatalogName;
|
|
||||||
this.defaultSchemaName = defaultSchemaName;
|
|
||||||
|
|
||||||
this.extractionContext = new ExtractionContextImpl(
|
this.extractionContext = new ExtractionContextImpl(
|
||||||
serviceRegistry,
|
serviceRegistry,
|
||||||
|
@ -137,38 +127,15 @@ public class DatabaseInformationImpl implements DatabaseInformation, ExtractionC
|
||||||
throw new IllegalArgumentException( "Passed table name cannot be null" );
|
throw new IllegalArgumentException( "Passed table name cannot be null" );
|
||||||
}
|
}
|
||||||
|
|
||||||
TableInformation result = tableInformationMap.get( qualifiedTableName );
|
return extractor.getTable(
|
||||||
if ( result == null ) {
|
|
||||||
result = extractor.getTable(
|
|
||||||
qualifiedTableName.getCatalogName(),
|
qualifiedTableName.getCatalogName(),
|
||||||
qualifiedTableName.getSchemaName(),
|
qualifiedTableName.getSchemaName(),
|
||||||
qualifiedTableName.getTableName()
|
qualifiedTableName.getTableName()
|
||||||
);
|
);
|
||||||
|
|
||||||
// ATM we cannot stop from looking up tables over and over again. The reason
|
|
||||||
// being that schema migration will create missing tables. So if a table is found to
|
|
||||||
// not exist through this call we will create it. But the problem is that
|
|
||||||
// we will have added a "marker", which means we will then always think that
|
|
||||||
// the table does not exist
|
|
||||||
// if ( result == null ) {
|
|
||||||
// // table does not exist. make a notation in the map so we don't keep
|
|
||||||
// // trying to looking iut up
|
|
||||||
// tableInformationMap.put( qualifiedTableName, new KnownNonExistentTableInformation() );
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// tableInformationMap.put( qualifiedTableName, result );
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if ( result != null ) {
|
|
||||||
// tableInformationMap.put( qualifiedTableName, result );
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
// else if ( result instanceof KnownNonExistentTableInformation ) {
|
|
||||||
// // we know table did not exist from a previous attempt to locate it...
|
|
||||||
// result = null;
|
|
||||||
// }
|
|
||||||
|
|
||||||
return result;
|
@Override
|
||||||
|
public void registerTable(TableInformation tableInformation) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -188,16 +155,16 @@ public class DatabaseInformationImpl implements DatabaseInformation, ExtractionC
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SequenceInformation getSequenceInformation(QualifiedSequenceName qualifiedSequenceName) {
|
public SequenceInformation getSequenceInformation(QualifiedSequenceName qualifiedSequenceName) {
|
||||||
return locateRegisteredSequenceInformation( qualifiedSequenceName );
|
return locateSequenceInformation( qualifiedSequenceName );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TableInformation locateRegisteredTableInformation(QualifiedTableName tableName) {
|
public TableInformation locateTableInformation(QualifiedTableName tableName) {
|
||||||
return tableInformationMap.get( tableName );
|
return getTableInformation( tableName );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SequenceInformation locateRegisteredSequenceInformation(QualifiedSequenceName sequenceName) {
|
public SequenceInformation locateSequenceInformation(QualifiedSequenceName sequenceName) {
|
||||||
// again, follow legacy behavior
|
// again, follow legacy behavior
|
||||||
if ( sequenceName.getCatalogName() != null || sequenceName.getSchemaName() != null ) {
|
if ( sequenceName.getCatalogName() != null || sequenceName.getSchemaName() != null ) {
|
||||||
sequenceName = new QualifiedSequenceName( null, null, sequenceName.getSequenceName() );
|
sequenceName = new QualifiedSequenceName( null, null, sequenceName.getSequenceName() );
|
||||||
|
@ -205,61 +172,4 @@ public class DatabaseInformationImpl implements DatabaseInformation, ExtractionC
|
||||||
|
|
||||||
return sequenceInformationMap.get( sequenceName );
|
return sequenceInformationMap.get( sequenceName );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void registerTable(TableInformation tableInformation) {
|
|
||||||
tableInformationMap.put( tableInformation.getName(), tableInformation );
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class KnownNonExistentTableInformation implements TableInformation {
|
|
||||||
@Override
|
|
||||||
public QualifiedTableName getName() {
|
|
||||||
throw new UnsupportedOperationException( "Table does not exist" );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPhysicalTable() {
|
|
||||||
throw new UnsupportedOperationException( "Table does not exist" );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getComment() {
|
|
||||||
throw new UnsupportedOperationException( "Table does not exist" );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterable<ColumnInformation> getColumns() {
|
|
||||||
throw new UnsupportedOperationException( "Table does not exist" );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ColumnInformation getColumn(Identifier columnIdentifier) {
|
|
||||||
throw new UnsupportedOperationException( "Table does not exist" );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PrimaryKeyInformation getPrimaryKey() {
|
|
||||||
throw new UnsupportedOperationException( "Table does not exist" );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterable<ForeignKeyInformation> getForeignKeys() {
|
|
||||||
throw new UnsupportedOperationException( "Table does not exist" );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ForeignKeyInformation getForeignKey(Identifier keyName) {
|
|
||||||
throw new UnsupportedOperationException( "Table does not exist" );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterable<IndexInformation> getIndexes() {
|
|
||||||
throw new UnsupportedOperationException( "Table does not exist" );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IndexInformation getIndex(Identifier indexName) {
|
|
||||||
throw new UnsupportedOperationException( "Table does not exist" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,10 +47,10 @@ public interface ExtractionContext {
|
||||||
Identifier getDefaultCatalog();
|
Identifier getDefaultCatalog();
|
||||||
Identifier getDefaultSchema();
|
Identifier getDefaultSchema();
|
||||||
|
|
||||||
public static interface RegisteredObjectAccess {
|
public static interface DatabaseObjectAccess {
|
||||||
public TableInformation locateRegisteredTableInformation(QualifiedTableName tableName);
|
public TableInformation locateTableInformation(QualifiedTableName tableName);
|
||||||
public SequenceInformation locateRegisteredSequenceInformation(QualifiedSequenceName sequenceName);
|
public SequenceInformation locateSequenceInformation(QualifiedSequenceName sequenceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
RegisteredObjectAccess getRegisteredObjectAccess();
|
DatabaseObjectAccess getDatabaseObjectAccess();
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ import org.junit.Test;
|
||||||
public class ForeignKeyMigrationTest extends BaseUnitTestCase {
|
public class ForeignKeyMigrationTest extends BaseUnitTestCase {
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue( jiraKey = "HHH-9716" )
|
@TestForIssue( jiraKey = "HHH-9716" )
|
||||||
@FailureExpected( jiraKey = "HHH-9716" )
|
// @FailureExpected( jiraKey = "HHH-9716" )
|
||||||
public void testMigrationOfForeignKeys() {
|
public void testMigrationOfForeignKeys() {
|
||||||
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue