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
|
||||
*/
|
||||
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<QualifiedSequenceName,SequenceInformation> sequenceInformationMap = new HashMap<QualifiedSequenceName, SequenceInformation>();
|
||||
|
||||
|
@ -55,32 +55,32 @@ public class DatabaseInformationImpl implements DatabaseInformation, ExtractionC
|
|||
|
||||
@Override
|
||||
public TableInformation getTableInformation(Identifier catalogName, Identifier schemaName, Identifier tableName) {
|
||||
return locateRegisteredTableInformation( new QualifiedTableName( catalogName, schemaName, tableName ) );
|
||||
return locateTableInformation( new QualifiedTableName( catalogName, schemaName, tableName ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableInformation getTableInformation(Schema.Name schemaName, Identifier tableName) {
|
||||
return locateRegisteredTableInformation( new QualifiedTableName( schemaName, tableName ) );
|
||||
return locateTableInformation( new QualifiedTableName( schemaName, tableName ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableInformation getTableInformation(QualifiedTableName tableName) {
|
||||
return locateRegisteredTableInformation( tableName );
|
||||
return locateTableInformation( tableName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SequenceInformation getSequenceInformation(Identifier catalogName, Identifier schemaName, Identifier sequenceName) {
|
||||
return locateRegisteredSequenceInformation( new QualifiedSequenceName( catalogName, schemaName, sequenceName ) );
|
||||
return locateSequenceInformation( new QualifiedSequenceName( catalogName, schemaName, sequenceName ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SequenceInformation getSequenceInformation(Schema.Name schemaName, Identifier sequenceName) {
|
||||
return locateRegisteredSequenceInformation( new QualifiedSequenceName( schemaName, sequenceName ) );
|
||||
return locateSequenceInformation( new QualifiedSequenceName( schemaName, sequenceName ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SequenceInformation getSequenceInformation(QualifiedSequenceName sequenceName) {
|
||||
return locateRegisteredSequenceInformation( sequenceName );
|
||||
return locateSequenceInformation( sequenceName );
|
||||
}
|
||||
|
||||
|
||||
|
@ -95,12 +95,12 @@ public class DatabaseInformationImpl implements DatabaseInformation, ExtractionC
|
|||
}
|
||||
|
||||
@Override
|
||||
public TableInformation locateRegisteredTableInformation(QualifiedTableName tableName) {
|
||||
public TableInformation locateTableInformation(QualifiedTableName tableName) {
|
||||
return tableInformationMap.get( tableName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SequenceInformation locateRegisteredSequenceInformation(QualifiedSequenceName sequenceName) {
|
||||
public SequenceInformation locateSequenceInformation(QualifiedSequenceName sequenceName) {
|
||||
return sequenceInformationMap.get( sequenceName );
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ public class ExtractionContextImpl implements ExtractionContext {
|
|||
private final ServiceRegistry serviceRegistry;
|
||||
private final JdbcEnvironment jdbcEnvironment;
|
||||
private final JdbcConnectionAccess jdbcConnectionAccess;
|
||||
private final RegisteredObjectAccess registeredTableAccess;
|
||||
private final DatabaseObjectAccess registeredTableAccess;
|
||||
private final Identifier defaultCatalogName;
|
||||
private final Identifier defaultSchemaName;
|
||||
|
||||
|
@ -51,7 +51,7 @@ public class ExtractionContextImpl implements ExtractionContext {
|
|||
ServiceRegistry serviceRegistry,
|
||||
JdbcEnvironment jdbcEnvironment,
|
||||
JdbcConnectionAccess jdbcConnectionAccess,
|
||||
RegisteredObjectAccess registeredTableAccess,
|
||||
DatabaseObjectAccess registeredTableAccess,
|
||||
Identifier defaultCatalogName,
|
||||
Identifier defaultSchemaName) {
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
|
@ -109,7 +109,7 @@ public class ExtractionContextImpl implements ExtractionContext {
|
|||
}
|
||||
|
||||
@Override
|
||||
public RegisteredObjectAccess getRegisteredObjectAccess() {
|
||||
public DatabaseObjectAccess getDatabaseObjectAccess() {
|
||||
return registeredTableAccess;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
|
@ -444,8 +443,8 @@ public class InformationExtractorJdbcDatabaseMetaDataImpl implements Information
|
|||
|
||||
final QualifiedTableName incomingPkTableName = extractKeyTableName( resultSet, "PK" );
|
||||
|
||||
final TableInformation pkTableInformation = extractionContext.getRegisteredObjectAccess()
|
||||
.locateRegisteredTableInformation( incomingPkTableName );
|
||||
final TableInformation pkTableInformation = extractionContext.getDatabaseObjectAccess()
|
||||
.locateTableInformation( incomingPkTableName );
|
||||
|
||||
if ( pkTableInformation == null ) {
|
||||
// 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 {
|
||||
final String incomingCatalogName = resultSet.getString( prefix + "TABLE_SCHEM" );
|
||||
final String incomingSchemaName = resultSet.getString( prefix + "TABLE_CAT" );
|
||||
final String incomingCatalogName = resultSet.getString( prefix + "TABLE_CAT" );
|
||||
final String incomingSchemaName = resultSet.getString( prefix + "TABLE_SCHEM" );
|
||||
final String incomingTableName = resultSet.getString( prefix + "TABLE_NAME" );
|
||||
|
||||
return new QualifiedTableName(
|
||||
|
|
|
@ -36,13 +36,9 @@ import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
|||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.tool.schema.extract.internal.ExtractionContextImpl;
|
||||
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.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.PrimaryKeyInformation;
|
||||
import org.hibernate.tool.schema.extract.spi.SequenceInformation;
|
||||
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.
|
||||
*/
|
||||
@Deprecated
|
||||
public class DatabaseInformationImpl implements DatabaseInformation, ExtractionContext.RegisteredObjectAccess {
|
||||
public class DatabaseInformationImpl implements DatabaseInformation, ExtractionContext.DatabaseObjectAccess {
|
||||
private final InformationExtractor extractor;
|
||||
private final ExtractionContext extractionContext;
|
||||
|
||||
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>();
|
||||
|
||||
public DatabaseInformationImpl(
|
||||
|
@ -76,8 +68,6 @@ public class DatabaseInformationImpl implements DatabaseInformation, ExtractionC
|
|||
Identifier defaultCatalogName,
|
||||
Identifier defaultSchemaName) throws SQLException {
|
||||
this.jdbcEnvironment = jdbcEnvironment;
|
||||
this.defaultCatalogName = defaultCatalogName;
|
||||
this.defaultSchemaName = defaultSchemaName;
|
||||
|
||||
this.extractionContext = new ExtractionContextImpl(
|
||||
serviceRegistry,
|
||||
|
@ -137,38 +127,15 @@ public class DatabaseInformationImpl implements DatabaseInformation, ExtractionC
|
|||
throw new IllegalArgumentException( "Passed table name cannot be null" );
|
||||
}
|
||||
|
||||
TableInformation result = tableInformationMap.get( qualifiedTableName );
|
||||
if ( result == null ) {
|
||||
result = extractor.getTable(
|
||||
qualifiedTableName.getCatalogName(),
|
||||
qualifiedTableName.getSchemaName(),
|
||||
qualifiedTableName.getTableName()
|
||||
);
|
||||
return extractor.getTable(
|
||||
qualifiedTableName.getCatalogName(),
|
||||
qualifiedTableName.getSchemaName(),
|
||||
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
|
||||
|
@ -188,16 +155,16 @@ public class DatabaseInformationImpl implements DatabaseInformation, ExtractionC
|
|||
|
||||
@Override
|
||||
public SequenceInformation getSequenceInformation(QualifiedSequenceName qualifiedSequenceName) {
|
||||
return locateRegisteredSequenceInformation( qualifiedSequenceName );
|
||||
return locateSequenceInformation( qualifiedSequenceName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableInformation locateRegisteredTableInformation(QualifiedTableName tableName) {
|
||||
return tableInformationMap.get( tableName );
|
||||
public TableInformation locateTableInformation(QualifiedTableName tableName) {
|
||||
return getTableInformation( tableName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SequenceInformation locateRegisteredSequenceInformation(QualifiedSequenceName sequenceName) {
|
||||
public SequenceInformation locateSequenceInformation(QualifiedSequenceName sequenceName) {
|
||||
// again, follow legacy behavior
|
||||
if ( sequenceName.getCatalogName() != null || sequenceName.getSchemaName() != null ) {
|
||||
sequenceName = new QualifiedSequenceName( null, null, sequenceName.getSequenceName() );
|
||||
|
@ -205,61 +172,4 @@ public class DatabaseInformationImpl implements DatabaseInformation, ExtractionC
|
|||
|
||||
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 getDefaultSchema();
|
||||
|
||||
public static interface RegisteredObjectAccess {
|
||||
public TableInformation locateRegisteredTableInformation(QualifiedTableName tableName);
|
||||
public SequenceInformation locateRegisteredSequenceInformation(QualifiedSequenceName sequenceName);
|
||||
public static interface DatabaseObjectAccess {
|
||||
public TableInformation locateTableInformation(QualifiedTableName tableName);
|
||||
public SequenceInformation locateSequenceInformation(QualifiedSequenceName sequenceName);
|
||||
}
|
||||
|
||||
RegisteredObjectAccess getRegisteredObjectAccess();
|
||||
DatabaseObjectAccess getDatabaseObjectAccess();
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ import org.junit.Test;
|
|||
public class ForeignKeyMigrationTest extends BaseUnitTestCase {
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-9716" )
|
||||
@FailureExpected( jiraKey = "HHH-9716" )
|
||||
// @FailureExpected( jiraKey = "HHH-9716" )
|
||||
public void testMigrationOfForeignKeys() {
|
||||
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue